R204 · Knowledge for agents › Retrieval over long documents

RAG chunk size is the last knob: measure, fix boundaries, restore context

Read the original

Authors Hao Hoang

ragretrievalevalsteaching

Source: Hao Hoang's LinkedIn post, 2026-11-21, part of his AI Agent Engineering Interview Questions series. Framed as an interview question; useful as a debugging order for any team whose RAG returns "sort-of-relevant" results.

The scenario

A RAG system returns chunks that are loosely on-topic. One engineer wants smaller chunks (100 tokens instead of 500), another wants bigger ones (1,500). The post's point is that both proposals trade one failure for another, and that size should be tuned last.

  1. Measure retrieval on its own. Label real queries with the passages that answer them and track recall@k (how often the right passage is in the top k). Without this, every change is a guess, and end-to-end answer quality mixes retrieval errors with generation errors.

  2. Fix boundaries before size. Split on document structure (headings, paragraphs, sentences) with roughly 10-20% overlap so no chunk starts mid-thought.

  3. Put the missing context back. Contextual retrieval prepends a short model-written note about where the chunk sits in its document before embedding it. Cost: one model call per chunk at index time.

  4. Search small, send big. Match on small chunks, then hand the model the parent section. Cost: more prompt tokens per answer.

  5. Only then tune size, against the retrieval eval from step 1.

The summary claim: most chunk-size debates are really missing-context problems.

Tradeoffs

TechniqueHelps withCosts
Structure-aware splittingchunks that start or end mid-thoughtper-format parsers; messy sources (PDFs, chat logs) have weak structure
Overlapanswers split across a boundaryindex size, near-duplicate hits
Contextual noteschunks that lost their subjectone model call per chunk; re-index when the prompt or model changes
Small-to-bigprecise matching plus enough context to answerprompt tokens; parent sections can be long

Failure modes to watch

Review checklist

Teaching notes

Good as a whiteboard exercise: give students one document and two queries, chunk it at three sizes, and have them find which queries fail at each size and why. Then add contextual notes and show the failures change without changing size.

Cited in field guides

Connections

See R204 on the knowledge map

Part of the Research notes on nowucca.com. Figures and claims are the source's own unless the summary says otherwise.