Skip to main content
Optimise how documents are split into chunks for better retrieval quality.
from praisonaiagents import Agent, KnowledgeConfig

agent = Agent(
    name="Researcher",
    instructions="Answer using retrieved document chunks.",
    knowledge=KnowledgeConfig(sources=["docs/"], chunk_size=500, chunk_overlap=50),
)

agent.start("What does our deployment guide say about Docker?")
The user uploads documents; they are chunked and embedded, and the agent retrieves the best slices for each question. Optimize how documents are split into chunks for better retrieval quality.

Chunking Options

from praisonaiagents import Knowledge

knowledge = Knowledge(
    sources=["docs/"],
    chunk_size=500,        # Target chunk size
    chunk_overlap=50,      # Overlap between chunks
    chunking_strategy="semantic"  # Chunking method
)

Strategies

Fixed Size (Default)

knowledge = Knowledge(
    sources=["docs/"],
    chunking_strategy="fixed",
    chunk_size=500,
    chunk_overlap=50
)

Semantic

knowledge = Knowledge(
    sources=["docs/"],
    chunking_strategy="semantic"
)

Sentence-Based

knowledge = Knowledge(
    sources=["docs/"],
    chunking_strategy="sentence",
    sentences_per_chunk=5
)

Best Practices

Technical docs: 500–800 tokens with 50–100 overlap (semantic). FAQs: 200–400 with 20–50 overlap (fixed).
Use 800–1200 token chunks with 100–200 overlap and semantic splitting for narrative content.
Keep code chunks around 300–500 tokens with ~50 overlap; prefer fixed splitting for source files.

Knowledge Base

Build a knowledge base

Knowledge Module

Full API reference