Chunking strategies for retrieval
WHAT is chunking?
The RAG pipeline is: document → chunk → embed → store in vector DB → (query) embed → nearest-neighbour search → top-k chunks → LLM. Chunking sits at the very front — every downstream quality ceiling is set here.
WHY the number-of-tokens matters (a mini derivation)
Suppose a document has tokens and we split into chunks of size tokens. Number of chunks:
Why ceiling? the last chunk may be partial but still needs its own vector.
Each chunk is embedded to one vector. So the index size grows as : smaller chunks ⇒ more vectors ⇒ more storage and slower search, but finer resolution.
Now the probability a needed fact survives in a single retrievable chunk. If the answer spans tokens and we place chunk boundaries without overlap, the answer is split whenever a boundary lands inside it. The fraction of "boundary positions" that break a length- span:
Effective stride (new tokens per chunk) is , so the chunk count becomes:
Why this form? the first chunk consumes tokens; each later chunk advances by the stride . Solving gives the formula.

HOW: the main strategies (in 80/20 order)
1. Fixed-size (token/char) chunking
Split every tokens with overlap . Simple, fast, predictable index size.
- When: uniform prose, logs, transcripts.
- Weakness: cuts mid-sentence → semantic blur.
2. Recursive / structure-aware chunking
Try to split on the biggest natural separator first (\n\n paragraphs), then sentences, then words, only falling back to hard cuts when a piece exceeds .
- Why better: boundaries align with meaning, so each chunk is a coherent idea.
- When: articles, docs, markdown.
3. Semantic chunking
Embed each sentence; start a new chunk when the cosine distance between consecutive sentences exceeds a threshold (a topic shift).
- Why: boundaries follow meaning, not token counts.
- Cost: many extra embedding calls.
4. Document-structure chunking
Use headings/sections/tables/code-blocks as units (one chunk per section). Attach the heading path as metadata.
- When: technical docs, legal contracts, wikis.
5. Small-to-big / parent-document retrieval
Index small chunks (precise matching) but return the larger parent for context.
- Why: decouples the retrieval unit from the generation unit — best of both.
Worked examples
Common mistakes (steel-manned)
Recall Feynman: explain to a 12-year-old
Imagine a huge library book with one amazing fact hidden inside. Instead of handing your friend the whole book, you tear it into index cards — each card holds one clear idea. Now when your friend asks a question, you can find the one right card fast. If the cards are too big they hold too many ideas and are confusing; too small and each card doesn't make sense on its own. And you let neighbouring cards share a sentence so a fact split across two cards is never lost. That's chunking.
Active-recall flashcards
What is chunking in a RAG pipeline?
Why does a chunk that is too large hurt retrieval?
Why does a chunk that is too small hurt retrieval?
Formula for number of chunks with overlap o and size c over N tokens?
Minimum overlap to keep a span of s tokens intact across a boundary?
What is the effective stride between chunk starts?
Name the FRS-DP strategies.
How does semantic chunking decide boundaries?
What is small-to-big / parent-document retrieval?
Why chunk on tokens not characters?
Connections
- Retrieval-Augmented Generation (RAG)
- Text Embeddings and Cosine Similarity
- Vector Databases and ANN Search
- Context Window Limits of LLMs
- Tokenization
- Metadata Filtering in Retrieval
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Dekho, RAG mein sabse pehla aur sabse important step hai chunking — document ko chhote tukdon mein todna. Socho tumhare paas ek 50-page PDF hai. Agar tum poora document ek hi vector mein embed kar doge, to woh vector saari ideas ka average ban jaata hai — kisi bhi query se sharp match nahi karega. Aur agar tum ek-ek word ka chunk banaoge, to context hi khatam — "1876 mein invent hua" par kya invent hua, pata hi nahi chalega. Isliye chunk ka size ek tradeoff hai: ek chunk mein ek clear idea hona chahiye, roughly 200-500 tokens.
Ab overlap ka jugaad samjho. Bina overlap ke, agar koi important sentence do chunks ke beech ki boundary par aa gaya, to woh do tukdon mein tut jaayega aur retrieval usko pura kabhi nahi laayega. Formula simple hai: agar answer span tokens ka hai, to overlap rakho — tabhi guarantee hai ki woh span kisi ek chunk mein pura milega. Practically 10-20% overlap rakhna safe hai.
Strategies yaad rakhne ke liye mnemonic hai FRS-DP: Fixed-size (simple, tez), Recursive (paragraph/sentence pe todo — meaning preserve hoti hai), Semantic (topic change pe naya chunk), Document-structure (heading/section wise), aur Parent-document ya small-to-big (chhota chunk se match karo, bada parent return karo context ke liye). 80/20 rule: bas fixed-size-with-overlap aur recursive achhe se seekh lo — 80% cases yahi solve kar dete hain. Ek cheez kabhi mat bhoolna — chunk tokens par karo, characters par nahi, kyunki model tokens hi ginta hai.