POST
/
knowledge
/
{knowledge_base_id}
/
add
from opperai import Opper
import time

opper = Opper(http_bearer="YOUR_API_KEY")

# First, create a knowledge base
unique_name = f"hr_policies_{int(time.time())}"
knowledge_base = opper.knowledge.create_base(
    name=unique_name,
    embedding_model="azure/text-embedding-3-large",
)

print(f"Created knowledge base: {knowledge_base.name}")
print(f"Knowledge base ID: {knowledge_base.id}")

# Add data to the knowledge base
document = opper.knowledge.add_data(
    index_id=knowledge_base.id,
    content="Our company offers 25 days of paid vacation annually. Employees can carry over up to 5 unused days to the next year. Vacation requests must be submitted at least 2 weeks in advance through the HR portal.",
    key="vacation_policy_2024",
    metadata={
        "category": "hr_policies",
        "department": "hr",
        "last_updated": "2024-01-15",
        "version": "2.1",
    },
)

print(f"Added document: {document['key']}")
print(f"Document ID: {document['id']}")
print(f"Metadata: {document['metadata']}")
"<any>"

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

knowledge_base_id
string
required

The id of the knowledge base to add the data to

Body

application/json

Response

201
application/json

Successful Response

The response is of type any.