Data and retrieval

Chunking

Chunking is the step in a retrieval system that splits long documents into smaller passages before they are embedded and indexed, so that a search can return the specific section that answers a question rather than a whole file.

A language model cannot read a whole document library for every question, and a retrieval system that returns entire hundred-page manuals is little help. Chunking cuts documents into passages small enough to search precisely and to fit in the model's context window, yet large enough to keep their meaning. It sounds like a minor technical setting, but in practice the way documents are chunked is one of the main reasons a RAG system finds the right answer or misses it.

How it works

The simplest approach is fixed-size chunking: split the text every few hundred tokens, with some overlap so a sentence that straddles a boundary appears in both chunks. It is quick and works tolerably on plain prose.

Better results usually come from structure-aware chunking that follows the document's own shape: split at headings, sections, clauses or list items, keep tables together, and attach the section title to each chunk so it makes sense on its own. A chunk from an employee handbook reading "Carry-over is limited to five days" is far more useful when it also carries the heading "Annual leave". More advanced methods split where the topic changes, or store small chunks for searching while returning the larger surrounding section to the model.

Each chunk is then turned into an embedding and stored in a vector database along with metadata such as the source file, page and date.

What it means for cost

Chunking is where much of the hidden data work in a retrieval build sits. Clean, well-structured documents can be chunked with standard tools in little time. Mixed collections of scanned PDFs, slide decks, spreadsheets and contracts each need their own parsing and splitting rules, and that work shows up in the quote.

Chunk size also affects running costs: larger chunks mean more tokens sent to the model on every question. Ask a builder how they chose the chunking strategy, whether they tested it against real questions with known answers, and how tables and images are handled.

Common mistakes

The usual mistakes are splitting mid-sentence or mid-table, losing the heading that gives a passage its meaning, and choosing a chunk size once without testing. Another is never re-chunking: when documents change format, the old rules can quietly degrade retrieval.

Common questions

What is the best chunk size?

There is no single best size. Short chunks give precise matches but can lose context; long ones keep context but blur the match and cost more to send to the model. The right size is found by testing retrieval on a set of real questions for the specific documents.

Does chunking matter with long-context models?

Less than it did, but it still matters. Even when a model can accept very long inputs, sending whole documents for every question is slow and expensive, and models can overlook details buried in long contexts. Retrieving well-chosen chunks remains cheaper and often more accurate.

Related terms

Pricing a build that involves Chunking? Send the brief and get a fixed price set next to the market range.Get a quote