Chunking
Chunking is splitting documents into smaller passages, called chunks, before they are indexed for retrieval. In retrieval-augmented generation, a chunk is often an indexing unit. Retrieval may expand it into a parent section or adjacent passages, and ranking, generation, and citation can use different spans. How documents are split therefore decides what a search can find and what the model gets to read.
Size and overlap
Chunk size is a trade-off. Google’s RAG Engine documentation puts one side plainly, “A smaller chunk size means the embeddings are more precise”, and notes that larger chunks give more general embeddings that can miss specific details, since each chunk is compressed into a vector of fixed size. Smaller chunks can focus a representation but may lose the context needed to match or interpret a query. Larger chunks retain more text but can mix topics and consume more context. Retrieval quality depends on the corpus, queries, and embedding model; size alone does not guarantee precision. That service’s defaults, 1,024 tokens per chunk with 256 tokens of overlap, are a starting point, not an answer. Overlap repeats boundary text and can preserve a short passage across a split; it does not guarantee that every sentence fits whole in some chunk. With 200-token windows and 50-token overlap, a fact spanning positions 140 through 219 fits in neither the window starting at 0 nor the one starting at 150. Both pieces remain available, so retrieving neighboring spans can reconstruct it at additional context cost.
A chunk must carry its context
The most damaging chunking errors are not about size. Consider a hypothetical leave policy with a section headed Applies to employees only and, three paragraphs later, the sentence Staff may take up to 16 weeks of parental leave. Split by length, that sentence lands in a chunk without its heading, and a contractor’s question retrieves it as if it applied to everyone. Splitting along the document’s own structure, by sections, headings, list items, and table rows, can preserve local relationships, but conditions in earlier paragraphs, footnotes, or other sections may still be lost. Where a chunk must be cut from a longer section, prefixing it with the document title and heading path restores that heading context, not every dependency. Retain or retrieve referenced conditions and exceptions as needed. Remove repetitive decoration only after distinguishing it from meaningful dates, qualifiers, and table notes.
Each chunk should also carry metadata that retrieval can filter on and answers can cite: a stable identifier, the source document and version, its effective date, the audience or scope it applies to, and the access rules of its source. Tables need their relevant headers and notes. Check embedding, reranking, and generation limits separately, including any title or heading tokens: a passage can fit one stage and be truncated at another. Preserve source offsets when expanding or splitting it.
Chunking choices should be tested, not assumed: run a set of real questions with known answers and check whether the chunk that answers each one is retrieved, as described in Retrieval-Augmented Generation and Tool-Using Agents, which also shows the splitting code. How chunking fits into diagnosing a wrong answer is covered in Last Year’s Policy, Cited Correctly.
References
- Google Cloud, RAG Engine: Fine-tune RAG transformations (Creative Commons Attribution 4.0).
Discover more from Insightful Data Lab
Subscribe to get the latest posts sent to your email.
