Skip to main content

Chunking Strategies

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

Content TypeChunk SizeOverlapStrategy
Technical docs500-80050-100Semantic
FAQs200-40020-50Fixed
Long articles800-1200100-200Semantic
Code300-50050Fixed