# 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.

Also called: text chunking, document splitting, chunk size, text splitting. Category: Data and retrieval. Source: https://aibuildindex.com/glossary/chunking

## In the index

- Search over internal documents: median $2,150, middle half $300 to $8,800, 918 priced briefs (https://aibuildindex.com/cost/document-search-rag)
- RAG: median $3,860, middle half $500 to $14,400, 586 priced briefs (https://aibuildindex.com/skills/rag)

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](https://aibuildindex.com/glossary/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](https://aibuildindex.com/glossary/retrieval-augmented-generation) 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](https://aibuildindex.com/glossary/embedding) and stored in a [vector database](https://aibuildindex.com/glossary/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

- [Retrieval-augmented generation (RAG)](https://aibuildindex.com/glossary/retrieval-augmented-generation): Retrieval-augmented generation is a way of answering questions with a language model that first looks up relevant passages in your own documents, then writes an answer grounded in what it found.
- [Embedding](https://aibuildindex.com/glossary/embedding): An embedding is a list of numbers that represents the meaning of a piece of text, an image or another item, so that items with similar meanings end up close together and can be compared, searched or grouped by software.
- [Vector database](https://aibuildindex.com/glossary/vector-database): A vector database is a data store built to save embeddings, the numeric representations of text, images or audio, and to find the stored items most similar in meaning to a query, which makes it the usual search layer behind RAG systems.
- [Context window](https://aibuildindex.com/glossary/context-window): A context window is the maximum amount of text, measured in tokens, that a language model can take in and produce in a single request, including instructions, documents, conversation history and its own reply.
- [Reranking](https://aibuildindex.com/glossary/reranking): Reranking is a second retrieval step in which a more precise model rescores the top results from a first, faster search and reorders them by relevance to the query, so the best passages reach the user or language model first.
- [Semantic search](https://aibuildindex.com/glossary/semantic-search): Semantic search is search that matches by meaning rather than exact words, typically by comparing embeddings, so a query such as "how do I get my money back" can find a page titled "Refund policy".
