The Chunking Dilemma: Too Small or Too Large?
When you build a RAG (retrieval-augmented generation, see RAG overview) system, you need to split your documents into pieces, called chunks, to index and retrieve them. This splitting choice is one of the most consequential in the whole chain, and paradoxically one of the most often rushed.
Chunks too small: each piece lacks context. An isolated sentence like "The result is 42%" means nothing without knowing what result we're talking about. Retrieval brings back incomprehensible fragments.
Chunks too large: each piece covers so many different topics that the single vector summarising it resembles no particular question. Retrieval brings back big blocks where only two sentences are useful.
This is the Goldilocks problem: neither too hot nor too cold.
The Tradeoff, Explained by Its Consequences
Rather than memorising a recommended size, understand what you lose on each side. The mechanism follows from one fact: a chunk is reduced to a single vector whatever its length, a fixed-length list of numbers, the same for three lines as for three pages.
What a too-short chunk costs you. The vector is sharp, so retrieval finds it reliably. But the retrieved passage isn't enough to answer with. That lands you in the worst case for diagnosis: retrieval "succeeded" (the right piece came back) and generation still failed, for lack of material. A second, less visible effect: the shorter the chunks, the more of them are needed to cover the same answer, so the more you have to retrieve, and the K available slots run out fast.
What a too-long chunk costs you. That single vector now has to stand for several topics at once. Since it is roughly an average of what the piece contains, it ends up halfway between everything and close to nothing: the chunk that actually holds the answer can be ranked behind a more homogeneous chunk only loosely related to the question. Two direct costs follow: the prompt sent to the model grows (so price and response time grow with it), and the useful passage sits buried in off-topic text.
What overlap costs you (the slice of text repeated between two consecutive chunks). Without it, an idea straddling a cut is lost on both sides: neither piece contains it in full, so neither will score well for the question aimed at it. With it, that idea survives whole in at least one piece. But you pay: the indexed corpus grows accordingly (20% overlap means 20% more vectors and storage), and above all the results start looking alike, two neighbouring chunks sharing half their text take up two of the K slots for near-identical content.
The perfect chunk would contain exactly one complete idea, no noise, with enough context to stand on its own. In practice that is unreachable systematically, because real documents aren't made of constant-length ideas. Any figure for size or overlap is therefore a starting point to be measured, never an answer, the end of this page explains how.
Splitting Strategies

1. Fixed Size (naive)
Split every N tokens (the units a model chops text into, see Tokenization) with overlap between consecutive chunks.
from langchain.text_splitter import CharacterTextSplitter
splitter = CharacterTextSplitter(
chunk_size=500,
chunk_overlap=100,
)
chunks = splitter.split_text(doc)
Strength: simple, predictable, fast. You know exactly how many chunks you'll have. Weakness: cuts arbitrarily in the middle of sentences and paragraphs. A table can end up split into two incomprehensible pieces.
2. Recursive (the recommended default)
Tries to split on large separators first (paragraphs \n\n), then progressively descends to finer separators (line breaks \n, sentences ., words ). The result: chunks that respect the natural structure of the text as much as possible.
from langchain.text_splitter import RecursiveCharacterTextSplitter
splitter = RecursiveCharacterTextSplitter(
chunk_size=512,
chunk_overlap=50,
)
Strength: respects text structure, produces few "orphan chunks" (incomplete fragments). Weakness: variable size depending on document structure. Some chunks will be near the limit, others much shorter.
RecursiveCharacterTextSplitter is the default splitter in the LangChain library, and it is a reasonable starting point: it needs no tuning and avoids the crudest failure of fixed-size splitting, cutting mid-sentence. If results aren't satisfactory, then refine with a more specific strategy.
3. Semantic
Computes the embedding of each sentence, then spots topic breaks by measuring cosine similarity between consecutive sentences, the angle between their two vectors, defined in norms and distances. When that similarity drops sharply, a topic change is assumed: that's where you cut.
Note what is actually being measured: not a "meaning" the machine has grasped, but a gap between two lists of numbers. The method works to the extent that the embedding model has learned to place same-topic sentences near each other, and it fails exactly where that model fails.
Strength: produces chunks with homogeneous content, so their single vector is representative of them. Weakness: slow (you need to compute the embedding of each sentence individually), unpredictable chunk sizes, and quality depends entirely on the embedding model used for detection.
Recommended for: scientific documents, structured reports. For general text or an FAQ, it's usually disproportionate.
4. By Document Structure
Leverage the structure already present in the document: Markdown headers, HTML sections, PDF chapters.
# Simplified example: split on Markdown H2s
chunks = text.split("## ")
Strength: respects the author's intent. If a document has sections, it's because the author judged each section forms a coherent unit. Weakness: requires format-specific parsing (Markdown, PDF, HTML, source code). And not all documents are well-structured.
Ideal for: technical documentation, manuals, source code. Unsuitable for unstructured text (emails, transcriptions).
5. Parent-Child (advanced)
Store two levels of chunks with different roles:
- Children (small): these are what get indexed in the vector database and compared against the question. Their small size keeps their vector sharp, so the ranking is reliable.
- Parents (large): it is the parent of the best-scoring child that gets sent to the LLM (large language model). Its size gives the model enough context to answer.
This is the most direct way out of the tradeoff described above: the dilemma only existed because one and the same piece served both purposes. Separate them and you search narrow, read wide.

