ClouisleClouisle

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

ScopeDescription
kb:readList and view knowledge bases
kb:testRun searches against knowledge bases
kb:createCreate knowledge bases
kb:updateUpdate knowledge bases and upload documents
kb:deleteDelete knowledge bases and documents

Endpoint Overview

MethodPathPurpose
GET/POST/knowledge-basesPaginated query / create a knowledge base
GET/PUT/DELETE/knowledge-bases/{kb_id}Details / update / delete
GET/knowledge-bases/{kb_id}/statsStatistics
GET/knowledge-bases/{kb_id}/documentsDocument list
POST/knowledge-bases/{kb_id}/documents/uploadUpload a file
POST/knowledge-bases/{kb_id}/documents/urlImport a URL
GET/knowledge-bases/{kb_id}/documents/{doc_id}Document details
GET/knowledge-bases/{kb_id}/documents/{doc_id}/downloadDownload 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}/processProcess document
POST/knowledge-bases/{kb_id}/documents/{doc_id}/process-with-chunksProcess with edited chunks
POST/knowledge-bases/{kb_id}/documents/{doc_id}/preview-chunksPreview chunks
POST/knowledge-bases/{kb_id}/documents/{doc_id}/reprocessReprocess
POST/knowledge-bases/{kb_id}/documents/{doc_id}/retry-failed-chunksRetry failed chunks
POST/knowledge-bases/{kb_id}/documents/{doc_id}/chunks/{chunk_id}/retry-embeddingRetry single chunk embedding
POST/knowledge-bases/{kb_id}/documents/{doc_id}/rechunkRechunk
GET/POST/PUT/DELETE/knowledge-bases/{kb_id}/documents/{doc_id}/chunksChunk CRUD
POST/knowledge-bases/{kb_id}/searchSingle retrieval
POST/knowledge-bases/{kb_id}/search/batchMulti-config comparison retrieval
POST/knowledge-bases/{kb_id}/shareShare the knowledge base with another team
GET/knowledge-bases/{kb_id}/sharesList 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-bases

Query parameters:

ParameterTypeRequiredDefaultDescription
pageintegerNo1Page number
page_sizeintegerNo20Items per page
team_idstringNo-Filter by team ID (requires team membership)
statusarrayNo-Filter by status: active, processing, error, archived (repeatable)
searchstringNo-Search by name or description
own_onlybooleanNofalseOnly return KBs created by the current user (non-superusers)
include_sharedbooleanNotrueAlso 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:

FieldTypeDescription
visibilitystringprivate, team, or public
is_ownedbooleanWhether the KB belongs to the caller's team; false for shared KBs
owner_team_id / owner_team_namestringOwning team ID / name
share_permissionstring | nullPermission granted to a shared KB (currently read_only); null for owned KBs
shared_with_countintegerNumber 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-bases

Request fields:

FieldTypeRequiredDescription
namestringYesKB name (max 100 chars)
descriptionstringNoKB description (max 500 chars)
iconstringNoIcon name or emoji (max 50 chars)
team_idstringYesTeam UUID
embedding_model_idstringNoEmbedding model UUID (must be authorized for the team)
rerank_model_idstringNoRerank model UUID (must be authorized for the team)
settingsobjectNoKB 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.

The embedding model is selected when the knowledge base is created and cannot be changed by the update endpoint.

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/upload

Content-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/url

Request body:

{"name": "Page Title", "source_url": "https://example.com/page", "doc_type": "url"}

List Documents

GET /api/v1/knowledge-bases/{kb_id}/documents

Query parameters:

ParameterTypeRequiredDefaultDescription
pageintegerNo1Page number
page_sizeintegerNo20Items per page
statusarrayNo-pending, processing, completed, error (repeatable)
doc_typearrayNo-pdf, docx, txt, markdown, url, etc. (repeatable)
searchstringNo-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}/download

Returns 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}/process

Optional 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-chunks

Request 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-chunks

Requires 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-embedding
  • reprocess: Re-chunks and re-embeds the document
  • retry-failed-chunks: Re-runs all failed chunk embeddings
  • retry-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_size pagination
  • Create: Inserts a new chunk after after_index; body {"content": "..."}
  • Update: Body {"content": "..."}
  • Rechunk: Accepts chunk_size, chunk_overlap, and optional separator

Each endpoint requires kb:read/kb:update/kb:delete according to the operation.

Retrieval

Single Retrieval

POST /api/v1/knowledge-bases/{kb_id}/search

Request fields:

FieldTypeRequiredDescription
querystringYesSearch query (max 1000 chars)
search_modestringNovector, fulltext, hybrid (default: hybrid)
top_kintegerNoNumber of results (default: 5, max: 20)
score_thresholdfloatNoMinimum dense similarity score (0.0-1.0, default: 0.0)
dense_weightfloatNoDense RRF weight (default: 1.0)
lexical_weightfloatNoLexical RRF weight (default: 1.0)
rrf_kintegerNoRRF rank constant (default: 60)
filter_doc_idsarrayNoRestrict search to specific document IDs
rerank_enabledbooleanNoOverride rerank enabled setting
rerank_candidate_kintegerNoOverride rerank candidate pool size
rerank_score_thresholdfloatNoOverride 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/batch

Request 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:

CaseHTTPDescription
KB visibility is private400Private KBs cannot be shared (private_kb_cannot_be_shared)
The target team is the owning team400A KB cannot be shared with its own team (kb_cannot_share_to_own_team)
The team already has the share400Duplicate share (kb_already_shared)
The target team does not exist404team_not_found

List Knowledge Base Shares

GET /api/v1/knowledge-bases/{kb_id}/shares

Returns { "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}/stats

Returns 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

CodeMessageDescription
6000KB not foundKnowledge base does not exist
6001Name already existsKB name is taken
6002Document not foundDocument does not exist
6003Invalid document typeDocument type is not supported
6004Document processing failedDocument processing error
3000Permission deniedInsufficient permissions
1001Validation failedInvalid request data

There are no per-endpoint rate limits; no rate-limit middleware is implemented on these endpoints.

How is this guide?

On this page