Chop the Book
Robo can't search a whole book at once, so the book gets chopped into pieces called chunks. For every question, Robo picks the chunk that matches best. If the answer is cut in half, or lost inside a giant chunk, Robo can't answer. How big should the pieces be?
This is my Junior Ranger handbook, chopped into tiny 20-word pieces. Lots of answers got cut in half! Drag the chunk size slider and watch the colours change.
The handbook, chopped into 0 chunks
Each little block is one word, read left to right, row by row. Tap a block to read its chunk.
Challenges
What just happened?
- Robo can't search a whole book in one go, so the book was chopped into chunks, and each question fetched the best-matching chunk.
- Too small: the answer gets cut in half. The chunk Robo finds has only part of it.
- Too big: the answer is mixed in with lots of other stuff, so the match gets weaker, and Robo stops reading before he reaches it.
- Overlap repeats a few words between neighbours, so an answer that sits on an edge is whole in at least one chunk.
- The best size sits in the middle. Real apps test this on their own questions, just like the sweep.
How it works
Chop
Walk through the book and cut a piece every "size" words. With overlap, each new piece starts a little before the last one ended.
Fingerprint
Turn each chunk into a list of 512 numbers. Every word adds its own fixed pattern; rare words count more.
Ask
The question gets a fingerprint the same way.
Match
Compare the question's fingerprint with every chunk's. The closest chunks win.
Check
We know where each answer is in the book, so we can check whether the winning chunk holds all of it.
For grown-ups: what's really going on
Chunking is the first design decision in any RAG pipeline. Documents are split into passages, each passage is embedded once into a vector index, and at query time the top-k passages by similarity go into the language model's prompt. This page runs that loop on a 1,200-word handbook with 12 questions whose answer spans are known, so retrieval quality can be measured exactly.
- Chunker: fixed-size sliding window over whitespace words, stride = size − overlap. Real systems usually count tokens and prefer to cut at sentence or paragraph boundaries (recursive splitters), which reduces splits without changing the trade-off.
- Embedding: a deterministic hashed bag-of-words vector (the hashing trick): each content word gets a fixed pseudo-random ±1 vector in 512 dimensions, weighted by IDF (computed over the book's sentences), summed and L2-normalised. Similarity is the cosine
q·c. It is lexical, not semantic, but it dilutes exactly like a dense embedding does: the more unrelated words a chunk contains, the smaller the share of its vector that matches the question. - Reading window: only the first 80 words of a chunk are embedded and counted, standing in for an encoder's maximum input length (all-MiniLM-L6-v2 truncates at 256 word pieces; many models at 512) and the limited room in the prompt. Text past the limit is invisible to search, which is a real and common chunking bug.
- Metrics: recall@k = share of questions where a top-k chunk contains the entire answer span within its read window. "Split" means the top-1 chunk overlaps the span only partly; "buried" means it contains the span past the window.
- What to expect: recall rises steeply once chunks exceed the answer length (10 to 24 words here), peaks around 40 to 100 words, then falls as chunks get diluted and truncated. Overlap of 10 to 25% is a common default; it costs index size (more, partly duplicated chunks). With only 12 questions, the curve is bumpy: each question is worth 8 points.
- Further options: parent-document retrieval (search small chunks, return their bigger parent), sentence-window retrieval, and semantic chunking (cut where embeddings of adjacent sentences diverge).