Knowledge Base API
Manage knowledge bases, documents, chunks, and retrieval requests
Knowledge base resource endpoints have a base path of /api/v1/knowledge-bases. All endpoints require an authenticated JWT user session; API-key authentication is not accepted.
Required Scopes
| Scope | Description |
|---|---|
kb:read | List and view knowledge bases |
kb:test | Run searches against knowledge bases |
kb:create | Create knowledge bases |
kb:update | Update knowledge bases and upload documents |
kb:delete | Delete knowledge bases and documents |
Endpoint Overview
| Method | Path | Purpose |
|---|---|---|
| GET/POST | /knowledge-bases | Paginated query / create a knowledge base |
| GET/PUT/DELETE | /knowledge-bases/{kb_id} | Details / update / delete |
| GET | /knowledge-bases/{kb_id}/stats | Statistics |
| GET | /knowledge-bases/{kb_id}/documents | Document list |
| POST | /knowledge-bases/{kb_id}/documents/upload | Upload a file |
| POST | /knowledge-bases/{kb_id}/documents/url | Import a URL |
| GET | /knowledge-bases/{kb_id}/documents/{doc_id} | Document details |
| GET | /knowledge-bases/{kb_id}/documents/{doc_id}/download | Download the original document |
| GET | /knowledge-bases/{kb_id}/documents/{doc_id}/media/{filename} | Fetch media extracted from a document |
| PUT | /knowledge-bases/{kb_id}/documents/{doc_id} | Update document metadata |
| DELETE | /knowledge-bases/{kb_id}/documents/{doc_id} | Delete document |
| POST | /knowledge-bases/{kb_id}/documents/{doc_id}/process | Process document |
| POST | /knowledge-bases/{kb_id}/documents/{doc_id}/process-with-chunks | Process with edited chunks |
| POST | /knowledge-bases/{kb_id}/documents/{doc_id}/preview-chunks | Preview chunks |
| POST | /knowledge-bases/{kb_id}/documents/{doc_id}/reprocess | Reprocess |
| POST | /knowledge-bases/{kb_id}/documents/{doc_id}/retry-failed-chunks | Retry failed chunks |
| POST | /knowledge-bases/{kb_id}/documents/{doc_id}/chunks/{chunk_id}/retry-embedding | Retry single chunk embedding |
| POST | /knowledge-bases/{kb_id}/documents/{doc_id}/rechunk | Rechunk |
| GET/POST/PUT/DELETE | /knowledge-bases/{kb_id}/documents/{doc_id}/chunks | Chunk CRUD |
| POST | /knowledge-bases/{kb_id}/search | Single retrieval |
| POST | /knowledge-bases/{kb_id}/search/batch | Multi-config comparison retrieval |
| POST | /knowledge-bases/{kb_id}/share | Share the knowledge base with another team |
| GET | /knowledge-bases/{kb_id}/shares | List knowledge base shares |
| DELETE | /knowledge-bases/{kb_id}/share/{team_id} | Revoke a team's share |
Knowledge Base Management
List Knowledge Bases
GET /api/v1/knowledge-basesQuery parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
page | integer | No | 1 | Page number |
page_size | integer | No | 20 | Items per page |
team_id | string | No | - | Filter by team ID (requires team membership) |
status | array | No | - | Filter by status: active, processing, error, archived (repeatable) |
search | string | No | - | Search by name or description |
own_only | boolean | No | false | Only return KBs created by the current user (non-superusers) |
include_shared | boolean | No | true | Also include KBs shared with the caller's teams; ignored when own_only=true |
include_shared only adds KBs whose visibility is team or public and that have been shared with the caller's teams; with own_only=true no shared KBs are merged in. Because the default is true, "list knowledge bases" returns both owned and shared KBs — use is_owned to tell them apart.
curl -X GET "https://your-domain.com/api/v1/knowledge-bases?page=1&page_size=20" \
-H "Authorization: Bearer YOUR_TOKEN"Each KB object in data.items contains id, name, description, icon, team, created_by, status, visibility, embedding_model_id, embedding_model, rerank_model_id, rerank_model, embedding_dimension, document_count, total_chunks, total_tokens, created_at, plus share metadata:
| Field | Type | Description |
|---|---|---|
visibility | string | private, team, or public |
is_owned | boolean | Whether the KB belongs to the caller's team; false for shared KBs |
owner_team_id / owner_team_name | string | Owning team ID / name |
share_permission | string | null | Permission granted to a shared KB (currently read_only); null for owned KBs |
shared_with_count | integer | Number of teams the KB is shared with (non-zero only for owned KBs) |
The response is wrapped in the items/total/page/page_size pagination structure.
Get Knowledge Base Details
GET /api/v1/knowledge-bases/{kb_id}Returns a single KB with additional settings and updated_at fields. The settings object contains chunk_size, chunk_overlap, rerank_enabled, rerank_candidate_k, search_mode, top_k, score_threshold.
Create Knowledge Base
POST /api/v1/knowledge-basesRequest fields:
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | KB name (max 100 chars) |
description | string | No | KB description (max 500 chars) |
icon | string | No | Icon name or emoji (max 50 chars) |
team_id | string | Yes | Team UUID |
embedding_model_id | string | No | Embedding model UUID (must be authorized for the team) |
rerank_model_id | string | No | Rerank model UUID (must be authorized for the team) |
settings | object | No | KB settings: chunk_size (default 1000, min 100), chunk_overlap (default 100, min 0), separator, rerank_enabled (default true), rerank_candidate_k (default 10), rerank_score_threshold, search_mode (vector/fulltext/hybrid), top_k, score_threshold, dense_weight, lexical_weight, rrf_k |
curl -X POST "https://your-domain.com/api/v1/knowledge-bases" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Product Documentation",
"description": "Product docs and FAQs",
"team_id": "team-123",
"embedding_model_id": "model-emb-01",
"settings": {"chunk_size": 1000}
}'Update Knowledge Base
PUT /api/v1/knowledge-bases/{kb_id}All fields are optional; include only the fields you want to update: name, description, icon, settings.
Delete Knowledge Base
DELETE /api/v1/knowledge-bases/{kb_id}Successful response has data: null and msg: "Knowledge base deleted successfully".
Document Management
Upload Document
POST /api/v1/knowledge-bases/{kb_id}/documents/uploadContent-Type is multipart/form-data; the file field is required. Supports .pdf, .docx, .txt, .md, etc.
curl -X POST "https://your-domain.com/api/v1/knowledge-bases/{kb_id}/documents/upload" \
-H "Authorization: Bearer YOUR_TOKEN" \
-F "file=@document.pdf"After upload, the document status is pending; you must call a process endpoint to begin embedding.
Import URL
POST /api/v1/knowledge-bases/{kb_id}/documents/urlRequest body:
{"name": "Page Title", "source_url": "https://example.com/page", "doc_type": "url"}List Documents
GET /api/v1/knowledge-bases/{kb_id}/documentsQuery parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
page | integer | No | 1 | Page number |
page_size | integer | No | 20 | Items per page |
status | array | No | - | pending, processing, completed, error (repeatable) |
doc_type | array | No | - | pdf, docx, txt, markdown, url, etc. (repeatable) |
search | string | No | - | Search by document name |
Get Document Details
GET /api/v1/knowledge-bases/{kb_id}/documents/{document_id}Returns full document info including uploaded_by, processed_at, etc.
Download and Document Media
GET /api/v1/knowledge-bases/{kb_id}/documents/{doc_id}/downloadReturns the original file's binary content (with Content-Disposition; the filename matches the document name).
GET /api/v1/knowledge-bases/{kb_id}/documents/{doc_id}/media/{filename}Returns media extracted during document parsing (such as images embedded in docx or Markdown). The body is binary with a type-appropriate Content-Type (for example image/png or image/jpeg). {filename} must be one of the filenames produced by that document's parsing. Both endpoints require kb:read.
Update Document
PUT /api/v1/knowledge-bases/{kb_id}/documents/{document_id}Only the document name can be updated:
{"name": "Updated Title.pdf"}Delete Document
DELETE /api/v1/knowledge-bases/{kb_id}/documents/{document_id}Successful response has data: null.
Document Processing Lifecycle
Uploading a document creates it with status: "pending"; upload does not process it automatically. The processing flow is: pending → processing → completed (or error).
Process a Pending Document
POST /api/v1/knowledge-bases/{kb_id}/documents/{document_id}/processOptional JSON body:
{"chunk_size": 1000, "chunk_overlap": 100, "separator": null, "clean_text": true}Returns 200 OK with the document object, normally transitioning to processing before asynchronous embedding completes.
Process with Edited Chunks
POST /api/v1/knowledge-bases/{kb_id}/documents/{document_id}/process-with-chunksRequest body contains custom chunks:
{"chunks": [{"content": "A chunk of text", "chunk_index": 0}]}This replaces the document chunks and starts embedding.
Preview Chunks
POST /api/v1/knowledge-bases/{kb_id}/documents/{document_id}/preview-chunksRequires kb:read scope. Body accepts chunk_size (minimum 100), chunk_overlap, optional separator, and clean_text. Response contains total_chunks, total_tokens, total_chars, and chunks array.
Reprocess and Retry
POST /api/v1/knowledge-bases/{kb_id}/documents/{doc_id}/reprocess
POST /api/v1/knowledge-bases/{kb_id}/documents/{doc_id}/retry-failed-chunks
POST /api/v1/knowledge-bases/{kb_id}/documents/{doc_id}/chunks/{chunk_id}/retry-embeddingreprocess: Re-chunks and re-embeds the documentretry-failed-chunks: Re-runs all failed chunk embeddingsretry-embedding: Re-runs a single failed chunk
Each returns 200 OK with the document object.
Document Chunks
GET /api/v1/knowledge-bases/{kb_id}/documents/{document_id}/chunks?page=1&page_size=50
POST /api/v1/knowledge-bases/{kb_id}/documents/{document_id}/chunks?after_index=0
PUT /api/v1/knowledge-bases/{kb_id}/documents/{document_id}/chunks/{chunk_id}
DELETE /api/v1/knowledge-bases/{kb_id}/documents/{document_id}/chunks/{chunk_id}
POST /api/v1/knowledge-bases/{kb_id}/documents/{document_id}/rechunk- List: Uses
items/total/page/page_sizepagination - Create: Inserts a new chunk after
after_index; body{"content": "..."} - Update: Body
{"content": "..."} - Rechunk: Accepts
chunk_size,chunk_overlap, and optionalseparator
Each endpoint requires kb:read/kb:update/kb:delete according to the operation.
Retrieval
Single Retrieval
POST /api/v1/knowledge-bases/{kb_id}/searchRequest fields:
| Field | Type | Required | Description |
|---|---|---|---|
query | string | Yes | Search query (max 1000 chars) |
search_mode | string | No | vector, fulltext, hybrid (default: hybrid) |
top_k | integer | No | Number of results (default: 5, max: 20) |
score_threshold | float | No | Minimum dense similarity score (0.0-1.0, default: 0.0) |
dense_weight | float | No | Dense RRF weight (default: 1.0) |
lexical_weight | float | No | Lexical RRF weight (default: 1.0) |
rrf_k | integer | No | RRF rank constant (default: 60) |
filter_doc_ids | array | No | Restrict search to specific document IDs |
rerank_enabled | boolean | No | Override rerank enabled setting |
rerank_candidate_k | integer | No | Override rerank candidate pool size |
rerank_score_threshold | float | No | Override rerank score threshold (null disables) |
curl -X POST "https://your-domain.com/api/v1/knowledge-bases/{kb_id}/search" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"query": "How to reset password", "search_mode": "hybrid", "top_k": 5}'Query length is limited to 1-1000 characters; in hybrid mode, dense_weight and lexical_weight cannot both be 0.
Each result in the response results array contains chunk_id, document_id, document_name, content, score, metadata, search_type, and per-stage scores: dense_score, lexical_score, fusion_score, rerank_score, rerank_rank. The timings array records recall, rerank, total stage latencies in milliseconds.
In hybrid retrieval mode, dense_weight and lexical_weight cannot both be 0; the request will be rejected.
Multi-Config Comparison Retrieval
POST /api/v1/knowledge-bases/{kb_id}/search/batchRequest body is an array of retrieval configs, each executed independently and returned for parameter comparison.
Cross-Team Sharing
Share a knowledge base with other teams in the organization with read-only access. Sharing grants read access only: listing, details, document listing, chunk reads, and search work for the receiving teams, but no write endpoint (updating/deleting a KB, uploading/processing/deleting documents, creating/updating/deleting chunks) is opened up by a share — writes still require the caller to be a member of the owning team (and usually an owner/admin role).
Creating or modifying a share requires the owner or admin role within the knowledge base's owner team; otherwise the request returns 403 with TEAM_ADMIN_REQUIRED. Superusers and admin-scoped platform calls bypass this team-role requirement. Listing shares only requires membership in that team.
Share Knowledge Base
POST /api/v1/knowledge-bases/{kb_id}/share{
"team_id": "target-team-uuid",
"permission": "read_only"
}Returns a KnowledgeBaseShareOut record with id, knowledge_base_id, knowledge_base_name, shared_with_team_id, shared_with_team_name, permission (currently always read_only), shared_by_id, shared_by_name, and shared_at.
These cases are rejected:
| Case | HTTP | Description |
|---|---|---|
KB visibility is private | 400 | Private KBs cannot be shared (private_kb_cannot_be_shared) |
| The target team is the owning team | 400 | A KB cannot be shared with its own team (kb_cannot_share_to_own_team) |
| The team already has the share | 400 | Duplicate share (kb_already_shared) |
| The target team does not exist | 404 | team_not_found |
List Knowledge Base Shares
GET /api/v1/knowledge-bases/{kb_id}/sharesReturns { "shares": [...], "total": N }, ordered by shared_at descending.
Remove Knowledge Base Share
DELETE /api/v1/knowledge-bases/{kb_id}/share/{team_id}Requires kb:delete and the owner/admin role in the owning team; on success data is null.
Knowledge Base Statistics
GET /api/v1/knowledge-bases/{kb_id}/statsReturns document_count, total_chunks, total_tokens, documents_by_status (distribution by status), documents_by_type (distribution by type), embedding_dimension, embedding_stats (total_vectors, missing_vectors).
Error Codes
| Code | Message | Description |
|---|---|---|
6000 | KB not found | Knowledge base does not exist |
6001 | Name already exists | KB name is taken |
6002 | Document not found | Document does not exist |
6003 | Invalid document type | Document type is not supported |
6004 | Document processing failed | Document processing error |
3000 | Permission denied | Insufficient permissions |
1001 | Validation failed | Invalid request data |
There are no per-endpoint rate limits; no rate-limit middleware is implemented on these endpoints.
How is this guide?