New Tool Radar

AI Concepts

How to Choose a Chunk Overlap Size So RAG Does Not Split an Answer Across a Boundary

Set an overlap between neighbouring chunks, test whether answers that straddle a boundary are still retrieved, and adjust the overlap until they are.

Schematic with three steps: Pick a starting overlap and rebuild; Test the boundary questions; Shrink the overlap until failures return.

Fixed-size chunking cuts a document every N tokens, and an answer can fall exactly across the cut, leaving half the fact in one chunk and half in the next. Neither chunk alone answers the question, so the retriever misses it. Overlap repeats the end of one chunk at the start of the next, so a fact near a boundary appears whole in at least one chunk. The right overlap is the smallest one that stops boundary misses on your own test questions.

What you need

  • A set of test questions whose answers sit near chunk boundaries
  • The chunk size you already use, in tokens
  • A way to rebuild the index with a different overlap

Step 1: Pick a starting overlap and rebuild

Start with an overlap of about a tenth of the chunk size, for example 50 tokens of overlap on 500-token chunks, and rebuild the index. Overlap is shared text, so it costs a little extra storage and embedding work.

Step 2: Test the boundary questions

Run the test questions whose answers straddle a boundary and check whether the full answer now appears in a retrieved chunk. A question that still fails needs a larger overlap or a different chunking method.

Step 3: Shrink the overlap until failures return

Reduce the overlap in steps and re-run the same questions. Keep the smallest overlap that still passes all of them, so you do not pay for repeated text that buys nothing.

Worked example: synthetic overlap test on 4 boundary questions

The table below is a synthetic example. It shows the expected result of testing overlap sizes; no index was built.

Overlap Boundary questions passed Extra tokens
0 tokens 1 of 4 None
50 tokens 3 of 4 Small
100 tokens 4 of 4 Moderate
200 tokens 4 of 4 Large

Expected result (UNTESTED). 100 tokens of overlap passes all 4 boundary questions, and 200 tokens adds cost without passing more. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • Overlap only helps when the answer fits inside one overlapped chunk; a fact longer than the chunk still splits.
  • Every overlapped token is embedded twice, so overlap raises ingestion cost and index size.
  • Chunk boundaries, chunk size and overlap all affect retrieval, so change one at a time when testing.
  • Anthropic notes that chunk boundaries and overlap affect retrieval performance, so measure rather than guess.

Sources

See all