RAG Chunking Explained: Fixed vs Recursive Splitting and Retrieval Quality | Ameya
Liam, in for Ameya Deshmukh, takes apart a 12-line chunker. The video covers step size, overlap, recursive splitting, the real distribution of chunk sizes, and a read-one-chunk-alone test for broken context.
Chunking is about twelve lines of code that most people write once and never think about again. It also moves retrieval quality more than almost anything else in a RAG pipeline. In this video, Liam, in for Ameya Deshmukh, builds the chunker with Claude and then takes it apart.
The sliding window and the step size
When you slide a window across text, the step is not the chunk size. It is the chunk size minus the overlap. That single subtraction is what makes chunks overlap instead of sitting edge to edge. Get it wrong and the chunks either leave gaps or duplicate each other.
The actual twelve lines are a list comprehension, and the part to read is the range step, which is chunk size minus overlap exactly as described. One guard stops the overlap from swallowing the chunk. That is the entire naive chunker.
Why overlap exists
A fact that lands exactly on a boundary can get cut in half. Overlap is a small insurance policy: repeat a little text at each seam so no sentence is orphaned across the cut, and either neighboring chunk can then answer the question.
Fixed versus recursive splitting
The naive splitter is blind. It cuts at exactly 400 characters whether that is the end of a sentence or the middle of a word. The production fix is recursive splitting, which tries to break on paragraphs first, then lines, then sentences, then words, and only as a last resort raw characters. Recursive splitting just wraps smarter separators around the same idea.
The video points out a result that surprises people. With the same chunk size and the same overlap, recursive splitting produced 10 chunks where the fixed splitter produced eight. It stops at a sentence boundary even when there is room left in the budget, rather than packing text up to the limit.
What real chunk sizes look like
Because of that behavior, chunks are not uniform. In the project's 1,500 chunks, the distribution was bimodal: a tall cluster of short pieces such as headers and trailing fragments, and a tall cluster of full body paragraphs. The minimum was 67 characters, the maximum 388, the mean 200, and the median just 104. So the chunk size is a ceiling, not a target.
Chunk by data type
The video's rule is that one size does not fit all data:
- Prose splits recursively at around 500 to 1,000 characters.
- Code splits on function boundaries.
- Tables split into row groups, with the header repeated in every chunk.
- Contracts split by clause.
- Transcripts split by speaker turn.
The isolation test
One test, runnable by eye, tells you whether chunking is broken: read a chunk in isolation. If it says something like "increased 40% due to this factor," with no subject and no idea what increased, the context was severed and no retriever or model will recover it. Good chunks stand alone.
Key takeaways
- The window step is chunk size minus overlap.
- Overlap protects facts that fall on a boundary.
- Recursive splitting breaks on paragraphs, lines, sentences, then words, and beats fixed character cuts.
- Chunk size is a ceiling: real chunks vary widely, with a mean of 200 and a median of 104 characters in the project's data.
- Split by data type: prose, code, tables, contracts, transcripts.
- If a chunk cannot be understood alone, fix chunking before touching anything else.
Try it yourself
Take your own documents and chunk them both ways, fixed and recursive, with the same settings. Then read ten random chunks from each out loud. You will feel which ones stand alone and which ones do not, and the video says that signal predicts retrieval quality before you even build the index.
Chapters
- 0:00Introduction: Chunking as the Quiet Quality Lever
- 0:30The Sliding Window Formula: Step Size equals Chunk Size minus Overlap
- 1:15Why Overlap Matters: Preventing Boundary Sentence Seams Fixed vs Recursive Splitting: Paragraphs, Lines, and Sentence Boundaries
- 2:50Chunk Size as a Ceiling: Real-World Distribution and Character Counts
Full transcript(auto-generated, with timestamps)
Introduction: Chunking as the Quiet Quality Lever
[0:00]Namaste, a circumflex euros. This is Liam in for Amia. Build it with Claude then take it apart. Chunking is 12 lines of code that most people write once and never think about again. It also moves retrieval quality more than almost anything else. So, let's take those 12 lines apart. Start with the one detail that matters most. When you slide a window across the text, the step is not the chunk size. It is the chunk size minus the overlap. That single subtraction is what makes chunks overlap instead of sitting edge to edge. Get it wrong and your chunks either gap or
The Sliding Window Formula: Step Size equals Chunk Size minus Overlap
[0:30]Duplicate. Why overlap at all? Because a fact that lands exactly on a boundary gets cut in half a circumflex euros and then either chunk can answer the question. The overlap is a small insurance policy. Repeat a little at each seam so no sentence is orphaned across the cut. But the naive splitter is blind. It cuts at exactly 400 characters whether that's the end of a sentence or the middle of a word. The production fix is recursive splitting. Try to break on paragraphs first then lines then sentences then words and only as a last resort raw characters. And here's what surprises people. Same chunk size, same overlap a circumflex euros, but recursive splitting produced 10 chunks where the fixed splitter produced eight. More chunks from identical settings because recursive splitting stops at a sentence boundary
Why Overlap Matters: Preventing Boundary Sentence Seams Fixed vs Recursive Splitting: Paragraphs, Lines, and Sentence Boundaries
[1:16]Even when there's room left in the budget. It will not pack text up to the limit. Which means your chunks are not uniform at all. Here's the real distribution from 1,500 chunks in the project a circumflex euros and it's bimodal. A tall cluster of short pieces headers and trailing fragments. A tall cluster of full body paragraphs. Minimum 67 characters, maximum 388, mean 200, median just 104. Your chunk size is a ceiling not a target. So, the real rule is chunk by data type. Prose splits recursively around 500 to 1,000 characters. Code splits on function boundaries. Tables split into row groups with the header repeated in every chunk. Contracts split by clause. Transcripts by speaker turn. One size does not fit your data. And here are the actual 12 lines. The whole function is a list comprehension a circumflex euros, but read the range
Step. It's chunk size minus overlap exactly as we said. One guard stops overlap from swallowing the chunk. That's the entire naive chunker. Recursive splitting just wraps smarter separators around the same idea. There's one test that tells you if your chunking is broken and you can run it by eye. Read a chunk in isolation. If it says something like increased 40% due to this factor a circumflex euros with no subject, no idea what increased a circumflex euros, then the context was severed and no retriever or model will recover it. Good chunks stand alone. So keep three things. The step size is chunk size minus overlap a circumflex euros. That subtraction is the whole mechanism. Recursive splitting beats fixed because it stops at real boundaries, so your chunk size is a ceiling, not a target. And the test is simple. If a chunk can't be understood
Chunk Size as a Ceiling: Real-World Distribution and Character Counts
[2:50]Alone, fix the chunking before you touch anything else. Your turn. Take this prompt to your own documents. Chunk them fixed and recursive with the same settings, then read 10 random chunks from each out loud. You'll feel which ones stand alone and which ones don't a circumflex euros, and that's the signal that predicts your retrieval quality before you even build the index. Rag a circumflex euros chunking, the quietest quality lever. Cut on real boundaries and read one alone. This is Liam in for Aamia.
More from Humanitarians AI Fellows
3:14RAG Embeddings: Mean Pooling, Memory Bandwidth, and the 12x Batching Speedup | Ameya
2:05What Is An Agent Harness? | Aishwarya Patil
3:25RAG Evaluation in Production: CI and CD Golden Set Gates and Live Monitoring
1:53What Is AI Red Teaming | Aishwarya Patil
3:25RAG Tokenization: Why Financial Text Costs 3x More and Causes Silent Truncation | Ameya
4:14