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

FieldTypeRequiredDescription
namestringYesDocument name (1-255 characters)
source_urlstringNoWeb page or YouTube address (up to 1024 characters); fetched server-side when the document is processed
doc_typestringNoDocument type, defaults to url
{"name": "Page Title", "source_url": "https://example.com/page", "doc_type": "url"}

The document is created with status pending; call a process endpoint before the page is fetched, chunked, and indexed.

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

The body carries the custom chunks plus optional batch aggregation fields:

{
  "chunks": [{"content": "A chunk of text", "chunk_index": 0}],
  "batch_id": "0f7c2b1e-8a44-4c1f-9a0e-2d5c8f6b1a33",
  "batch_total": 3
}
FieldTypeRequiredDescription
chunksarrayYesAt least one chunk; each needs content (non-empty) and a zero-based chunk_index
batch_idUUIDNoBatch ID shared by every document in the batch, used to aggregate completion notifications
batch_totalintegerNoNumber of documents in the batch; provide it together with batch_id

This replaces the document chunks and starts embedding. The server tracks progress with Redis counters (kb_batch:{batch_id}:remain, :total, :success, :failed; TTL 7200 seconds) and sends one aggregated notification when the last document finishes (all succeeded, all failed, or partial success — partial success prefers the failure notification; the switches and wording come from the site notification settings). Without batch_id each document notifies on its own.

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. This endpoint searches only the knowledge base in the path; global fusion and single-rerank across several knowledge bases run inside agent/workflow retrieval.

Response shape:

FieldDescription
queryThe original query
resultsResult array, described below
totalNumber of results
diagnosticsPer-knowledge-base diagnostics (kb_id, code, detail, stage)
timingsStage latencies in milliseconds: recall, rerank, context, total

Each result contains chunk_id, document_id, document_name, content, score, metadata, search_type, and per-stage values: dense_score/dense_rank, lexical_score/lexical_rank, fusion_score/fusion_rank, rerank_score/rerank_rank/rerank_reason, final_score_stage (dense/lexical/fusion/rerank), plus channel degradation reasons in degradation_reasons (for example full-text recall failed but vector results were returned). Score fields for a channel that did not recall the chunk are null.

{
  "code": 0,
  "data": {
    "query": "How to reset password",
    "total": 1,
    "results": [
      {
        "chunk_id": "chunk-012",
        "document_id": "doc-789",
        "document_name": "Account handbook",
        "content": "Click reset password in personal settings…",
        "score": 0.032,
        "search_type": "hybrid",
        "dense_score": 0.86,
        "dense_rank": 1,
        "lexical_score": 4.12,
        "lexical_rank": 2,
        "fusion_score": 0.032,
        "fusion_rank": 1,
        "final_score_stage": "fusion"
      }
    ],
    "diagnostics": [],
    "timings": [
      {"stage": "recall", "latency_ms": 120.4},
      {"stage": "rerank", "latency_ms": 0},
      {"stage": "context", "latency_ms": 1.8},
      {"stage": "total", "latency_ms": 127.9}
    ]
  },
  "msg": "success"
}

In hybrid retrieval mode, dense_weight and lexical_weight cannot both be 0; the request is rejected. Hybrid mode also sits behind the site rollout: a team outside it degrades silently to pure vector with no separate degradation flag in the response.

Multi-Config Comparison Retrieval

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

One query, several independently executed configurations, for comparing parameters:

{
  "query": "How to reset password",
  "configurations": [
    {"id": "baseline", "search_mode": "hybrid", "top_k": 5},
    {"id": "dense-only", "search_mode": "vector", "top_k": 5, "score_threshold": 0.6}
  ]
}
  • configurations accepts at most 10 items; each id is required (max 64 characters) and must be unique; configuration fields match single retrieval.
  • The response is { "query": "...", "outcomes": [...] }. outcomes follows request order and each item carries id and status: fulfilled includes the full response (same shape as single retrieval), rejected includes error (code, retrieval_error_category, stage).
  • A failure in one configuration never hides the results of the others.

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