Most RAG failures are not model failures. They start earlier, when you split source documents into pieces that lose the sentence the answer needed, or glue unrelated sections into one oversized block. RAG chunking strategies decide what the retriever can find and what the generator is allowed to see.
Chunking is the contract between your corpus and your embedding index. If that contract is wrong, hybrid search, rerankers, and fancy prompts only rearrange the same bad evidence. This guide walks through practical chunk designs, failure modes, and a scorecard you can use before you scale ingestion.
What chunking actually controls
A chunk is the unit you embed, store, and retrieve. Size, overlap, and boundary rules change three outcomes at once: recall (did the right passage enter the candidate set?), precision (did noise crowd it out?), and generation quality (did the model get enough contiguous context to answer without inventing glue?).
Embeddings average meaning over the chunk. A 2,000-token dump that mixes pricing, legal disclaimers, and a product FAQ produces a muddy vector. Tiny 50-token shards preserve local meaning but break tables, procedures, and arguments that span paragraphs. The useful range for most prose knowledge bases sits between roughly 200 and 800 tokens, adjusted for your embedding model’s training distribution and your answer style.
If you are still leveling up on vectors themselves, start with our guide to what embeddings are in AI, then return here to pick boundaries that match how those vectors behave.
Fixed-size windows versus structure-aware splits
Fixed-size chunking (N tokens with optional overlap) is easy to ship and easy to debug. It works when documents are homogeneous prose: blog posts, release notes, internal wikis written as continuous paragraphs. Overlap of 10–20% helps when answers sit on boundaries, at the cost of duplicate storage and occasional near-duplicate retrieval.
Structure-aware splitting respects headings, code fences, list items, and page breaks. Markdown and HTML trees are ideal inputs: split on h2/h3, keep lists intact, and treat tables as single units when they fit the context budget. PDF pipelines need an extra layout step—column detection and header/footer stripping—before any semantic split, or you will embed page numbers and watermarks as “knowledge.”
Recursive character splitters (as in common LangChain utilities) try separators in order: double newline, single newline, sentence punctuation, then characters. That middle ground is a solid default for mixed corpora. Prefer official recipes from the LangChain text splitter docs when you want a battle-tested separator ladder rather than inventing one.
Semantic and late-chunking patterns
Semantic chunking groups consecutive sentences until embedding similarity between the running buffer and the next sentence drops below a threshold. It shines on narrative docs where topic shifts are gradual. It struggles on dense specs and on documents with abrupt but valid section changes (API reference pages). Always cap maximum size so a long “similar” stretch cannot blow your context window.
Late chunking and parent–child (or small-to-big) patterns separate retrieval grain from generation grain. Embed small children for precise matches; return the parent section or neighboring windows to the LLM. This is one of the cheapest upgrades when your naive fixed chunks answer with fragmented quotes. Pair it with a clear parent id in metadata so you can audit which parent won.
LlamaIndex documents a similar idea under node relationships and hierarchical indexes; their node parser guide is a useful reference when you implement parent–child in production rather than in a notebook toy.
Domain-specific boundaries that matter
Code: split by function or class when files are large; keep imports with the first chunk or attach them as metadata so the model does not invent missing symbols. Never split mid-string or mid-expression just to hit a token quota.
Policies and legal text: preserve clause numbering; prefer splitting on article/section headers over sentences. A single “shall” clause out of context is how compliance RAG hallucinates obligations.
Support tickets and chat logs: chunk by turn groups or by resolved issue, not by raw message count. Include the resolution in the same chunk as the problem statement when possible.
Tables and CSV-like content: serialize with headers repeated every N rows, or store row-level chunks with a table title prefix. Blind token cuts through CSV destroy meaning faster than any other format.
A practical scorecard before you scale
Run a 50–100 question gold set against three chunk configs. Score retrieval hit rate at k=5 and k=10, then faithfulness of the final answer with a judge or with RAGAS-style evaluation. Do not optimize chunk size on anecdote alone.
| Signal | Healthy range | If unhealthy |
|---|---|---|
| Median chunk tokens | 200–800 for prose | Retune splitter; check PDF noise |
| Empty / boilerplate rate | <5% | Strip headers, nav, cookie banners |
| Duplicate near-neighbors | Low cosine clusters | Reduce overlap; dedupe parents |
| Answer citations land in chunk | >80% on gold set | Smaller children + larger parents |
| p95 context tokens to LLM | Within budget with headroom | Tighten top-k or parent size |
Store chunk_id, source_uri, section_path, token_count, and content_hash in metadata. When freshness matters—product docs that change weekly—tie re-ingestion to hashes so you only re-embed changed parents. That pattern pairs well with practices in our note on agent knowledge freshness.
Failure modes you will see in production
- Boundary orphans: the answer sentence sits in chunk N+1 while the question matches chunk N. Fix with overlap or parent expansion.
- Kitchen-sink chunks: multiple topics in one vector. Fix with heading-aware splits.
- Boilerplate pollution: repeated disclaimers dominate similarity. Fix with boilerplate stripping before embed.
- Table shredding: columns split across chunks. Fix with table-aware serialization.
- Language mix: English headers with Korean bodies (or the reverse) without language tags. Fix with language metadata and, when needed, language-specific embedding routes.
When retrieval still feels “almost right,” move up the stack: hybrid search for RAG recovers lexical hits that pure dense search misses, and a reranker for RAG reorders noisy candidate lists. Chunking remains the foundation; those layers amplify good splits and amplify bad ones.
Rollout steps that avoid rework
Start with one document family (for example, product help center Markdown). Implement structure-aware splitting with a modest overlap. Index into your vector store—see our overview of vector databases for AI—and measure the gold set before touching other families. Only then generalize the splitter with per-family profiles in config, not hard-coded magic numbers in application code.
Version the chunker: chunker_version in metadata lets you A/B two strategies in the same collection or run side-by-side indexes. Never silently change chunking under a production index without a re-embed plan; mixed strategies in one collection create irreproducible evals.
Prompting still matters after retrieval. Keep the system instructions short and put evidence in a delimited block so the model can cite chunk ids. Our prompt engineering guide covers citation-friendly patterns that reduce “answer without evidence” behavior when chunks are correct but the model ignores them.
Finally, decide when RAG is the wrong lever. If the knowledge is stable style or format rather than facts that change, compare against fine-tuning and tool-using agents in RAG vs fine-tuning vs agents. Chunking excellence will not fix a problem that belongs in weights or tools.
FAQ
What is the best default chunk size for RAG?
For general prose with modern embedding models, start around 300–500 tokens with 10–15% overlap, then tune on a gold set. Domains with dense tables or code often need smaller retrieval chunks and larger parent windows for generation.
Should every document use the same RAG chunking strategies?
No. Help articles, API references, and PDFs behave differently. Use per-family profiles that share one embedding model when possible, but different separators, max sizes, and parent rules.
Does more overlap always improve recall?
Only up to a point. Excess overlap inflates duplicates, wastes context slots, and can confuse rerankers with near-identical passages. Measure duplicate rate and answer quality together.
How do I chunk PDFs without destroying layout?
Run layout-aware extraction first (columns, reading order, header/footer removal). Then split on detected headings. If extraction quality is poor, fix extraction before investing in semantic chunking.
When should I use parent–child chunking?
When small chunks retrieve well but answers need surrounding paragraphs, headings, or table headers. Embed children; return parents (or neighbors) to the LLM with clear provenance.
Can a better prompt fix bad chunks?
Prompts can reduce hallucination around missing evidence, but they cannot invent facts that never entered the context. Fix retrieval units first, then tighten prompts and evaluation gates.
AI Generated Apps AI Code Learning Technology

2 comments
Pingback: Citation Grounding for RAG: Make Answers Traceable
Pingback: GraphRAG Explained: Graphs vs Flat RAG