Skip to main content
Knowledge bases let agents retrieve relevant documents at query time, grounding their responses in your data.

How It Works

Documents → Chunking → Embedding → Vector Storage (PGVector)

User Query → Query Expansion → Semantic Search → Reranking → Agent Context

Creating a Knowledge Base

POST /knowledge-bases
{
  "name": "Product Docs",
  "description": "Internal product documentation",
  "chunk_size": 512,
  "overlap_percentage": 0.1,
  "embedding_model": "text-embedding-3-small"
}

Adding Documents

POST /knowledge-bases/{kb_id}/documents
Content-Type: multipart/form-data

file: @product-guide.pdf
AgentFlow processes the document through:
  1. Chunking — splits into overlapping segments with context preservation
  2. ML enrichment — optional table and layout extraction
  3. Embedding — generates vector representations
  4. Storage — persists in PostgreSQL with PGVector

Searching

POST /knowledge-bases/{kb_id}/search
{
  "query": "How does billing work?",
  "top_k": 5
}

Search Pipeline

StageDescription
Query expansionRewrites the query into multiple variants
Semantic searchCosine similarity against embedded chunks
Hybrid searchCombines semantic with BM25 keyword matching
RerankingLLM or cross-encoder reorders results by relevance

Agent Integration

When an agent has enable_retrieval=True and is linked to a knowledge base, retrieval happens automatically:
  1. The user sends a message
  2. The agent searches its knowledge bases
  3. Top results are injected into the prompt context
  4. The agent responds using the retrieved information

Configuration

KBConfig(
    name="Product Docs",
    description="Internal docs",
    chunk_size=512,
    overlap_percentage=0.1,
    vector_db_type="pgvector",
    embedding_model="text-embedding-3-small",
    reranker_model="rerank-english-v3.0",
    enable_query_processors=True,
    enable_ml_processing=False,
)