Knowledge Base
Understand document parsing, chunking and embedding, hybrid retrieval, and read-only cross-team sharing
A knowledge base turns documents into chunks that Agents and workflows can retrieve. The resource belongs to a team, picks an embedding model at creation (plus an optional rerank model), and ingests content from several sources.
Deep-dive retrieval and ingestion pipeline
┌───────────────────────────┐ ┌────────────────────────────────────────────────────────┐
│ Upload document │ ──► │ MarkItDown multi-format parser │
│ (PDF, DOCX, XLSX, HTML...)│ │ • Base64 embedded media extraction -> asset storage │
└───────────────────────────┘ │ • Structural flattening and XSS cleaning (Bleach) │
└────────────────────────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────┐
│ CJK-optimized two-stage splitting engine │
│ • Escaped-newline hard split (\n\n, \n) │
│ • Zero-overlap recursive punctuation split + │
│ exact character-level trailing overlap │
└────────────────────────────────────────────────────────┘
│
┌────────────────────┴────────────────────┐
▼ ▼
┌──────────────────────────────┐ ┌──────────────────────────────┐
│ PostgreSQL 17 + pg_search │ │ Qdrant vector engine │
│ • BM25 Tantivy lexical index │ │ • Dense vectors ({prefix}_{dim})│
└──────────────────────────────┘ └──────────────────────────────┘
│ │
└────────────────────┬────────────────────┘
▼
┌────────────────────────────────────────────────────────┐
│ Weighted Reciprocal Rank Fusion (RRF, k=60) │
│ • Single-channel fallback and shared vector caching │
└────────────────────────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────┐
│ Optional Cross-Encoder neural rerank │
└────────────────────────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────┐
│ Context assembly and token budget protection │
│ • Per-document chunk cap and total budget control │
└────────────────────────────────────────────────────────┘- Document parsing and embedded media extraction:
- Multi-format support:
MarkItDownparses PDF, DOCX, PPTX, XLSX, HTML, CSV, TXT, MD, and JSON. - Automatic media extraction (
replace_embedded_media_data_uris): base64 images embedded in a document are extracted into separate stored assets (/knowledge-bases/{kb_id}/documents/{doc_id}/media/{filename}) and replaced with lightweight URLs so vectors and token space do not balloon. - Structural flattening and cleaning: CSV becomes a Markdown table, JSON is flattened into dotted-path keys, and
bleachstrips dangerous tags.
- Multi-format support:
- CJK-aware splitting:
- Custom separators pass through
_decode_separator_escapes, which turns\n,\r,\t, and\\back into real control characters — that is why typing\n\nin the form splits on newlines. - Chunks are split with zero internal overlap using a punctuation hierarchy (
\n\n,\n,。,!,?,.,!,?,;,;,,,,, space, character), then exact character-level trailing slices of preceding chunks are prepended, guaranteeing deterministic token boundaries. - Tables and code blocks are preserved structurally: small tables stay intact, while large tables split row by row with the header repeated in every sub-chunk so character slicing cannot break the meaning.
- Custom separators pass through
- Dual-engine hybrid retrieval and weighted RRF:
- Lexical retrieval: PostgreSQL
pg_search(BM25 index). - Dense vectors: the Qdrant vector database (collections partitioned by
{prefix}_{dimension}). - Weighted RRF fusion: computes weighted reciprocal-rank fusion scores (defaults
k = 60,dense_weight = 1.0,lexical_weight = 1.0). When one channel fails, retrieval degrades to single-channel recall.
- Lexical retrieval: PostgreSQL
- Neural rerank (cross-encoder): reranking is on by default (
rerank_enabled = true); the toprerank_candidate_k(default10, range1-100) RRF candidates go to the cross-encoder for rescoring and are filtered by the optionalrerank_score_threshold(0-1, no threshold by default). - Context assembly and budget protection: bounded by
context_token_budget(total token budget) andmax_chunks_per_document(per-document chunk cap) so one long file cannot starve other retrieved results.
Chunking and embedding
chunk_sizedefaults to1000characters (minimum100, form maximum2000) andchunk_overlapto100characters (minimum0); both are measured in characters, not tokens, and token estimates use4characters ≈1token.- When
separatoris empty, the built-in priority separator list applies; a custom separator replaces the first primary separator while the remaining levels act as fallbacks. - A knowledge base must pick an embedding model and dimension at creation:
embedding_model_idcannot be changed afterwards, and the dimension is recorded when the first document is processed. Every later document and query must match that dimension or fail with a dimension-mismatch error. Changing the signature or dimension requires an explicit reprocess/rechunk or a new knowledge base.
Retrieval and ranking
| Parameter | Default | Range | Notes |
|---|---|---|---|
search_mode | Knowledge base setting empty (effective default hybrid) | vector / fulltext / hybrid | Overridable per request; hybrid mode requires at least one positive weight |
top_k | 5 | Search request 1-20, knowledge base setting up to 100 | Number of results returned |
score_threshold | 0.0 | 0-1 | Minimum dense similarity |
dense_weight / lexical_weight | 1.0 / 1.0 | >= 0 | RRF channel weights |
rrf_k | 60 | 1-1000 | RRF rank constant |
rerank_candidate_k | 10 | 1-100 | Rerank candidate pool size |
Adjacent-chunk expansion (expand_adjacent) is an internal retrieval option, off by default, and is not exposed by the current public search endpoint (POST /knowledge-bases/{id}/search), so never present it as an available parameter in the retrieval lab or API docs. It can be enabled inside the internal retrieval service, where it additionally fetches the chunk_index ± 1 siblings of a hit to restore the paragraph; no built-in caller enables it today.
Team visibility and cross-team sharing
- A knowledge base belongs to a team: team members access it by role, and a
privateknowledge base is visible only to its creator. - Cross-team sharing is read-only:
KnowledgeBaseSharePermissionhas exactly one value,read_only, so the team it is shared with can list and search it but cannot upload documents, change settings, or delete it. Write operations still require membership in the owning team (and a team admin where needed). - Sharing constraints: a
privateknowledge base cannot be shared (private_kb_cannot_be_shared), it cannot be shared with the owning team itself, and a duplicate share returnskb_already_shared. - On the list endpoint,
include_shareddefaults totrue(knowledge bases shared with the current team are listed too) andown_onlydefaults tofalse; combining them switches from "including shared" to "this team only".
Retrieval lab
The Retrieval Lab runs single-configuration tests or A/B comparisons, showing each result's rank and score across the vector, full-text, fusion, and rerank stages, and can apply a local preset to the production knowledge base settings. When comparing chunking strategies, confirm the split result in the preview first, then rechunk processed documents.
Related content: Import documents, Chunking, Retrieval and quality tuning, Knowledge base settings reference.
How is this guide?