RAG chunking strategies are the rules you use to split documents into the pieces that get embedded, retrieved and handed to a language model. Start with structure-aware recursive splitting at about 200 to 500 tokens with little or no overlap, then measure. This guide covers sizes, overlap, eight methods, metadata, code and a simple evaluation loop.
- Split on the document's own structure first (headings, pages, functions), then cap size with a recursive splitter; that beats fixed-size cuts for most corpora.
- In Chroma's benchmark, a recursive splitter at 200 tokens with no overlap was consistently strong, while 800-token chunks with 400 overlap scored lowest on precision.
- Overlap is not free: it duplicates tokens and lowers precision. Start at zero to 15 percent and keep it only if your recall numbers improve.
- Prepend context to every chunk (document title, section path, or an LLM-written summary); Anthropic's contextual retrieval cut failed retrievals by 35 to 67 percent.
- Pick chunking by evaluation, not by blog post: 30 to 50 real questions with known answers are enough to compare strategies.
What are RAG chunking strategies?
RAG chunking strategies are the rules that decide where you cut your documents before embedding them for retrieval-augmented generation. Each chunk becomes one vector in your index, one search result, and one block of text the model reads, so the cut points decide what your system can find. If RAG is new to you, start there.
You chunk for three reasons:
- Embedding limits. Embedding models have a maximum input. OpenAI's
text-embedding-3-smalland-largeaccept up to 8,192 tokens, according to the embeddings guide. - Precision. One vector for a whole 40-page manual averages away the details. A smaller chunk has a sharper meaning, so it matches specific questions better.
- Context budget. Whatever you retrieve goes into the prompt. Five tight chunks leave room for instructions and conversation; five bloated ones crowd them out and cost more.
The trade-off runs in both directions. Chunks that are too small lose the context that makes them meaningful ("it increased 12 percent" with no subject). Chunks that are too large match many queries weakly and drag irrelevant text into the answer.
What chunk size should you use for RAG?
Start with 200 to 500 tokens for prose, split on the document's structure, and adjust from measurements. Use smaller chunks for short factual lookups and larger chunks or whole pages for questions that need reasoning across paragraphs.
Two public benchmarks are worth knowing, because they disagree with a lot of copy-pasted advice.
Chroma (July 2024) measured retrieval at the token level across several corpora. A RecursiveCharacterTextSplitter at 200 tokens with no overlap was consistently strong. The setting Chroma treats as OpenAI's default (800-token chunks, 400 overlap) had slightly below-average recall and the lowest precision and IoU of everything tested. The report also found that the choice of strategy moved recall by up to 9 percent.
NVIDIA (June 2025) tested token chunks from 128 to 2,048 tokens against page-level and section-level chunking on five datasets, scoring end-to-end answer accuracy. Page-level chunking had the highest average accuracy (0.648) and the most consistent results. The best fixed size varied by dataset: 512 tokens for one, 1,024 for another, and 128 tokens was the weakest on the knowledge-graph set.
Practical starting points:
| Content | Start with | Why |
|---|---|---|
| Help center, FAQs | One article or Q&A pair per chunk | Each item already answers one question |
| Technical docs in Markdown | Split by heading, cap at 300 to 500 tokens | Sections are the unit people ask about |
| Reports and paginated PDFs | One page per chunk | Pages hold tables and figures together |
| Contracts, policies | Split by clause or numbered section | Answers cite a clause |
| Source code | One function or class per chunk | Matches how developers ask |
| Chat logs, transcripts | Group by topic or time window | Single messages lack context |
If you use OpenAI's file search, the default auto strategy currently uses 800-token chunks with 400 tokens of overlap. A static strategy lets you set max_chunk_size_tokens between 100 and 4,096 and chunk_overlap_tokens up to half the chunk size, per the vector store API reference.
Does chunk overlap help?
A small overlap can help recall, but overlap is not free: it repeats the same tokens in neighboring chunks, grows the index and lowers precision. Start with zero to 15 percent overlap and keep it only if your recall improves.
Overlap exists so that a fact sitting on a boundary appears whole in at least one chunk. That matters most when chunks are small and splits are blind (fixed character counts). When you split on paragraphs, headings or sentences, boundaries already fall in sensible places and overlap adds less.
The evidence:
- Chroma found that reducing overlap improved IoU, a metric that penalizes redundant tokens, and that with a small-context embedding model, overlap was needed for high recall.
- NVIDIA tested 10, 15 and 20 percent overlap on one dataset and saw the best result at 15 percent with 1,024-token chunks, noting it was not a full grid search.
A useful default: no overlap for structure-aware chunks, 10 to 15 percent for fixed-size chunks.
Which chunking methods are there, and when do you use each?
There are eight methods worth knowing, from simple fixed-size cuts to LLM-assisted chunking. Most production systems combine a structural split with a size cap and add context to each chunk.
| Method | How it splits | Cost | Use when |
|---|---|---|---|
| Fixed-size | Every N tokens or characters | Lowest | Quick baselines, uniform text |
| Recursive | Paragraphs, then lines, then words until under N | Low | General prose, the default |
| Structure-aware | Headings, HTML tags, JSON objects, code blocks | Low | Docs, wikis, Markdown, code |
| Page-level | One page per chunk | Low | PDFs, reports, slide decks |
| Semantic | Starts a new chunk where embedding similarity between sentences drops | Medium | Long unstructured prose |
| LLM-based | A model decides the boundaries | High | Small, high-value corpora |
| Late chunking | Embeds the whole document, then pools token vectors per chunk | Medium | Long-context embedding models |
| Contextual chunks | Any split, plus a generated context line prepended to each chunk | Medium | Most corpora, once the basics work |
A few notes on the less obvious ones:
- Recursive splitting in LangChain tries the separators
"\n\n","\n"," "and""in order, keeping paragraphs intact where possible. The LangChain docs recommend it as the starting point for most use cases. Add sentence punctuation to the separator list for languages such as Chinese and Japanese. - Semantic and LLM-based chunking led some of Chroma's metrics, but a 200-token recursive split came close at a fraction of the cost. LLM chunking can take minutes per corpus instead of seconds.
- Late chunking (Günther et al.) runs the full text through a long-context embedding model and splits afterwards, so each chunk's vector carries information from the rest of the document. It needs no extra training but does need an embedding model that exposes token-level outputs.
How do you chunk different document types?
Chunk each document type along the structure its readers use: sections for docs, pages for PDFs, whole tables as single chunks, and functions for code. Mixed corpora need a splitter per type, not one setting for everything.

