deep · 6 min
Chunking
Cutting documents into pieces before you embed them, which decides what retrieval can find.
updated 27 Sept 2026
We have a 40-page quarterly filing from a made-up company, Pellow Foods, and someone asks: "What was Pellow Foods' revenue growth in Q3 2025?" The answer is one sentence on page 12.
Semantic search finds text by turning each stored piece into one vector and returning the pieces closest to the question. So what counts as a "piece"? The obvious first try is the whole filing, one vector per document. Let's see why that goes badly.
First, even if we find the right filing, we hand the model 40 pages to get one sentence. That fills the context window, costs tokens on every call, and can distract the model. Second, one vector has to stand for everything in those 40 pages at once. Our one sentence about revenue gets watered down by all the rest, so the filing doesn't look much like our question.
So we cut the document into smaller pieces, called chunks, and embed each one. The chunk becomes the thing search returns and the model reads. That makes where we cut a real decision. And a bad cut never throws an error. It just makes the answers a bit worse, quietly.
Ways to cut
The plainest way is fixed size: count tokens and cut every 400, say. (Sizes are in tokens, so they depend on the model's tokenizer; the same text is a different count under another one.) It ignores meaning entirely. A cut can land mid-sentence, or between "revenue rose" and "4%".
Recursive splitting is the next step up. We set a maximum size and try
the most natural break first: blank lines between paragraphs. Any piece
still too big gets split on line breaks, then on spaces.
So chunks end on the biggest break that fits. It still knows nothing about
meaning, only where the text has seams. This is what LangChain's
RecursiveCharacterTextSplitter does.
Structure-aware splitting uses the document's own layout: one chunk per PDF page, or one per section under a heading. The author picked those borders, which is nice. The catch is size, since a section can be two lines or ten pages. Tables are a good case for this: pull them out whole so nobody retrieves half a table.
Semantic chunking tries to cut where the topic changes. Embed small windows of text in order, and cut where neighbouring windows suddenly look different. A popular version cuts at jumps bigger than 95% of all the jumps in the document. Some variants just ask an LLM where to cut. Either way we pay extra: everything gets embedded twice, or an LLM reads the whole corpus.
Any of these can add overlap: each chunk repeats the end of the one before. If a key sentence sits on a border, one chunk still has it whole. The cost is duplicate text, more to store, and search can return the same sentence twice. OpenAI's file search, for instance, cuts files into 800-token chunks with 400 tokens of overlap by default.
So how big?
This is where everyone wants a number, and the honest answer is that the measurements disagree.
One set of tests looked only at retrieval. For each question it pulled the top 5 chunks and asked two things: how much of the answer text came back (recall), and how much of what came back was answer at all. Recall barely moved, staying between about 84% and 92% for every method. What moved was the junk riding along with the answer:
Small recursive chunks of 200 tokens with no overlap did well on every measure without topping any of them. The 800/400 setting (yes, the same as OpenAI's default) came out worst on almost everything.
Another set of tests looked at final answers, on PDFs, mostly financial reports, with an LLM grading them. There, whole pages scored best on average and varied least. Fixed sizes from 128 to 2,048 tokens all landed close behind, but the extremes lost: 128 was too little, 2,048 too much. The best size also moved with the question. Short factual questions liked 256 to 512 tokens, and questions that needed analysis liked 1,024 or a full page. Even three sets of financial documents each picked a different winner.
Why the gap? Partly they measured different things: tokens retrieved versus final answers, top 5 chunks versus top 10, plain text versus PDFs. Neither transfers to your data for free.
Overlap is the same story. It adds duplicates, which hurts efficiency. But with a small embedding model, overlap helped recall: 250-token chunks got 82% with overlap and 77% without.
And "semantic chunking" isn't one thing. One study found the extra compute wasn't justified by consistent gains over plain fixed-size chunks. In the retrieval tests above, one semantic method came near the bottom and another at the top. So test the specific method, not the label.
The chunk forgets where it came from
Say our recursive splitter does a nice job and page 12 gives us this chunk:
Revenue rose 4% on the quarter before.
Which company? Which quarter? Nothing in the chunk says. Our question is all about "Pellow Foods" and "Q3 2025", so this chunk has little to match against, even though it's the answer.
One fix is to put the context back before embedding. For each chunk, give an LLM the whole document plus the chunk and ask for a short note, usually 50 to 100 tokens, saying where the chunk sits. Glue the note on the front and embed that:
From Pellow Foods' Q3 2025 quarterly filing, in the section on sales; Q2 2025 revenue was $52 million. Revenue rose 4% on the quarter before.
Anthropic calls this contextual retrieval. In their tests it cut the times the right chunk was missing from the top 20 by 35%, and by 67% once they added keyword search and reranking on top. With prompt caching, so the document is loaded once instead of once per chunk, writing the notes cost about a dollar per million document tokens. Sticking a generic summary of the document on every chunk helped much less, so the note has to be about that chunk.
There's a cheaper move in the same direction: keep the document title and section heading with each chunk. Nobody we read measured how much of the gain that gets back.
Before you pick
A recursive splitter at a few hundred tokens with little or no overlap is a reasonable place to start. If the documents have clear headings or pages, split on those first and use the size limit only for long sections.
Whatever you pick, store a stable location with every chunk. A page number stays the same however you chunk; a fixed-size chunk's position changes the moment you change the size. That matters as soon as you want to show where an answer came from.
Then compare two or three settings on a small test set of your own questions (that's retrieval evaluation). Budget the time, too: a plain splitter is nearly instant, and the LLM chunker in those tests took tens of minutes, paid again every time documents change.
Back at page 12, though, we still don't know the right size for Pellow Foods. Both sets of tests say the same thing in the end: it depends on your documents and your questions, and the only way to know is to measure. What we do with the chunks we find is RAG.
Further reading
- Evaluating Chunking Strategies for Retrieval, Smith and Troynikov (Chroma), 2024. The retrieval-only tests and the answer-share numbers. Look at the results table before you copy anyone's default.
- Finding the Best Chunking Strategy for Accurate AI Responses, Steve Han (NVIDIA), 2025. The final-answer tests on PDFs, where whole pages won. Good if your documents are reports.
- Contextual Retrieval, Anthropic, 2024. Where the "chunk forgets where it came from" fix comes from, with the costs worked out.
- Is Semantic Chunking Worth the Computational Cost?, Qu, Tu and Bao, 2024. Read it before you pay for a fancy splitter.
- Retrieval, OpenAI docs. The file search defaults and limits, if you're using it.