AI Applications
Chunking Strategies for RAG: What Actually Matters?
Five long documents, nine ways to split them plus a whole-document baseline, and one fair comparison: does the passage that answers the question reach the model, within the same token budget? Then: do better chunks give better answers?
On this page · 15 sections
The help center in the last three articles had short articles, so each one was a single piece of text. The pipeline from “Designing a Production-Ready RAG Pipeline (opens in a new tab)” embedded each article whole, and that worked.
Now the same assistant has to answer from the product’s real documentation: an administrator guide, an API reference, a billing guide, a data processing policy, and release notes. Each is thousands of words long, with tables, numbered steps, and sections that refer to each other. They have to be split before they’re embedded, and the advice you find is mostly a number: 512 tokens, 10% overlap, or “use semantic chunking”.
This article tests that advice instead of repeating it. Five long documents, nine ways to split them plus the option of not splitting at all, and one question for each: does the passage that answers the customer’s question reach the model? Then a second question that matters more: when it does, does the answer get better?
Try to Understand It This Way
You’re helping a colleague on a support call. They can’t read the whole manual during the call, so you photocopy a few pages and hand them over. Two things decide whether that helps.
The first is where you cut. Cut a table between its header and the row they need, and they get “Yes, Yes, No, No” with no column names. Copy a release note without its heading, and they know what changed, but not in which version. Copy step 4 of 8, and they can’t follow the procedure.
The second is how much they can hold. If you can hand over only four pages, a stack of whole chapters doesn’t fit, and small scraps leave room for the scrap that matters.
Chunking is deciding where to cut. Retrieval is choosing which pieces to hand over. And the token budget is how much the model can hold.
What a Chunk Has to Carry
A chunk is useful only if it contains the passage that answers the question, completely. What “completely” means depends on the question:
| Kind of question | What the retrieved chunks must contain |
|---|---|
| A fact in one sentence | the sentence |
| A table lookup | the row, and the header row that names its columns |
| “In which version…?” | the release note, and the version heading above it |
| A procedure | every step |
| A cross-reference (“see section 5.3”) | both places, in one chunk or in two |
Each required passage has to be whole inside one retrieved chunk. A question that needs two passages, such as a row and its header, can get them from two different chunks, but a passage cut in half doesn’t count, even if both halves are retrieved. A chunk that contains a matching phrase without the rest doesn’t count either. “Second retry: 3 days after the failed payment” is an answer. “| Second retry | 3 days |” without the header might be.
The Experiment
The demo, 04-chunking, uses five long documents written for the same fictional product as the help center: about 7,800 words, or 10,147 tokens in the answer model’s tokenizer. The documents are consistent with the help center from “RAG Explained: How AI Systems Work With Your Data (opens in a new tab)” and add many new ones. They’re fictional on purpose: the model has no reason to know these product-specific facts from its training data.
Sixty questions were written after the documents. Each records the exact passages that answer it, following the table above: 21 one-sentence facts, 13 release-note questions, 14 table lookups, 6 procedures or lists, and 6 questions that combine two places. The documents and questions were committed to the repository before any chunking code existed, so the questions couldn’t be tuned to one strategy.
Ten strategies, the first of which doesn’t split at all:
whole-document one chunk per document
fixed-128/256/512 windows of 128, 256, or 512 tokens, with and without overlap (a quarter of the window)
structure one chunk per Markdown section; a section over 512 tokens is split between
paragraphs, then between lines
structure-headings the same chunks, with the heading lines above each one copied in front of it
semantic split between sentences where the meaning shifts most, measured with embeddings
Every chunk is embedded with nomic-embed-text, and each question retrieves chunks by cosine similarity, as in Article #12. The scoring rule is the one the questions were written with: a question’s evidence is found if every passage it needs is whole inside one of the retrieved chunks.
The most important design choice is what “retrieved” means. A common comparison is “top k”: is the answer in the first three or five chunks? But three 512-token chunks hold four times as much text as three 128-token chunks, and more text contains more answers. So the main comparison is at an equal retrieved-context budget: 500, 1,000, or 2,000 tokens of retrieved text, in the answer model’s tokens. The retriever walks the ranked chunks, adds a chunk if it fits the remaining budget, and skips it if it doesn’t. The budget covers the retrieved chunks only; the instructions and the question come on top.
The questions were split into 31 development and 29 test questions. As with the relevance threshold in Article #14, settings are chosen on one set and results reported on the other: the development questions choose which strategies go on to the answer stage, and the test questions report the results.
Implementation note: the exact setup
Machine: Apple M4 Pro (24 GB), macOS 26.6.2
Runtime: Ollama 0.40.16, /api/embed and /api/chat
Embeddings: nomic-embed-text, ID 0a109f422b47, prefixes "search_query: " / "search_document: ",
truncate: false (an input that is too long is an error, not silently shortened)
Chat model: llama3.2:3b, ID a80c4f17acd5 (Q4_K_M), temperature 0, seed 1, at most 500 output
tokens, JSON schema in `format`
Tokens: Llama 3.2 tokens, counted by a small implementation of its tokenizer; checked
against Ollama's own prompt counts on 80 texts (14,809 tokens): no mismatches
Budget rule: retrieved chunk text only, in rank order; a chunk that doesn't fit the remaining
budget is skipped. Instructions, excerpt labels, and the question added
169 to 299 tokens (median 206) in the answer stage
Selection: the fixed-256 baseline, plus the two strategies with the most development
questions found at 1,000 tokens (ties: fewer indexed tokens); fixed before
the first run
Languages: Python 3.12.13 and Node.js 24.16.0, identical output: the same 570 chunks,
the same rankings, the same 87 replies
Runs: retrieval three times in Python and twice in JavaScript, the answer stage twice
in each language; identical every time, 2026-11-15
Grading: every reply read and labeled by hand; each label stored with a hash of the reply
Counting in the answer model’s tokens matters: the budget is about what the model reads, and the embedding model has a different tokenizer, which counts the same text differently.
Whole Documents: They Don’t Fit Twice
The simplest strategy is no splitting at all: one embedding per document. It fails in two separate ways.
First, the embedding model can’t read them. In this setup, nomic-embed-text accepts at most 2,048 tokens, and two of the five documents are longer. With truncate: false, those calls fail:
admin-guide.md: the input length exceeds the context length
api-reference.md: the input length exceeds the context length
Ollama’s default is the opposite. Its documentation describes truncate as “If true, truncate inputs that exceed the context window. If false, returns an error”, and the default is true. With the default, those two documents are embedded without any warning, but only their beginning: about the first 1,959 of the administrator guide’s 2,808 tokens. The cut falls in the middle of the SCIM setup steps, so the audit log, the security settings, and everything after them were never embedded. Nine of the sixty questions have their answer in a part the embedding never read. Their document can still rank first, but only because of what the beginning says.
Second, the model can’t hold them. At a budget of 1,000 tokens, no document fits, and whole-document retrieval finds nothing at all. At 2,000 tokens, only the three shortest fit.
So “send the whole document” isn’t a chunking strategy for long documents. It’s the absence of one, and with default settings it fails without an error.
Where You Cut: Evidence That Doesn’t Survive
Before asking what retrieval finds, ask what’s still there to find. The demo counts the questions whose required evidence survives chunking at all, meaning it would be found if every chunk were retrieved:
strategy chunks median tokens indexed tokens evidence intact
fixed-128 81 128 10,147 48/60
fixed-256 41 256 10,147 53/60
fixed-512 23 512 10,147 57/60
fixed-128-overlap-32 106 128 13,379 60/60
fixed-256-overlap-64 53 256 13,219 60/60
fixed-512-overlap-128 27 512 12,963 60/60
structure 98 83 10,147 60/60
structure-headings 98 90 10,913 60/60
semantic 38 275 10,132 60/60
The table leaves out the whole-document baseline, whose five chunks bring the total across all ten strategies to 570. Fixed windows without overlap destroyed the evidence of 12 questions at 128 tokens, 7 at 256, and 3 at 512. Here is one cut, at the end of a 256-token window in the administrator guide’s permissions table:
end of one chunk: | Change project settings | Yes | Yes | Only in projects they created | No |
| Restore a deleted project
start of the next: | Yes | Yes | No | No |
| View the audit log | Yes | Yes | No | No |
“Can a Member restore a deleted project?” now has no answer in any chunk: one has the question, the next has four columns of yes and no without it.
Overlap fixes this. With a quarter of each window repeated in the next, every passage survived in at least one chunk, at the cost of 28 to 32% more tokens to embed and store. Following the document’s structure also kept every passage intact, without the extra tokens, because its cuts fall between sections, paragraphs, and lines, never inside a table row.
How Much You Retrieve: Compare at Equal Budgets
Here is “top 3” next to the comparison at equal retrieved-context budgets. Development questions, 31:
top 3 chunks within 500 within 1,000 within 2,000
strategy found (tokens) tokens tokens tokens
fixed-128 20 (381) 21 23 24
fixed-128-overlap-32 22 (381) 22 28 30
fixed-256 25 (750) 18 25 26
fixed-256-overlap-64 26 (761) 18 26 30
fixed-512 26 (1,261) 2 20 29
fixed-512-overlap-128 25 (1,370) 5 16 29
structure 25 (340) 27 30 31
structure-headings 29 (373) 31 31 31
semantic 19 (951) 15 22 27
By “top 3”, fixed-512 looks as good as almost anything: 26 of 31. But it gets there with about 1,260 tokens of context, while structure finds 25 with 340. Within the same budget, the picture changes.
It also shows something no top-k table shows: chunk size and budget interact. With a 1,000-token budget, only one full 512-token chunk fits, because two would be 1,024. So fixed-512 finds 20 at 1,000 tokens and 29 at 2,000. With 500 tokens, nothing of that size fits at all, except the short last chunk of a document. Overlap helped the small windows at 1,000 tokens (23 to 28 questions for 128-token chunks) and hurt the large ones (20 to 16 for 512-token chunks).
The lesson isn’t “512 is too big”. It’s that a chunk size only means something together with the context it has to fit into. Pick the budget first, from what the model can use and what you can pay for, and then the chunk size.
Following the Structure
On these documents, splitting along the Markdown structure did best: every passage intact, 30 of 31 development questions found at 1,000 tokens, and 29 of 29 test questions. The documents are written in sections, and a section is usually exactly one topic, so a section is a natural chunk. Most are short: the median chunk was 83 tokens, so many of them fit into a budget.
Its one miss was a release note:
## Version 5.4 (2026-01-12)
### Changed
- Organization web addresses can now be changed once every 30 days, ...
### Removed
- SMS codes for two-factor authentication are no longer accepted. ...
“In which version were SMS codes removed?” The “Removed” section is its own chunk, and the version is two headings up. Copying the heading lines above each chunk in front of it (structure-headings) fixed that, and with it every development question was found, even at 500 tokens. Adding context to a chunk before embedding it is the same idea, in a cheap form, as Anthropic’s Contextual Retrieval, which starts from the observation that “traditional RAG solutions remove context when encoding information” and fixes it by “prepending chunk-specific explanatory context to each chunk before embedding.” Here the context is just the headings, copied, with no model call.
One caveat matters more than any number in this section. These documents are clean Markdown with many short sections, and I wrote them. Structure-aware splitting is only as good as the structure: a PDF converted to text, a wiki page without headings, or a contract whose sections run for pages would look different. The demo lets you add your own documents to find out.
Semantic Chunking: More Cost, Less Evidence
Semantic chunking splits where consecutive sentences change topic. Each sentence is embedded together with its neighbours, the distances between consecutive embeddings are compared, and the document is split at the largest jumps: in this implementation, above the 95th percentile of the distances within each document. Implementations differ in how they set that threshold. It sounds like the most principled option.
Here it was the most expensive and one of the weakest. Deciding where to split took 616 extra embeddings, one per sentence window: 46,470 embedding tokens in total, against 10,807 to 14,695 for the other chunked strategies. And at 1,000 tokens it found 22 of 31 development questions, fewer than most fixed windows.
Reading its chunks shows why. A distance between sentences doesn’t know about tables, so one split put a table’s header row in a chunk of its own:
| Error code | Meaning | What to do |
Another chunk was two tokens long (## Taxes), and the largest was 675. Chunks that size are hard to rank and hard to fit into a budget: for 17 questions, the evidence was intact in some chunk that retrieval didn’t place within 1,000 tokens.
This matches a published study that compared the two more systematically (Qu et al., 2025): “The results show that the computational costs associated with semantic chunking are not justified by consistent performance gains.” It’s one result on one set of documents here, but it’s worth running the comparison yourself before paying for semantic chunking.
Do Better Chunks Give Better Answers?
Finding the evidence is necessary, not sufficient. The rule fixed before the run sent three strategies to the answer stage: the fixed-256 baseline and the two best on the development questions, structure-headings and structure. All 29 test questions went through each strategy with a 1,000-token budget, and every reply was read:
evidence in answers (29)
strategy the context correct partly wrong declined
fixed-256 24 21 0 1 7
structure-headings 29 22 0 2 5
structure 29 22 1 3 3
Better chunking got the evidence into the context for all 29 questions instead of 24. It bought one more correct answer.
The baseline used what it found well: when the evidence was missing, it declined all five times instead of guessing. The structural strategies had the evidence every time, and llama3.2:3b still declined three to five questions and got two or three wrong. “Can a Member restore a deleted project?” was declined by all three, including the two with the right row and its header in the context. “Where is the live chat subprocessor located?” got “European Union and United States”: the location from the row above. And one reply with every step of the downgrade checklist ended mid-sentence, “The audit log is kept, but it stops”, exactly where its 256-token chunk ended.
So on these documents, chunking moved the bottleneck. Once the evidence reliably reached the model, what limited the answers was a 3-billion-parameter model reading tables and long excerpts. With 29 questions and one model, differences of one or two answers aren’t meaningful. The size of the gap between “evidence in the context” and “correct answer” is.
Under the hood: what "evidence found" does and doesn't measure
The check is strict and simple: every required passage must appear character for character, intact within at least one retrieved chunk. A question that needs two passages can be satisfied by two different retrieved chunks. That makes it reproducible and free of judgment, but it has edges.
- A passage split across two retrieved chunks doesn’t count, even if both chunks were retrieved and a reader could join them. That penalizes small fixed windows slightly.
- Where a fact appears in two places, either place counts; the questions list both.
- It says nothing about distractors: a context can contain the right row and three similar ones, which is what happened with the subprocessor question.
That’s why the answer stage exists. Retrieval metrics tell you whether the model could have answered. Only reading the answers tells you whether it did.
What Breaks
- Silent truncation. An embedding call with default settings embeds the beginning of a long text and drops the rest without an error.
- Cuts inside structure. Fixed windows split table rows from headers, steps from procedures, and notes from their headings.
- Top-k comparisons across chunk sizes. Bigger chunks win “top k” by holding more text, not by retrieving better.
- Chunk sizes that don’t fit the budget. A 512-token chunk in a 1,000-token budget leaves room for one.
- Orphaned sections. A chunk that’s correct on its own can lose the heading that says which version, plan, or product it’s about.
- Splitting by meaning without structure. Semantic splits can separate a table from its header and produce chunks from 2 to 675 tokens.
- Assuming retrieval is the bottleneck. With the evidence in the context, a small model still declined or misread it.
Engineering Decisions
1. Measure chunking by evidence, at the budget you’ll use
Write questions with the exact passages that answer them, and compare strategies at the same number of context tokens, in the answer model’s tokens. Top-k across chunk sizes compares different amounts of text.
2. Choose the budget before the chunk size
The budget comes from the model’s context and your cost per request. Then choose a chunk size that uses it well; a size that barely misses a multiple of the budget wastes most of it.
3. Turn off silent truncation
Set the embedding call to fail on input that’s too long (truncate: false in Ollama), and handle it in the chunker. A silently truncated embedding is a bug that never raises an error.
4. Split along the document’s structure when it has one
Sections, paragraphs, and lines are where authors put topic boundaries. Fall back to token windows with overlap only inside a section that is too long, or for text without structure.
5. Carry the headings with the chunk
Copying the heading path into each chunk is cheap and fixes the chunks that are only meaningful in their section: release notes, plan-specific settings, numbered policy sections.
6. Treat semantic chunking as an experiment, not a default
It costs an embedding per sentence to decide where to split, and here it didn’t pay for itself. Run it against the alternatives on your own documents before adopting it.
7. Read the answers, not only the retrieval metrics
Evidence in the context is the upper bound. The answer stage showed how far below it a small model can stay.
What to Take Away
- What actually matters is whether the answering passage reaches the model, whole, within the budget. Chunk size alone predicts little.
- Compare strategies at equal token budgets. Top-k rewards bigger chunks for holding more text.
- Cuts destroy evidence, and structure is the best guide to where not to cut. Overlap is the fallback when there’s no structure.
- Semantic chunking used 3.2 to 4.3 times as many embedding tokens and found less here.
- Better chunking can move the bottleneck to the model. Evidence in the context for 29 of 29 questions gave 22 correct answers, not 29.
Think About These Use Cases
-
A contract repository: Clauses refer to definitions and to other clauses by number. How would you chunk so that “the Term” in clause 14 is answerable?
-
API documentation with code samples: Should a code block ever be split? What would you do with a 3,000-token reference page for one endpoint?
-
Scanned PDFs without headings: Structure-aware chunking has nothing to follow. What would you use instead, and how would you measure it?
-
A changelog with 500 entries: Most questions are “when did X change?”. How would you make sure the version and date travel with every entry?
-
A small budget on a phone: The model can take 800 tokens of context. Which chunk sizes make sense, and why?
If you want to work through one of these, take it to GPT along with this article. Ask GPT ↗️
Related Sources
- 04-chunking: The companion demo: the documents, the questions with their evidence, ten strategies, the token-budget evaluation, and the hand-graded answers (Python and JavaScript).
- Evaluating Chunking Strategies for Retrieval (Smith and Troynikov, Chroma, 2024): Evaluates chunking “at the token level”, and finds that “default settings for certain popular chunking strategies can lead to relatively poor performance.”
- Is Semantic Chunking Worth the Computational Cost? (Qu, Tu, and Bao, Findings of NAACL 2025): Semantic chunking against simpler fixed-size chunking on document retrieval, evidence retrieval, and retrieval-based answer generation.
- Introducing Contextual Retrieval (Anthropic, 2024): Why chunks lose context, and adding context to each chunk before embedding it.
- Ollama: Generate embeddings: The
/api/embedendpoint, including thetruncateparameter and its default. - nomic-embed-text-v1.5 (Nomic AI): The embedding model family, and its
search_query:/search_document:prefixes.
What’s Next?
Every strategy here retrieved by one signal: cosine similarity between embeddings. That signal is good at meaning and bad at exact strings: an error code like SSO-103, a header name like X-RateLimit-Reset, or a version number.
In the next article, we’ll look at Retrieval Strategies: Vector Search, Keyword Search, and Hybrid Search: what each one finds that the other misses, and how to combine them.