Chunking documents
Models and indexes work on small pieces. How you cut documents into chunks decides whether retrieval finds the right answer.
Words on this page (8)
- chunk
- : A small piece of a document, sized for indexing and retrieval.
- retrieval
- : Finding the most relevant pieces of text for a query.
- embedding
- : A list of numbers that represents the meaning of a piece of text or an image, so similar things sit close together.
- prompt
- : The input text you give a model, including instructions, examples and data.
- token
- : A piece of text the model reads and writes, usually a word or part of a word. About 4 characters of English on average.
- eval
- : A repeatable test of AI output quality, run before and after every change.
- metadata
- : Extra labels stored with a document or chunk, such as its title, date or country, which let you filter results.
- recall
- : Of the truly positive cases, the share the system found.
Why chunk
An of a whole book blurs everything into one point. A that covers one idea matches a question about that idea. Chunks must also fit in the next to others, so they cannot be huge. Too small, and a chunk loses the context needed to make sense of it, such as which product or date it refers to.
Common strategies
Fixed size: every 500 with a 50-token overlap so ideas cut at a boundary appear in two chunks. Structural: split on headings, paragraphs or code functions so chunks follow the author's own units. Semantic: split where the topic changes, detected by embedding sentences and cutting at large jumps. Hierarchical: index small chunks for matching but return the larger parent section for reading. Contextual: prepend a one-sentence note to each chunk saying where it came from.
Practical tips
Start with structural splitting at 200 to 500 tokens and tune on your . Keep with every chunk: source, title, section, date and permissions. Inspect actual chunks, since bad splits are easy to see and common.
A worked example: overlap
Text: "... demand rose. Prices increased by 4 percent because supply was limited. The central bank ..." Chunk 1 ends after "Prices increased by" and chunk 2 starts at "4 percent because". Neither holds the whole fact. With a 50-token overlap, chunk 2 starts a few sentences earlier and contains it whole.
How a fixed-size splitter works
Take a document of 1,000 tokens, a chunk size of 400 and an overlap of 50. Each chunk starts 350 tokens after the previous one (400 minus 50). The chunks are:
- Tokens 1 to 400.
- Tokens 351 to 750.
- Tokens 701 to 1,000, which is shorter because the document ends.
The overlap means the index stores about 14 percent more text than the document holds (400 divided by 350). That is the price of keeping boundary sentences whole.
Trade-offs in size
Bigger chunks keep more context but match less precisely, and each one uses more of the prompt. Five chunks of 500 tokens put 2,500 tokens in the prompt. Five chunks of 200 tokens put 1,000. Smaller chunks are cheaper to send and sharper to match, but they lose the surrounding facts. Hierarchical chunking tries to get both.
A second example: when not to chunk much
A help center has 300 FAQ entries, each 80 tokens, one question and one answer. Each entry is already one idea, so splitting further would only cut answers in half. A 2-page memo fits in a prompt whole, so it needs no at all. Chunking earns its place on long documents with many topics.
What goes wrong
Symptoms you can see by reading real chunks:
- A chunk that starts mid-sentence, so the split ignored the text's structure.
- A chunk that says "it" or "the product" with no hint of which one.
- A table row separated from its column headers.
- A chunk that mixes two topics, so it matches both questions badly.
To confirm, print ten random chunks and read them as if you were the model. If a chunk makes no sense alone, it will not retrieve well either.
Try it yourself
Take one long document and 15 questions with known answers. Split it at 200 tokens and again at 600. For each question, check whether the right text appears in the top five chunks. Expect the small size to win on precise facts and the large size to win on questions needing context. Pick by your numbers.
Common mistake
Choosing the size by guesswork and never measuring. Try two sizes and compare on your test questions.
A student uses a search tool on a 300-page textbook and asks "what causes inflation?" If the whole book is one embedding, the search is useless. If every sentence is its own embedding, results are fragments like "This is why prices rose." The right size, a paragraph or section, returns a complete idea.
Check yourself
Why use overlap between chunks?
Not quite. Overlap protects against a split landing in the middle of an important sentence.
What is wrong with chunks that are too small?
Not quite. A fragment may not say which product or date it describes.
Your answers are wrong and you see a key fact split between two chunks. What is the quick fix to try?
Not quite. Better chunk boundaries keep facts together. Then measure recall.
You got 0 of 3 right.
Go deeper
- Article
Pinecone · Fixed, structural and semantic approaches compared.
- Article
Anthropic · Prepending chunk context, with measured retrieval gains.
- Repo
Nir Diamant · Notebooks for chunking and many other methods.
- ToolChunkVizTool
Greg Kamradt · Visualize how different splitters cut the same text.
Spotted a mistake or something unclear? Report it on GitHub.