Markdown and HTML. Split on #, ## and ### headings, keep the heading path as metadata, then cap long sections with a recursive splitter. Keep code blocks and lists whole.
PDFs. Parse with a layout-aware extractor so you get reading order, headings and tables instead of a stream of lines. Then chunk by page or by detected section. Strip repeated headers, footers and page numbers before embedding, because they add noise to every chunk.
Tables. Keep a table in one chunk with its caption and column headers. If a table is too large, split by rows and repeat the header row in each piece. A row of numbers without its headers is unretrievable and invites the model to guess.
Code. Split on functions, classes or methods, and include the file path and the class name. Retrieval for code often works better with search on symbols and file paths alongside embeddings.
Conversations and tickets. Group messages by thread or by topic, and keep the question with its accepted answer.
What metadata should each chunk carry?
Every chunk should carry its source, its position in the document and enough context to stand alone. Metadata serves two jobs: filtering at query time and adding meaning to the text you embed.
Store at least:
source(file name or URL) andtitlesectionpath, such asBilling > Refunds > EU customerspagefor PDFsupdated_at, so you can prefer or filter recent content- access fields (
team,tenant,visibility) if not every user may see every document
Then put the most useful context into the embedded text itself. A chunk that begins "Billing > Refunds > EU customers" matches a question about EU refunds even if the paragraph never says "EU".
Anthropic's contextual retrieval takes this further: a small model writes a 50 to 100 token context for each chunk, which is prepended before embedding and before building a BM25 keyword index. In Anthropic's tests at top-20 retrieval, contextual embeddings cut failed retrievals by 35 percent, adding contextual BM25 brought that to 49 percent, and adding reranking to 67 percent. This is the prompt Anthropic published:
<document>{{WHOLE_DOCUMENT}}</document>Here is the chunk we want to situate within the whole document<chunk>{{CHUNK_CONTENT}}</chunk>Please give a short succinct context to situate this chunk within the overall document for the purposes of improving search retrieval of the chunk. Answer only with the succinct context and nothing else.Because the whole document is sent once per chunk, use prompt caching so the document is processed at the cached rate after the first call.
How do you implement structure-aware chunking in Python?
Split by headings first, then cap each section's size with a token-based recursive splitter, then prepend the source and heading path. This example uses langchain-text-splitters and tiktoken.
pip install langchain-text-splitters tiktokenfrom langchain_text_splitters import MarkdownHeaderTextSplitter, RecursiveCharacterTextSplitterheaders = [("#", "h1"), ("##", "h2"), ("###", "h3")]by_section = MarkdownHeaderTextSplitter(headers, strip_headers=False)by_size = RecursiveCharacterTextSplitter.from_tiktoken_encoder( encoding_name="cl100k_base", chunk_size=400, chunk_overlap=0)def chunk_markdown(text: str, source: str) -> list[dict]: chunks = [] for doc in by_size.split_documents(by_section.split_text(text)): path = " > ".join(doc.metadata[k] for k in ("h1", "h2", "h3") if k in doc.metadata) chunks.append({ "text": f"{source} | {path}\n\n{doc.page_content}", # embedded text carries its context "source": source, "section": path, }) return chunksfrom_tiktoken_encoder measures chunk_size in tokens rather than characters, and recursively splits any piece that is still too large. Count tokens with the tokenizer closest to your embedding model; token counts differ between model families. The embeddings explainer covers what happens to the text next.
How do you evaluate a chunking strategy?
Evaluate chunking with a small set of real questions whose answers you know, and compare retrieval recall and answer quality across two or three strategies. Change one setting at a time.
- Collect 30 to 50 questions from real users, support tickets or search logs. Include short factual ones and ones that need several paragraphs.
- Record the answer location for each question: the document and the exact sentence or table that answers it.
- Index the corpus once per strategy, for example recursive at 200 and 400 tokens, and page-level.
- Measure retrieval: for each question, does the answer text appear in the top 5 (or top k you will actually use) chunks?
- Measure answers: run the full pipeline and grade answers as correct, partial or wrong, by hand or with an LLM judge you have spot-checked.
- Check cost: count index size and average tokens retrieved per question.
- Keep the cheapest strategy within a point or two of the best, then try adding context to chunks.
def recall_at_k(eval_set: list[dict], search, k: int = 5) -> float: """eval_set items: {"question": str, "answer_text": str}; search returns [{"text": str}, ...].""" hits = sum( any(item["answer_text"] in r["text"] for r in search(item["question"], k=k)) for item in eval_set ) return hits / len(eval_set)The substring check is strict: an answer split across two chunks counts as a miss, which is exactly the failure you want to see. Our guide to LLM evaluation covers judges and test sets in more depth.
This kind of experiment is repetitive work that a coding agent can run for you: index, measure, change one setting, repeat. With Orkio, Claude Code or Codex can run the loop on an always-on cloud box and open a pull request with the results while your laptop is closed.
Do you still need chunking with long context windows?
For small knowledge bases, often not. Anthropic suggests that if your material is under about 200,000 tokens, you can put all of it in the prompt and use prompt caching instead of building retrieval.
Chunking still pays off when the corpus is larger than a context window, changes often, has per-user access rules, or when you need answers to cite a specific source. Long prompts also cost more per question and models can miss details buried in the middle; see our explainer on the context window. A common middle path: retrieve small chunks for matching, then pass the parent section or page to the model.
A chunking checklist to start with
Use this order when you set up or fix RAG chunking:
- Clean the text: remove headers, footers, navigation and duplicate boilerplate.
- Split on structure: headings, pages, clauses, functions or Q&A pairs.
- Cap size with a token-based recursive splitter at about 200 to 500 tokens.
- Set overlap to zero for structural chunks, 10 to 15 percent for fixed-size ones.
- Keep tables whole with their headers; keep code blocks whole.
- Prepend source and section path to the embedded text; store metadata for filters.
- Build a 30 to 50 question evaluation set and measure recall at your real k.
- Try one change at a time: size, then page-level, then contextual chunks and BM25.
- Re-run the evaluation whenever the corpus or the embedding model changes.
Frequently asked questions
What is the best chunk size for RAG?
There is no single best size, but 200 to 500 tokens is a sound starting range for prose, with smaller chunks for factoid questions and larger chunks or whole pages for analytical ones. NVIDIA found 256 to 512 tokens or page-level chunks worked best for factoid queries and 1,024 tokens or page-level for complex ones. Test two or three sizes on your own questions.
Should RAG chunks overlap?
Use a small overlap or none. Overlap protects facts that straddle a boundary, but it repeats tokens, inflates the index and lowers precision. Chroma's evaluation found that reducing overlap improved efficiency metrics, so treat overlap as a setting to measure rather than a default.
Is semantic chunking better than recursive chunking?
Sometimes, by small margins. In Chroma's 2024 benchmark, embedding-based and LLM-based chunkers led on some metrics, but a plain recursive splitter at 200 tokens was close behind and far cheaper to run. Try structural and recursive splitting first and move to semantic chunking only if evaluation shows a gain.
How do I chunk PDFs with tables?
Extract the PDF with a layout-aware parser, keep each table as one chunk with its caption and column headers, and chunk the surrounding text by section or page. A table split across chunks loses its headers, which makes the numbers unretrievable and easy to misread.
Do I still need chunking with long context models?
For small knowledge bases, often not. Anthropic suggests that if your material is under about 200,000 tokens you can put all of it in the prompt and use prompt caching instead of building retrieval. Larger or fast-changing corpora still need chunking and search.
SOURCES
- Chroma: Evaluating Chunking Strategies for Retrieval (July 2024)
- NVIDIA Technical Blog: Finding the Best Chunking Strategy for Accurate AI Responses (June 2025)
- Anthropic: Introducing Contextual Retrieval
- OpenAI API reference: Vector stores (chunking strategy)
- OpenAI docs: Embeddings
- LangChain docs: Text splitters
- Günther et al.: Late Chunking (arXiv 2409.04701)


