RAGcore
Chunking
Splitting documents into retrievable pieces — big enough to make sense alone, small enough to be precise.
What it is and why it exists
Strategies: fixed-size token windows with overlap (simple, breaks sentences and tables), recursive splitting on paragraphs then sentences, structure-aware splitting on headings (keeps sections and tables together), semantic splitting where embedding similarity drops, and parent-child (retrieve small, return the bigger parent).
Quick prototype
Fixed 512-token chunks with 50 tokens of overlap.
In production, at scale
Structure-aware chunking with a size cap, section titles prepended to each chunk, tables kept whole, chunk size tuned on your eval set (recall@k vs answer quality), and chunk IDs stable across re-indexing so incremental updates work.
Vendors and tools
| LangChain text splitters | Recursive, Markdown/HTML header, token splitters |
|---|---|
| LlamaIndex node parsers | Sentence, semantic, hierarchical |
| Chonkie | Chunking library with many strategies |
On AWS: Bedrock Knowledge Bases: fixed-size, hierarchical, semantic or no chunking, or a custom Lambda transformation.
How it fails
- Answer split across two chunks, neither retrieved alone
- Chunks without their heading — “it costs $40” but what does?
- Overlap so large that results are near-duplicates
What the interviewer asks next
How do you choose chunk size?
Empirically: build a labelled query set, try a few sizes and strategies, compare recall@k and end-answer quality. Smaller chunks are more precise but lose context; larger ones dilute the embedding.
Why prepend the section title to each chunk?
So the chunk carries its own context — embeddings and BM25 both match “Refund policy > Damaged items” even when the body never says “refund”.