AI & prompting

Chunking for RAG: Chunk Size, Overlap and Strategies

Chunking splits documents into passages small enough to embed and retrieve on their own, usually a few hundred tokens each with some overlap between neighbours. A good default is to split on the document's structure (headings, then paragraphs), cap each chunk at around 500 to 800 tokens, and add 10 to 25% overlap, then test retrieval on real questions and adjust.

If you need the bigger picture first, what is RAG covers the whole pipeline. This article is about the step that most often decides whether retrieval works.

Why chunking matters so much

In RAG, each chunk becomes one vector, and the search compares the question's vector against every chunk's vector (usually with cosine similarity). That creates two opposite failure modes:

  • Chunks too big: one vector has to represent several topics at once, so it matches none of them well. You also spend context window space on text that doesn't help the answer. Microsoft's chunking guide makes this point about a wiki page covering many sub-topics: it may fit the model's input limit, but splitting it more finely often retrieves better.
  • Chunks too small: a passage loses the context that makes it findable. Anthropic's example is the sentence "The company's revenue grew by 3% over the previous quarter." On its own, it doesn't say which company or which quarter, so a question naming either won't find it.

There is also a hard limit. Embedding models cap input length; Microsoft gives 8,191 tokens for text-embedding-3-small. Text past the limit is lost or rejected, so oversized chunks must be split anyway.

Published starting points for chunk size and overlap

SourceChunk sizeOverlap
Microsoft (Azure AI Search), fixed-size starting point512 tokens (about 2,000 characters)25% (128 tokens)
Microsoft, Text Split skill defaults when counting characters2,000 characters500 characters
Microsoft, general fixed-size example200 words or 600 characters10 to 15%
OpenAI vector stores (file search) default800 tokens (allowed: 100 to 4,096)400 tokens (at most half the chunk size)
Anthropic, describing typical RAG systems"usually no more than a few hundred tokens"Not specified

These are defaults and starting points, as of October 2026, not results of a benchmark on your data. Microsoft notes that structured data may need less overlap and narrative text may benefit from more.

Chunking strategies compared

StrategyHow it splitsGood forWeakness
Fixed-sizeEvery N characters or tokens, with overlapPlain text with little structure; quick first versionCuts sentences and tables mid-way
Sentence or paragraphOn sentence endings or blank lines, packing units up to a size limitProse, articles, support answersParagraphs vary wildly in length
Structure-awareOn headings in Markdown or HTML, or on document sections, then by paragraph inside long sectionsDocumentation, manuals, policies, specsNeeds a parser per format
SemanticWhere the meaning shifts between sentences, often detected with embeddingsLong documents with topic changes and no clear headingsSlower and harder to debug

Microsoft lists the same families and adds a useful hybrid: chunk by content, but append the document title to chunks from the middle of a document so they keep their context.

A minimal fixed-size chunker in Python

This splits by characters with overlap. It is the simplest version and a baseline to compare others against:

def fixed_chunks(text, size, overlap):
    assert 0 <= overlap < size
    step = size - overlap
    return [text[i:i + size] for i in range(0, max(len(text) - overlap, 1), step)]

for c in fixed_chunks("abcdefghijklmnopqrstuvwxyz", 10, 3):
    print(repr(c))

Output:

'abcdefghij'
'hijklmnopq'
'opqrstuvwx'
'vwxyz'

Each chunk starts with the last 3 characters of the previous one ("hij", "opq", "vwx"). That is what overlap does: anything cut at a boundary appears whole in at least one chunk, as long as it is shorter than the overlap.

Measured: how size and overlap change the chunk count

We ran that function on the plain-text version of RFC 9110 (the HTTP specification), about 503,000 characters and 69,000 words after collapsing blank lines:

Chunk size (characters)OverlapChunksCharacters embedded vs original
1,00005031.00x
1,0002006291.25x
2,00002521.00x
2,0005003351.33x
4,00001261.00x