Starting Points by Use Case
These are not measured optima: they are starting points, and the right-hand column says why this starting point rather than another. Figures are in tokens.
| Use Case | Starting size | Overlap | The reason |
|---|---|---|---|
| Factual question answering | 256-512 | ~50 | The answer fits in a sentence or two: a short piece already contains it and yields a sharp vector |
| Summary, analysis | 512-1024 | ~100 | You aren't after a fact but a line of argument, which loses its sense when cut |
| Code | Per function | 0 | The function is the unit that stands on its own; overlap would duplicate names and blur retrieval |
| Legal | Per article or clause | ~50 | That is the unit the reader cites, and the one they want back verbatim |
You will read everywhere that "256-512 tokens is the right size". The range circulates widely and is well justified by the reasoning above, but it does not come from any universal measurement: it depends on the corpus, the kind of questions asked, and the embedding model chosen. Treat it as a starting hypothesis to check against your data, not as an established result.
Chunk Enrichment
Metadata
Each chunk should receive filterable metadata: source, page, date, author, section. This enables filtering before the vector search.
{
"text": "chunk content...",
"metadata": {
"source": "report-2024.pdf",
"page": 15,
"section": "Financial Results",
"date": "2024-03-15"
}
}
Example: "retrieve from 2024 reports only" becomes a simple filter on the date metadata, followed by a vector search on the filtered subset.
Contextual Retrieval (Anthropic)
Add to each chunk a short situating sentence, written by an LLM, saying where in the original document this piece came from:
Context: This chunk comes from Chapter 3 of the 2024 annual report, Q3 financial results section.
[Original chunk content]
It is the situating sentence plus chunk pair, not the raw chunk, that then gets turned into a vector. So the vector also carries where the piece came from, which fixes a classic failure: a chunk saying "sales grew 12%" without naming the company or the year is nearly impossible to retrieve from a question that does name them.
Anthropic measures this gain on its own test set, against a precise criterion: the top-20 retrieval failure rate, meaning the share of questions for which none of the 20 retrieved chunks contains the answer. That rate goes from 5.7% to 3.7% with contextualised embeddings alone (a 35% relative drop), to 2.9% when a contextualised lexical index is added (49% drop), and to 1.9% with reranking on top (67% drop). The situating sentence itself runs 50 to 100 tokens.
Two reading precautions. First, these drops are relative: "49% better" does not mean half the questions are saved, it means 2.8 percentage points of failure out of 5.7 disappear. Second, the figure comes from the vendor of the technique, measured on its own corpora, an order of magnitude, not a transferable guarantee.
The price is that every chunk in the corpus goes through an LLM at indexing time, once each. On a large corpus that is the dominant setup cost.

Hypothetical Questions
Generate the questions the chunk could answer and store them alongside it. At retrieval time you compare the user's question not to the chunk's raw text but to those hypothetical questions. The appeal is easy to see: you are then comparing objects of the same kind. A question and an answer, even on the same subject, are not phrased alike, comparing question to question closes that gap.
Common Pitfalls to Avoid
- Ignoring structure: splitting a table or code block in the middle makes it incomprehensible
- Zero overlap: ideas that span two chunks are simply lost
- One size for everything: applying the same chunking to code, narrative text, and tables is a recipe for failure
- No cleaning: chunks polluted by repeated headers, page footers, pagination
- Very long chunks: the longer the context supplied, the less reliably the model exploits what is in it, particularly in the middle (see Long context vs RAG)
How to Evaluate Your Strategy
There is no shortcut: the only way to settle this is to measure on your own data.
Build a small evaluation set, say 50 to 100 questions, each paired with the passage or passages that genuinely answer it. Then vary one thing at a time (size, overlap, strategy) and measure recall: out of the passages that should have been found, what proportion actually shows up in the top 5 results, then the top 10? That is what recall@5 and recall@10 denote. Recall is defined in Evaluation metrics, and its transposition to search in RAG evaluation.
The important point is that this measurement does not involve the LLM. That is what lets you pin a bad result on the chunking rather than on the writing, the distinction set out in RAG overview.
One last warning: with 50 questions, a two- or three-point recall gap between two configurations is not a result, it is sampling noise. Only conclude from clear gaps.
1. Why does an overly long chunk hurt the retrieval ranking, even though it really does contain the answer?
2. With very short chunks, the right piece ranks at the top yet the final answer is wrong. Why is this the worst diagnostic case?
3. How does parent-child chunking escape the too-small versus too-big dilemma?
4. You read everywhere that 256-512 tokens is the right chunk size. How does this page say you should treat that range?
5. Anthropic reports that contextual retrieval cuts retrieval failure by 49 percent. What does that figure actually mean?