Chunking — the cut decides the quality
Chunking looks like a preprocessing footnote. It is, in practice, the highest-leverage decision in most RAG systems — more than the vector database, often more than the embedding model. Here's why it can't be dodged.
You know from Lesson 2 that an embedding is a lossy compression of meaning into one vector. Compress a sentence: crisp. Compress a 40-page document: the vector becomes an average of forty pages of topics — a gray smear that matches everything weakly and nothing well. But cut too small and each fragment loses the context needed to be understood ("It increased by 40%" — what did?). Chunking is finding the size where each piece is about one thing, and understandable alone.
The film-archive analogy: you're cutting a movie into clips for a searchable library. Keep whole reels and every search returns two hours of footage for a ten-second moment. Cut mid-scene and no clip makes sense on its own. You want cuts at scene boundaries — with a little overlap so nothing important falls between two clips.
The strategy ladder, simplest to smartest:
- Fixed-size with overlap — the baseline: ~300–800 tokens per chunk, 10–20% overlap between neighbors (the overlap exists precisely so an idea straddling a boundary survives whole in at least one chunk). Works surprisingly well; start here.
- Recursive splitting — try to split on paragraph breaks first, fall back to sentences, then words, only when a piece is still too big. Respects natural seams instead of cutting mid-sentence.
- Structure-aware — the professional default: split documents by headings/sections, code by functions and classes (parser-based, not line counts), PDFs with awareness of pages and tables. The document's author already marked the scene boundaries; use them.
- Semantic chunking — embed each sentence, walk the sequence, and cut wherever similarity between neighbors drops (a topic shift, detected geometrically). Elegant, costlier, sometimes worth it for messy unstructured text.
Two modern upgrades worth knowing by name:
- Contextual retrieval (popularized by Anthropic): before embedding each chunk, prepend a short LLM-generated situating line — "This chunk is from the Q3 sales report, section on the Karachi region…" — so the fragment carries its context into the vector. Directly attacks the "understandable alone" problem; measured retrieval-failure reductions are large.
- Small-to-big (parent-document) retrieval: search over small, precise chunks, but return the larger parent section they came from. Matching precision of small pieces, reading context of big ones — decoupling the two jobs a chunk was doing.
And always attach metadata to every chunk — source, title, section, date, permissions. It costs nothing at indexing time and enables filtering, citations, and access control forever after.
Summary
Chunk so each piece is about one thing and survives standalone. Start fixed-size-with-overlap (~400 tokens, 10–20%), graduate to structure-aware, and reach for contextual/small-to-big when quality demands it. Metadata always.
Mental model
Cutting film at scene boundaries, with a few seconds of overlap, and writing a slate card for every clip.
Mistakes to avoid
- Chunking PDFs by character count straight through tables and headers, then blaming the embedding model for terrible retrieval. Garbage cuts, garbage search — the Module 2 data lesson, reincarnated.
- Tuning chunk size by vibes. It's a measurable hyperparameter — Topic 52 gives you the retrieval metrics to tune it against.
Exercise
Take one real document ≥5 pages. Chunk it three ways — fixed 300 tokens, fixed 800, and by headings — and for each, run 5 identical questions through your Topic 48 pipeline. Track where the correct chunk ranked. You'll see with your own eyes that the same embeddings, same question, same document yield different answers depending on where the knife fell.