Recursive Chunking
What You'll Learn
You'll learn how to split documents hierarchically using multiple separators in priority order to preserve natural text structure better than flat chunking methods.
The Core Idea
Recursive chunking applies a hierarchy of text separators in order of structural importance. Instead of splitting text with just one separator (like newlines or sentences), you try the most significant separator first (e.g., double newlines for paragraphs). If resulting chunks are still too large, you recursively apply the next separator in your priority list (single newlines, then sentences, then words).
Think of it like breaking a chocolate bar: first snap along the major grooves (paragraphs), then along minor grooves (sentences), and only break individual pieces (words) if absolutely necessary.
How It Works
- Define a separator hierarchy:
["\n\n", "\n", ". ", " "] - Try the first separator: Split by double newlines
- Check chunk sizes: If any chunk exceeds your target size, recursively split that chunk using the next separator
- Repeat until all chunks fit your size constraints
This preserves semantic boundaries naturally present in the document structure rather than arbitrarily cutting mid-sentence or mid-paragraph.
Why It Matters for RAG
In retrieval-augmented generation, chunks that respect document structure (keeping complete thoughts together) retrieve more coherent context. A chunk containing a full paragraph is more semantically meaningful than one that cuts halfway through a sentence.
Recursive chunking automatically adapts to your document's natural breaks while staying within size limits—combining the structural awareness of paragraph-based chunking with the flexibility needed for varied text lengths.
Key Takeaway: Recursive chunking hierarchically splits text using multiple separators in priority order, preserving natural document structure while maintaining size constraints—crucial for high-quality RAG retrieval.