Knowledge Bases
Knowledge Bases API
Manage knowledge bases and documents for Retrieval Augmented Generation (RAG).
Knowledge Base Management
List Knowledge Bases
GET /orgs/{organizationId}/knowledgebasesQuery Parameters:
limit(optional): Number of results (default: 20)cursor(optional): Pagination offsetorderBy(optional): Sort fieldforAgentId(optional): Get/create personal KB for specific agentincludePersonalKBs(optional): Set to"true"to include personal knowledge bases
Response:
{
"items": [
{
"knowledgeBaseId": "kb-123",
"organizationId": "org-456",
"type": "ORGANIZATION",
"title": "Product Documentation",
"llmDescription": "Product docs and FAQs for our software",
"creatorUserId": "user-789",
"isPublic": false,
"createdAt": "2024-01-01T00:00:00Z",
"updatedAt": "2024-01-01T00:00:00Z"
}
],
"totalRows": 1,
"offset": 0
}Create Knowledge Base
POST /orgs/{organizationId}/knowledgebasesRequired Fields:
title: Knowledge base namellmDescription: Description for LLM to understand when to use this KBtype: Either"ORGANIZATION"or"PERSONAL"
Request Body:
{
"title": "Product Documentation",
"llmDescription": "Contains all product documentation, user guides, FAQs, and technical specifications for our software platform",
"type": "ORGANIZATION"
}Response: Returns created KnowledgeBase object with knowledgeBaseId
llmDescription field is crucial - it tells the LLM when this knowledge base should be used. Be specific and descriptive.Get Knowledge Base
GET /orgs/{organizationId}/knowledgebases/{id}Response: Returns KnowledgeBase object
Update Knowledge Base
PUT /orgs/{organizationId}/knowledgebases/{id}Required Fields:
title: Knowledge base titlellmDescription: LLM description
Request Body:
{
"title": "Updated Product Documentation",
"llmDescription": "Updated description with more context about what this KB contains"
}Delete Knowledge Base
DELETE /orgs/{organizationId}/knowledgebases/{id}Permanently deletes the knowledge base and all its files.
Response:
{
"message": "File deleted",
"knowledgeBaseId": "kb-123"
}Copy Knowledge Base
POST /orgs/{organizationId}/knowledgebases/{id}/copy-toCopies entire knowledge base to another organization.
File Management
List Files
GET /orgs/{organizationId}/knowledgebases/{id}/filesQuery Parameters:
query(optional): Search query to filter filesstatus(optional): Filter by status (WAITING-UPLOAD,ENQUEUED,PROCESSING,READY,ERROR)limit(optional): Number of results (default: 20)cursor(optional): Pagination offset
Response:
{
"items": [
{
"fileId": "file-123",
"knowledgeBaseId": "kb-456",
"organizationId": "org-789",
"fileName": "product-guide.pdf",
"key": "s3-key-path",
"status": "READY",
"embeddingMode": "TEXT",
"customInstructions": null,
"statusMessage": null,
"externalFileUrl": null,
"creatorUserId": "user-101",
"createdAt": "2024-01-01T00:00:00Z",
"updatedAt": "2024-01-01T00:05:00Z"
}
],
"totalRows": 1,
"offset": 0
}Upload File
Step 1: Get upload URL
POST /orgs/{organizationId}/knowledgebases/{id}/files/upload-urlRequest Body:
{
"fileName": "document.pdf",
"contentType": "application/pdf",
"createDownloadLink": false
}Required Fields:
fileName: Name of the filecontentType: MIME type (e.g.,application/pdf,image/png,text/plain)
Optional Fields:
createDownloadLink: Iftrue, creates a 7-day temporary download link
Response:
{
"fileId": "file-123",
"knowledgeBaseId": "kb-456",
"organizationId": "org-789",
"fileName": "document.pdf",
"key": "orgs/org-789/kbs/kb-456/files/file-123",
"status": "WAITING-UPLOAD",
"embeddingMode": "TEXT",
"creatorUserId": "user-101",
"createdAt": "2024-01-01T00:00:00Z",
"updatedAt": "2024-01-01T00:00:00Z",
"uploadUrl": "https://s3.amazonaws.com/signed-url...",
"downloadLink": "https://short.link/abc123"
}Step 2: Upload file to S3
curl -X PUT "${uploadUrl}" \
-H "Content-Type: application/pdf" \
--data-binary "@document.pdf"Step 3: Ingest file
POST /orgs/{organizationId}/knowledgebases/{id}/files/{fileId}/s3-ingestThe file status will change from WAITING-UPLOAD → ENQUEUED → PROCESSING → READY as it’s processed.
Supported File Types:
- PDF files:
.pdf - Images:
.png,.jpg,.jpeg,.gif,.webp - Text files:
.txt,.md,.csv,.json,.xml,.html,.docx
Delete File
DELETE /orgs/{organizationId}/knowledgebases/{id}/files/{fileId}Permanently deletes the file and all its embeddings.
Response:
{
"message": "File deleted",
"fileId": "file-123"
}Reindex File
POST /orgs/{organizationId}/knowledgebases/{id}/files/{fileId}/reindexReprocesses and re-embeds the file content. Useful if embedding algorithm changes or file needs updating.
Download File Link
POST /orgs/{organizationId}/knowledgebases/{id}/files/{fileId}/download-linkGenerates a temporary signed download URL for the file.
Copy File
POST /orgs/{organizationId}/knowledgebases/{id}/file/{fileId}/copy-toCopies a file to another knowledge base.
Request Body:
{
"targetKnowledgeBaseId": "kb-456",
"targetOrganizationId": "org-789"
}Search Knowledge Base
POST /orgs/{organizationId}/knowledgebases/{id}/searchPerforms semantic search across all files in the knowledge base.
Request Body:
{
"query": "How do I reset my password?",
"limit": 10
}Response:
{
"results": [
{
"vectorId": "vec-123",
"fileId": "file-456",
"fileName": "user-guide.pdf",
"key": "s3-key",
"pages": "5-7",
"text": "To reset your password, navigate to Settings > Account > Reset Password...",
"similarity": 0.92,
"externalFileUrl": null
}
]
}Knowledge Base ETL
ETL (Extract, Transform, Load) configurations allow automatic processing of files when they’re added to a knowledge base.
List ETL Configurations
GET /orgs/{organizationId}/knowledgebases/{id}/etlsResponse: Array of KnowledgeBaseETLView objects
Create ETL Configuration
POST /orgs/{organizationId}/knowledgebases/{id}/etlsRequest Body:
{
"etlType": "agent",
"agentId": "agent-123",
"prompt": "Extract key information from this document and summarize it",
"conditions": [
{
"field": "fileName",
"comparison": "ENDS_WITH",
"value": ".pdf",
"mergeOperator": "AND"
},
{
"field": "status",
"comparison": "EQUALS",
"value": "READY"
}
]
}ETL Types:
agent: Run an agent on the fileaction-chain: Execute an action chain
Condition Comparisons:
EQUALS- Exact matchCONTAINS- Contains substringSTARTS_WITH- Starts with valueENDS_WITH- Ends with valueIS_EMPTY- Field is emptyIS_NOT_EMPTY- Field is not empty
Get ETL Configuration
GET /orgs/{organizationId}/knowledgebases/{id}/etls/{etlId}Update ETL Configuration
PUT /orgs/{organizationId}/knowledgebases/{id}/etls/{etlId}Delete ETL Configuration
DELETE /orgs/{organizationId}/knowledgebases/{id}/etls/{etlId}File Status Lifecycle
Understanding file statuses:
- WAITING-UPLOAD: File record created, waiting for S3 upload
- ENQUEUED: File uploaded to S3, queued for processing
- PROCESSING: File is being parsed and embedded
- READY: File processed successfully, embeddings available
- ERROR: Processing failed (check
statusMessagefor details)
Best Practices
- Descriptive LLM Descriptions - Make
llmDescriptionspecific so agents know when to use the KB - File Organization - Use separate knowledge bases for different domains/topics
- File Formats - PDF and text files work best; images use OCR
- ETL for Automation - Set up ETL configs to automatically process new files
- Monitor Status - Check file status after upload to ensure processing completed
- Search Testing - Test semantic search to verify content is retrievable
- Public vs Private - Use
isPublic: falsefor sensitive organizational data
Common Issues
| Issue | Solution |
|---|---|
| File stuck in PROCESSING | Check statusMessage for error details |
| Search returns no results | Verify file status is READY and embeddings were created |
| Upload fails | Verify contentType matches actual file type |
| ETL not triggering | Check condition field names and comparison values |