
RAG Document Chunking: Sizes and Overlap That Actually Work
How to Chunk Documents for RAG: Optimal Sizes, Overlap Settings, and Splitting Strategies
TL;DR
For many pipelines, chunking quality can affect end-to-end answer accuracy as much as or more than the choice of base language model. Split too broadly and retrieval returns noise; split too narrowly and coherent evidence fragments across dozens of disconnected passages. Start with recursive or structure-aware splitting between 256 and 512 tokens, test overlap in the 10 to 25 percent range, preserve metadata on every chunk, and validate every configuration against a scored evaluation set before shipping to production.
Quick Takeaways
- Chunk size is the primary tuning parameter in a RAG pipeline; a mismatch in either direction degrades answer quality more than model choice does.
- Recursive and structure-aware splitting reliably outperform plain fixed-size cutting because they respect natural sentence and section boundaries.
- Azure AI Search guidance from Microsoft Learn (2026) sets 512 tokens as the starting chunk size, giving teams a vendor-tested reference point for their first comparison run.
- Overlap protects against boundary splits but adds storage and latency cost; test zero, ten, and twenty-five percent before locking in a value.
- No chunking configuration should reach production without a scored evaluation set covering retrieval recall, precision, citation accuracy, and answer faithfulness.
What Is Document Chunking in a RAG Pipeline?
RAG document chunking is the preprocessing step that transforms raw source files into indexed, retrievable passages sized for vector search. Chunking quality determines whether the retrieval layer passes the language model precise, relevant evidence or a loosely related wall of text that degrades the generated answer.
Every passage must be small enough to embed accurately, so vector similarity search can surface only the passages most relevant to a user query. The Wikipedia entry on retrieval-augmented generation provides a solid conceptual overview of where chunking fits in the broader pipeline architecture.
When chunks are too large, the embedding averages too many ideas, returning passages that match the query only tangentially and padding the model’s context with noise. When chunks are too small, a single coherent thought scatters across fragments, forcing retrieval to miss context or flood the model with partial results.
Chunking is also where metadata attaches to each passage. Every chunk can carry a document ID, source section heading, page number, timestamp, and access-control label, letting downstream retrieval filter by recency, by department, or by user permission level. Skipping structured metadata at this stage creates compliance and accuracy debt that compounds as the corpus grows.
How Chunk Size Affects RAG Retrieval Quality
Chunk size is the primary tuning dial in a RAG pipeline. Smaller chunks improve topical focus but risk splitting a single idea across passages; larger chunks preserve more context but push embeddings toward an averaged, less discriminating representation. The right size depends on query length, document density, and embedding model context limits.
A practical starting range for general factual retrieval is 256 to 512 tokens. For Azure AI Search, Microsoft Learn (2026) recommends a starting chunk size of 512 tokens. The same guidance notes that 200 words or 600 characters can serve as equivalent targets when working with character-based splitters.
Content where arguments or clauses span multiple sentences benefits from wider windows that preserve contextual continuity, while short self-contained document units retrieve more cleanly at narrower sizes. Document genre is therefore the first variable to audit when the general 256 to 512 token starting range underperforms on a specific corpus.
An embedding model’s maximum input length sets a hard ceiling on chunk size. Many widely used embedding models cap out between 512 and 8192 tokens (for example, text-embedding-ada-002 reaches 8192 tokens), but performance typically degrades well before the stated limit. Keeping chunks at roughly half the model’s rated limit leaves headroom for overlap tokens and special tokens without truncation.
Did You Know?
Token counts and word counts are not interchangeable. A 512-token chunk typically spans 350 to 400 English words, but code, multilingual text, and highly technical vocabulary can tokenize at two to three tokens per word, cutting actual word coverage significantly. Always measure chunk sizes in the same unit your embedding model uses, not in the unit that is easiest to count manually.
How Much Overlap Should RAG Chunks Have?
Chunk overlap copies a portion of one chunk’s tail into the beginning of the next to prevent a sentence at a boundary from losing half its context. It is a safeguard against boundary splits, not a free upgrade: it adds storage, increases embedding costs, and can introduce duplicate retrievals if set too high.
For Azure AI Search, Microsoft Learn (2026) recommends an initial overlap of 25 percent of the chunk length. On a 512-token chunk, that equals 128 bridging tokens per boundary. Adjust upward if evaluation shows frequent boundary-split failures, and trim downward if the same passage surfaces multiple times in a single retrieval batch.
For many general-purpose pipelines, 10 to 20 percent overlap is a reasonable baseline. Some datasets perform just as well with zero overlap, particularly when documents are structured into short, self-contained sections. Zero overlap is worth testing before committing to extra storage and deduplication complexity.
When the same passage surfaces two or three times in a single retrieval batch, the overlap setting is likely too aggressive. Build a deduplication step into the retrieval layer rather than fighting the problem purely through overlap reduction.
RAG Chunking Strategies: Fixed-Size, Recursive, Semantic, and Structure-Aware
Four main strategies dominate RAG document chunking: fixed-size, recursive, semantic, and structure-aware. Each makes a different tradeoff between implementation simplicity, boundary accuracy, and processing cost.
Fixed-size chunking splits text at a hard token or character count with no regard for sentence or paragraph boundaries. It is fast and cheap to run, but routinely bisects sentences and separates a question from its answer. It works adequately for dense, homogeneous corpora where sentences are roughly independent, but is a poor default for mixed document types.
Recursive character splitting attempts to split first on paragraphs, then sentences, then words, working down through a hierarchy of separators until the target size is reached. It respects natural language structure far better than fixed-size splitting. The LangChain text splitter documentation positions the recursive character text splitter as the recommended default for most general-purpose pipelines.
Semantic chunking uses an embedding model to detect topic shifts by measuring cosine distance between consecutive sentences, then splits where distance exceeds a threshold. It can produce chunks that align with actual topic boundaries rather than arbitrary counts. The tradeoff is higher processing cost and sensitivity to the threshold parameter, which requires its own calibration pass against your evaluation set.
Structure-aware chunking reads native document structure such as Markdown headers, HTML section tags, PDF outline nodes, or JSON keys, treating those as natural split points. The LlamaIndex node parser documentation covers parsers for Markdown, HTML, and code files. For well-structured documents, this is typically the most accurate strategy available and costs far less per chunk than semantic detection.
| Strategy | Boundary Awareness | Setup Complexity | Processing Cost | Best For |
|---|---|---|---|---|
| Fixed-size | None | Low | Low | Homogeneous plain text with high sentence independence |
| Recursive | Sentence and paragraph | Low | Low | Mixed document types; general-purpose baseline |
| Semantic | Topic boundary | Medium | High | Corpora where topic coherence is a confirmed retrieval problem |
| Structure-aware | Native document structure | Medium | Medium | Markdown, HTML, PDF with outlines, code repositories |
Did You Know?
Tables, code blocks, and numbered lists behave poorly under any character-based splitter. Many practitioners pre-process these elements into standalone chunks before applying the main splitting strategy, preserving their tabular or syntactic structure as a single unit rather than letting a size limit bisect a table row or divide a function signature across two separate embeddings.
Recommended RAG Chunk Sizes by Document Type
No single chunk size fits every document type. Matching chunk size to content genre and query pattern is the most direct way to lift retrieval quality without changing any other pipeline component.
Short, fact-dense content such as product listings, FAQ entries, and customer support transcripts retrieves well at 64 to 256 tokens. Each unit already encodes a discrete fact, keeping the embedding signal clean.
General business documents, news articles, and blog posts align well with the 256 to 512 token range. This window captures enough context for multi-sentence reasoning while remaining tight enough for meaningful similarity scoring. Vendor guidance for general-purpose search platforms targets exactly this document category.
Dense technical documentation, academic papers, legal contracts, and regulatory filings often call for 512 to 1024 tokens per chunk because a single argument or clause can span multiple paragraphs. For these document types, a parent-child chunk strategy adds measurable value: index small child chunks for precise retrieval, then expand to the larger parent chunk before passing context to the language model. Additional research on long-context retrieval is available in a 2024 preprint (arXiv:2401.18059).
How to Evaluate RAG Chunking with Real Queries
The only reliable way to choose a chunking configuration is to measure it against real queries from your actual user base. Build a representative evaluation set, run candidate configurations through it, and let the scores determine the winner.
A chunking evaluation set should cover the full range of query types users submit: short factual lookups, multi-part questions, comparison requests, and queries that require synthesizing evidence across multiple sections. Annotate each query with the source passage or passages containing the correct answer to create ground truth for measuring retrieval recall and precision.
Key metrics to track include retrieval recall at k, precision at k, answer faithfulness, and citation accuracy. Add storage footprint and query latency to the scorecard, since both increase as chunk count grows with higher overlap or smaller sizes.
Failure-case analysis matters as much as aggregate scores. Review every query where retrieval returned zero relevant passages and categorize each failure: boundary split, table content, scanned PDF, or cross-section evidence requirement. Research covering systematic RAG evaluation frameworks is available in a 2023 preprint (arXiv:2312.06648). Failure categories will reveal which element types need preprocessing before the main splitting pass.
A Step-by-Step RAG Chunking Workflow
A reproducible RAG chunking workflow processes documents consistently, preserves all metadata, and produces chunks that an evaluation set can score and compare. The steps below apply whether you are using LangChain, LlamaIndex, or a custom pipeline built on a bare embedding API.
The Python skeleton below shows the core logic for a recursive text splitting pass with metadata attachment. RecursiveCharacterTextSplitter handles paragraph-first splitting and falls back through sentence and word boundaries when needed.
from langchain.text_splitter import RecursiveCharacterTextSplitter
splitter = RecursiveCharacterTextSplitter(
chunk_size=512,
chunk_overlap=128,
length_function=len,
)
def chunk_document(text: str, metadata: dict) -> list[dict]:
chunks = splitter.create_documents([text], metadatas=[metadata])
return [
{"content": c.page_content, "metadata": c.metadata}
for c in chunks
]
In this skeleton, sizes are measured in characters. Replace len with your embedding model’s tokenizer to work in tokens: a 512-token target typically maps to 350 to 400 English words. Pass a metadata dict carrying at minimum the document ID, source filename, section heading, page number, and any access-control tags your retrieval layer needs at query time.
How to Implement RAG Chunking Configuration in Production
Before tuning any parameter, establish a measurement baseline. Build a labeled evaluation set of 50 to 100 representative queries, run your current or default configuration through it, and record baseline scores for recall at five, precision at five, answer faithfulness, and citation accuracy. Without a baseline, you cannot distinguish signal from noise when a parameter changes.
Once the baseline is in place, run a structured comparison across a matrix of configurations. Test at least three chunk sizes (256, 512, and 1024 tokens) and three overlap levels (zero, 10 percent, and 25 percent) for nine combinations total. Score each against your labeled set and rank by composite retrieval quality. The winning configuration on a specific corpus will often differ from published defaults, which is exactly why measurement exists.
Over the following 60 to 90 days, monitor production retrieval logs for signs of degradation: rising citation error rates, increasing no-relevant-passages fallbacks, and answer faithfulness scores drifting downward as new documents enter the corpus. When any signal crosses a predefined threshold, re-run the evaluation matrix against an updated document sample to determine whether a configuration change is warranted or whether the issue lies elsewhere in the pipeline.
Conclusion
Chunking choices in a RAG pipeline will outlast the initial model selection. As embedding models improve and language models accept larger context windows, the pressure on chunk boundaries shifts, but the core tradeoff between focused retrieval and preserved context does not go away. Start with structure-aware or recursive splitting in the 256 to 512 token range, instrument retrieval metrics from day one, and treat every chunking parameter as a hypothesis to validate against your data rather than a setting to copy from someone else’s production environment.
Frequently Asked Questions
- What is document chunking in RAG?
- Document chunking breaks source files into smaller passages before they are embedded and indexed. The resulting passages let the retrieval layer identify and return only the evidence most relevant to a given query, rather than loading entire documents into the model’s context window.
- What chunk size should you start with?
- Starting between 256 and 512 tokens covers most general factual retrieval scenarios. Adjust based on document density, query length, embedding model limits, and the scores your labeled evaluation set produces before treating any single value as final.
- How much overlap should chunks have?
- A starting band of one-tenth to one-quarter of the chunk length covers most pipelines. Azure AI Search guidance from Microsoft Learn (2026) puts the initial overlap target at a quarter of the chunk length. Test zero overlap first; some well-structured corpora need none and benefit from simpler deduplication as a result.
- Is semantic chunking better than fixed-size chunking?
- Not across the board. Recursive or structure-aware splitting provides a strong, low-cost baseline. Semantic chunking earns its overhead only when your evaluation set confirms that topic coherence failures are a measurable problem in your specific corpus, not as a default starting choice.
- How can chunking quality be measured?
- Build a representative labeled question-and-answer set, then score each candidate configuration on retrieval recall, precision, answer faithfulness, citation accuracy, query latency, and storage footprint. Reviewing failure cases covering tables, code blocks, scanned PDFs, and boundary-split sentences reveals problems that aggregate metric scores alone will not expose.