Skip to main content
Base path: /api/knowledge-bases
Knowledge bases store documents that agents use for RAG (Retrieval-Augmented Generation). When an agent has a knowledge base attached, relevant document chunks are automatically retrieved and injected into each LLM call - both in the playground and during voice calls. Related: Agents API (linking KB to agent) | Voice Agents (RAG in voice pipeline)

Types


Knowledge Base Endpoints

Create a new knowledge base

Defaults Applied: What happens on creation:
  1. Knowledge base record is created in the database
  2. A Qdrant vector collection is created: kb_{knowledgeBaseId}
    • Vector dimension: 1536 (matching OpenAI text-embedding-3-small)
    • Distance metric: Cosine
Status Codes:
Response:

List knowledge bases

Status Codes:

Get a single knowledge base by ID

Status Codes:

Update a knowledge base

Note: embeddingModel and chunkConfig cannot be changed after creation because changing them would require re-embedding all existing documents. Status Codes:

Delete a knowledge base and all its documents, vectors, a…

Cleanup order:
  1. Delete Qdrant collection (kb_{id}) - removes all vectors
  2. Delete all S3 files via FileService
  3. Soft-delete all knowledge_base_documents records
  4. Soft-delete knowledge_bases record
Status Codes:

Document Endpoints

Upload a document for processing

Constraints: Processing Pipeline (async, after 202 response):
Status Codes:

List documents in a knowledge base

Status Codes:

Get a single document’s status and details

Status Codes: Processing in progress:
Processing complete:
Processing failed:

Delete a document, its S3 file, and all its vectors

Cleanup order:
  1. Delete vectors from Qdrant (filtered by documentId)
  2. Delete S3 file via FileService
  3. Soft-delete knowledge_base_documents record
  4. Decrement documentCount on the knowledge base (only if document status was 'ready')
Status Codes:

Linking a Knowledge Base to an Agent

To enable RAG for an agent, update the agent with a knowledgeBaseConfig:
To remove the KB link:
See agents.md for the full agent update API.

RAG Retrieval Behavior

When an agent has a knowledgeBaseConfig, retrieval happens automatically:

In Playground (POST /agents/:id/test)

  1. User sends a message
  2. The message is embedded using the KB’s embedding model
  3. Top-K similar chunks are retrieved from Qdrant (filtered by documentGroups if set)
  4. Chunks below similarityThreshold are discarded
  5. Remaining chunks are formatted and prepended to the user message
  6. The enriched message is sent to the LLM

In Voice Calls (CONNECT_AGENT node)

Same flow as playground, but runs on every conversation turn:
  1. User speaks, speech is transcribed (STT)
  2. A context-aware search query is built (includes previous turn for pronoun resolution)
  3. Top-K chunks are retrieved from Qdrant
  4. Chunks are formatted and prepended to the transcript
  5. The enriched transcript is sent to the LLM
  6. LLM response is synthesized to speech (TTS)

Context Injection Format

The LLM sees the user message in this format:
The agent’s system prompt includes static instructions on how to use the retrieved context:

Graceful Degradation

RAG failures never break the agent. If retrieval fails (Qdrant down, embedding API error, network timeout), the agent responds without KB context - it may hallucinate, but the conversation continues.

RAG Latency Budget

This adds ~5-8% to total voice turn latency (~1.3-2.5s).

Defaults & Limits Reference


Document Status State Machine

Processing Steps (within processing status):
Each step updates the processingStep field. On failure, the step is preserved to show where the pipeline broke. The S3 file is always preserved on failure to allow manual retry.

Frontend Integration Notes

Document Upload Flow

  1. Show file picker (accept .txt, .md, .pdf, max 10MB)
  2. POST multipart/form-data to POST .../documents
  3. Receive 202 Accepted with document object (status: 'uploading')
  4. Poll GET .../documents/:docId every 2-3 seconds
  5. Show progress based on processingStep: parsing -> chunking -> embedding -> upserting
  6. When status becomes 'ready', show success with chunkCount
  7. When status becomes 'failed', show errorMessage

Document Groups

Document groups allow agents to query only relevant subsets of a KB:
  • Set documentGroup during upload (default: 'default')
  • Configure documentGroups array in agent’s knowledgeBaseConfig
  • If documentGroups is null/undefined, all documents in the KB are searched
  • Example: A KB has groups ['product-docs', 'faqs', 'internal-notes']. An agent configured with documentGroups: ['product-docs', 'faqs'] will only search those two groups.

Processing Step Progress UI

Map processing steps to a progress bar: