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.
retrieval_config field | Type | Notes |
|---|---|---|
method | string | vector_search / full_text / hybrid / tree_search. |
top_k | int | Results returned after any reranking. |
vector_weight | float | Hybrid only — balance of semantic vs keyword (default 0.5). |
context_mode | string | text (default) or image for multimodal retrieval. All strategies except Doc2JSON. |
reranker | object | { model, candidate_count }. Present ⇒ reranking on; omit ⇒ off. |
query_enrichment | object | { enabled, model }. LLM query rewriting; enabled defaults to false. |
PATCH (see below). Reranking, query enrichment, and context_mode take effect immediately on the next search — 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.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.
KB ID
DELETE /api/knowledge-bases/
Delete a knowledge base and all its indexed data.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, so you get both index status and source metadata in one response.
KB ID
Case-insensitive substring match on the source’s
name.Exact match on
index_status (pending, indexing, indexed, failed, cancelled).name or created_at. When omitted, sorts failed-first then newest-source-first — useful for surfacing problems at the top of a UI list.asc or desc (default desc). Ignored when sort is omitted.Page size. Defaults to 50, capped at 200.
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.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.
KB ID
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.
KB ID
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 — 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.
KB ID
Restrict to specific
indexed_sources.id values. If supplied, this wins — failed_only is ignored.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. Operator path — most KBs never need this, but it’s useful after changingretrieval_config tuning knobs or recovering from a partial index.
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.
This is the right endpoint when you want to enumerate everything the platform produced from a source — for export, debugging, or to consume Doc2JSON extracted_json directly without going through retrieval.
KB ID
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.Max items to return. Default 1000, capped at 10000.
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:
| Strategy | Source table | text is | Extra fields |
|---|---|---|---|
chunk_embed | ai.chunks | full chunk text | chunk_index, start_char, end_char, tokens |
page_index | ai.page_index_nodes | node text | node_id, title, depth, parent_node_id |
graph_index | ai.graph_index_nodes | node text | node_id, title, depth, parent_node_id |
full_document | ai.full_documents | document summary | full_text_path |
doc2json | ai.doc2json_documents | document summary | extracted_json |
POST /api/knowledge-bases//search
Run a search against the knowledge base.KB ID
| Body field | Type | Notes |
|---|---|---|
query | string (required) | Natural-language search query |
top_k | int | Number of results to return. Default 5 (or KB_DEFAULT_TOP_K setting) |
retrieval_method | string | vector_search / full_text / hybrid / tree_search. Omit to use the KB’s configured default — the response carries retrieval_method: "auto" to indicate this. |
similarity_threshold | float | Minimum vector score (0–1). Items below this are filtered out. Default 0.0. |
filter_metadata | object | Narrow to chunks whose enrichment-metadata fields match. Keys are field names from the KB’s enrichment config (see /enrichment); values can be scalars or { "op": "...", "value": ... } shapes. |
source_ids | array of UUIDs | Restrict to chunks from this set of sources only. Useful for “search inside one specific document.” |
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> }.
KB ID
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.Model identifier (e.g.
gpt-4o).Max tokens per enrichment call.
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.
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.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.
KB ID
Skip items that already have metadata.
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.
KB ID
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.
KB ID
Limit to a single source’s references.
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.
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 exact 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).
| Status | Description |
|---|---|
| 400 | Invalid chunking, embedding, or enrichment field configuration |
| 400 | Endpoint requires a specific indexing_config.strategy (e.g. graph-enrichment endpoints require graph_index) |
| 404 | No knowledge base or indexed source exists with the given ID |
| 404 | No enrichment config exists (DELETE /enrichment, GET /enrichment/results) |
| 409 | Indexing for this source has already finished or been cancelled (/sources/{id}/cancel) |
| 409 | Cannot update or delete enrichment config while a run is active |
| 503 | Failed to dispatch the indexing task (worker unavailable) |