Late Chunking
Embed first, then split for better chunk embeddings
Late chunking embeds the entire document first, then splits. This produces chunks with better individual embeddings.
Quick Start
from praisonaiagents import Agent
agent = Agent(
instructions="Answer questions with high precision.",
knowledge={
"sources": ["technical_docs/"],
"chunker": {
"type": "late",
"chunk_size": 512,
"embedding_model": "all-MiniLM-L6-v2"
}
}
)
response = agent.start("Explain the architecture")from praisonaiagents.knowledge.chunking import Chunking
chunker = Chunking(
chunker_type="late",
chunk_size=512,
embedding_model="all-MiniLM-L6-v2"
)
chunks = chunker.chunk("Your document content...")When to Use
- High-precision retrieval needed
- Quality matters more than speed
- Complex technical documents
- Semantic similarity search critical
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
chunk_size | int | 512 | Max tokens per chunk |
embedding_model | str | auto | Embedding model |
How It Works
Traditional chunking: Split → Embed each chunk Late chunking: Embed full doc → Split with context awareness
This preserves document-level context in each chunk’s embedding.