Overlap is not free. A 25% overlap (500 of 2,000) means a third more text to embed and store, and more near-duplicate chunks competing in search results. Microsoft's own test on a NASA e-book shows the same pattern with its Text Split skill: 85 chunks at 2,000 characters with no overlap, 113 with 500 characters of overlap.

We also split the same RFC on its numbered section headings instead. That gave 292 sections, with a median of 1,181 characters but a largest section of 53,892 characters. Real documents are uneven like this, which is why structure-aware chunking still needs a size cap: split on headings first, then split any section that is still too long by paragraph.

A practical recipe

  1. Extract clean text with structure. Keep headings, list items and table rows. Drop navigation, footers and repeated page headers, which otherwise end up in every chunk.
  2. Split on structure first: headings, then paragraphs, then sentences.
  3. Cap chunk size at roughly 500 to 800 tokens and merge tiny neighbouring pieces so you don't index one-line chunks. Use a tokenizer to measure, since embedding limits are in tokens; the larely token counter gives a quick estimate for a sample passage.
  4. Add overlap of 10 to 25% where splits fall inside running prose.
  5. Attach context and metadata: document title, section heading path, source URL, date and access permissions. Prepending the title and heading to the chunk text helps retrieval; the rest is for filtering and citing.
  6. Keep units whole where splitting destroys meaning: a code block, a table with its header row, a numbered procedure.

Contextual retrieval: fixing chunks that lost their context

Anthropic's contextual retrieval technique goes one step further. Before embedding, a model reads the whole document and writes a short context for each chunk, usually 50 to 100 tokens, which is prepended to the chunk. In Anthropic's example, the revenue sentence above is stored as "This chunk is from an SEC filing on ACME corp's performance in Q2 2023; the previous quarter's revenue was $314 million. The company's revenue grew by 3% over the previous quarter." Anthropic reports that, in its tests, this reduced the rate of failed retrievals in the top 20 results by 35% with contextual embeddings alone (5.7% to 3.7%), by 49% when combined with contextual keyword (BM25) search, and by 67% with reranking added on top.

The cost is one model call per chunk at indexing time. With prompt caching, so the document isn't paid for in full on every call, Anthropic estimated the one-time cost at $1.02 per million document tokens under its stated assumptions.

How to tell if your chunking works

Don't judge chunking by reading chunks. Judge it by retrieval:

  1. Write 20 to 50 real questions and note which passage answers each one.
  2. For each chunking setup, run the questions and check whether the answering passage appears in the top 5 or top 10 results.
  3. Change one thing at a time (size, overlap, splitting rule) and re-run.
  4. Look at the failures. If the right passage was split across two chunks, increase overlap or split on structure. If it was retrieved but buried under a long chunk, reduce size.

Re-embed everything after a chunking change. Mixing chunks made under different rules makes the results impossible to interpret. And check whether you need RAG at all: Anthropic notes that a knowledge base under about 200,000 tokens can simply go in the prompt, which removes chunking from the problem. See what is a context window for the limits.

Frequently asked questions

What is the best chunk size for RAG?
There is no single best size. Published starting points cluster around a few hundred tokens: Microsoft suggests 512 tokens with 25% overlap, and OpenAI's vector stores default to 800 tokens with 400 tokens of overlap. Start there, then test retrieval on real questions from your users and adjust.
Do I need chunk overlap?
Overlap helps when a fact or sentence would otherwise be cut in half at a chunk boundary, because the end of one chunk is repeated at the start of the next. It costs storage and embedding calls: 25% overlap means about 1.33 times as many characters to embed. Structure-aware splitting on headings and paragraphs reduces the need for it.
Should I chunk by tokens or characters?
Embedding models limit input in tokens, so tokens are the safer unit for staying under the limit. Characters are simpler and work as an approximation; Microsoft's guidance equates 512 tokens with about 2,000 characters for English text. Code, non-English text and tables use more tokens per character.
Do I need to chunk at all if my documents are small?
Not always. Anthropic notes that a knowledge base under about 200,000 tokens can be put directly in the prompt instead of using RAG. Microsoft also points out that a short page covering several unrelated topics can still retrieve better when split, because one vector represents one page's mixed meaning poorly.

Sources