Common Patterns
Create a knowledge base, add one or more sources to trigger indexing, then use the search endpoint to query. Check indexing status by fetching the knowledge base details. Reindex when you change chunking parameters or want to re-process sources.GET /api/knowledge-bases
List all knowledge bases.POST /api/knowledge-bases
Create a new knowledge base. Onlyname is required. You can also pass indexing_config (how sources are chunked/embedded) and retrieval_config (how the KB is searched); anything you supply is merged over the strategy’s defaults rather than replacing them. The retrieval-side features (reranking, query enrichment, and multimodal retrieval) all live inside retrieval_config and are persisted on the KB, so the minimal example and the fully-configured example below differ only in how much of that object you fill in.
All of these are editable later via
PATCH (see below). Reranking, query enrichment, and context_mode take effect on the next search with no reindex. Changing indexing_config (chunking, embedding model, strategy) requires a reindex to take effect. See Knowledge bases & indexing for the per-strategy indexing_config fields.
GET /api/knowledge-bases/
Get a knowledge base with its indexed sources and status.string
required
KB ID
PATCH /api/knowledge-bases/
Update knowledge base configuration or strategy. Accepts the samename, description, indexing_config, and retrieval_config fields as create. Send the full retrieval_config object you want; it is stored as-is. Reranking, query enrichment, and context_mode changes apply to the next search immediately; indexing_config changes need a reindex to take effect.
string
required
KB ID
DELETE /api/knowledge-bases/
Delete a knowledge base and all its indexed data.string
required
KB ID
GET /api/knowledge-bases//sources
Paginated, filterable, sortable list of the sources indexed into a knowledge base. Each item joins theindexed_sources row with its underlying sources row, returning both index status and source metadata in one response.
string
required
KB ID
string
Case-insensitive substring match on the source’s
name.string
Exact match on
index_status (pending, indexing, indexed, failed, cancelled).string
name or created_at. When omitted, sorts failed-first then newest-source-first, which surfaces problems at the top of a UI list.string
asc or desc (default desc). Ignored when sort is omitted.integer
Page size. Defaults to 50, capped at 200.
integer
Skip the first N rows. Defaults to 0.
id is the indexed_sources.id (use this with the cancel, reindex, and DELETE endpoints below). source_id is the underlying ai.sources row.
POST /api/knowledge-bases//sources
Add a source to the knowledge base. Triggers asynchronous indexing.string
required
KB ID
POST /api/knowledge-bases//sources//cancel
Cancel an in-progress indexing task. Onlypending and indexing rows can be cancelled; anything already indexed, failed, or cancelled returns 409. Returns 404 if no indexed_sources row matches the given pair.
string
required
KB ID
string
required
The
indexed_sources.id returned when the source was added (not the source UUID itself).DELETE /api/knowledge-bases//sources/
Remove a source from a knowledge base. The underlyingai.sources row is not touched, only its link to this KB and everything the indexing pipeline produced from it. The source stays available to re-add to other KBs.
Deleting the indexed_sources row cascades through all eight derivative tables: ai.chunks, ai.embeddings, ai.full_documents, ai.doc2json_documents, ai.page_index_toc, ai.page_index_nodes, ai.graph_index_toc, ai.graph_index_nodes. After the call, the source contributes nothing to retrieval in this KB.
If the source is mid-indexing (status pending or indexing with a celery_task_id), the Celery task is revoked before the row is deleted. A revoke failure logs a warning but does not block the deletion; the row goes regardless. Returns 200 with a small JSON body, or 404 if no indexed_sources row matches the given (kb_id, indexed_source_id) pair.
string
required
KB ID
string
required
The
indexed_sources.id returned when the source was added (not the source UUID itself).POST /api/knowledge-bases//reindex
Re-index sources in the knowledge base. The body is optional; an empty body re-indexes every source. Passindexed_source_ids to re-index a specific subset, or failed_only: true to retry only sources currently in failed status.
string
required
KB ID
string[]
Restrict to specific
indexed_sources.id values. If supplied, this wins and failed_only is ignored.boolean
When true (and
indexed_source_ids is empty), re-index only sources currently in failed status. Returns {"status": "noop"} if there are none.POST /api/knowledge-bases//build-bm25
Dispatch a one-shot BM25 rebuild for this KB. Re-tokenizes the entire item table for the KB’s strategy (chunks / full_documents / graph_index_nodes) and writes a fresh BM25 index, replacing whatever was there. This is an operator path: most KBs never need it, but it helps after changingretrieval_config tuning knobs or recovering from a partial index.
string
required
KB ID
Only valid for KBs whose
retrieval_config.method is hybrid or full_text. Vector-only KBs return 400 (BM25 isn’t part of their retrieval path).202 + {"task_id": "celery-task-uuid", "knowledge_base_id": "kb-uuid"}. Poll the KB’s bm25_status field via GET /api/knowledge-bases/{id} to observe completion. Returns 503 if the Celery worker can’t be reached.
POST /api/knowledge-bases//items
Fetch the indexed content items (chunks, nodes, or extracted JSON) for one or more source documents. The response shape depends on the KB’sindexing_config.strategy; every item carries id, source_id, text, and meta, plus strategy-specific extras.
Use this endpoint to enumerate everything the platform produced from a source: for export, debugging, or to consume Doc2JSON extracted_json directly without going through retrieval.
string
required
KB ID
string[]
required
Non-empty list of source UUIDs (
sources.id). Items from sources that were never added to this KB return zero rows for that ID rather than an error.integer
Max items to return. Default 1000, capped at 10000.
integer
Pagination offset. Default 0.
text field is the embeddable representation of the item (full chunk text for chunk_embed, node body for page_index/graph_index, document summary for full_document/doc2json). Strategy-specific extras:
POST /api/knowledge-bases//search
Run a search against the knowledge base.string
required
KB ID
Per-request overrides for retrieval tuning are also accepted:
vector_weight (hybrid only), context_mode (text or image; see Multimodal Retrieval), ts_language (full-text language for stemming), and reranker fields. These override the KB’s stored retrieval_config for this one request only.
The reranker, query-enrichment, and multimodal (context_mode) behaviors are all properties stored on the KB’s retrieval_config. Set them at creation or change them later with PATCH. See the create body below and the knowledge bases concept guide for the full field reference.
Metadata Enrichment
Metadata enrichment runs an LLM over each indexed item to extract structured fields (text, boolean, number, enum) into a per-KB metadata table. The enriched values can then be used as filters in the/search filter_metadata parameter. PUT triggers re-enrichment only when something material changes (see the endpoint notes below).
PUT /api/knowledge-bases//enrichment
Create or replace the enrichment config. Re-enrichment behavior depends on what changed:- Changes to
fieldsorllm_model: drop the metadata table, recreate it, and re-enrich every item from scratch. Returns 409 if a run is already in progress. - Toggle of
use_multimodal: keep the table, but re-enrich because results differ with/without images. Returns 409 if a run is in progress. max_tokens-only change: lightweight update, no re-enrichment.- Identical body: no-op.
{ "config": {...}, "re_enrichment_triggered": <bool> }.
string
required
KB ID
object[]
required
Field definitions. Each:
{ name, description, type: "text"|"boolean"|"number"|"enum", enum_values?: string[] }. name must be SQL-safe (alphanumeric + underscores, starts with a letter) and not in the reserved set (id, item_id, item_type, enriched_at, _enrichment_error). enum types require enum_values with at least 2 entries.string
Model identifier (e.g.
gpt-4o).integer
Max tokens per enrichment call.
boolean
When true, the enricher sees page images alongside text.
GET /api/knowledge-bases//enrichment
Get the current enrichment config and run status. Returns{"config": null} if no config exists. The config includes status (idle, enriching, completed, completed_with_errors, failed), enriched_count, total_count, and the dynamic metadata_table_name.
string
required
KB ID
DELETE /api/knowledge-bases//enrichment
Remove the enrichment config and drop its metadata table. Returns 404 if no enrichment config exists, or 409 if a run is in progress.string
required
KB ID
POST /api/knowledge-bases//enrichment/run
Manually trigger enrichment. Withincremental: true only items missing metadata are processed; with retry_failed: true items previously marked failed are retried.
string
required
KB ID
boolean
Skip items that already have metadata.
boolean
Re-enrich items currently marked failed.
GET /api/knowledge-bases//enrichment/results
Fetch enriched metadata for specific items. Pass a comma-separateditem_ids query parameter. Returns per-item field values plus item_errors for any items that failed enrichment.
string
required
KB ID
string
required
Comma-separated item UUIDs (chunk/node IDs from
/items).Graph-index re-enrichment
Specific to KBs whoseindexing_config.strategy is graph_index. These endpoints re-run reference enrichment (Stages 2+3) without a full reindex.
POST /api/knowledge-bases//graph-enrichment/run
Re-run graph reference enrichment. Optionally limit to a singleindexed_source_id, or set retry_failed: true to retry only the previously-failed references. Returns 400 if the KB strategy is not graph_index.
string
required
KB ID
string
Limit to a single source’s references.
boolean
Retry only previously-failed references.
GET /api/knowledge-bases//graph-enrichment/errors
Per-source enrichment error counts. Useful for surfacing which sources need retry. Returns 400 if the KB is notgraph_index.
string
required
KB ID
Discoverable defaults
GET /api/config/kb-defaults
Returns the platform’s KB-creation defaults so a UI or self-service KB-creation flow can present valid options without hardcoding them. The Studio’s KB-create wizard uses this endpoint. Returns:strategies: map of strategy name →{ label, compatible_retrievers, retriever_labels, default_retrieval_method, supports_reranker, default_indexing_config, default_retrieval_config }. The strategies are the indexing strategies described in Knowledge bases & indexing.reranker:{ default_model, candidate_count, options }.optionsis the list of supported reranker models (Cohere v3, Jina v2, Voyage 2.5, ZeroEntropy zerank-2, etc.).query_enrichment:{ model }(the model used to rewrite/expand user queries).enrichment:{ model, max_tokens }(the LLM used for chunk metadata enrichment).hybrid_vector_weight: default weight for hybrid search (vector vs. sparse contribution).extraction:{ default_method, fallback_chain, options }.optionslists every supported extraction method (mistral, paddleocr, lighton, opendataloader, fitz, pdfplumber, plusauto) with a one-line description of each.
Error Responses
KB routes return{"error": "<message>"} (no structured error code field).