# What Is Chunk Overlap?

> What chunk overlap is, why it keeps a split rule whole, and what it costs, explained simply for your AI interview.

**In short:** Chunk overlap is text repeated at the edge of two neighbouring chunks, so an idea cut at a boundary still appears whole in one of them. It helps retrieval, but repeated text is stored and searched twice, so the value needs testing.

AI and LLM interview question Q115, Retrieval-augmented generation (RAG). Beginner, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-is-chunk-overlap

## Say it in 30 seconds

Chunk overlap means the end of one chunk is repeated at the start of the next. When I split a long document for search, a cut can land in the middle of a rule, and the exception ends up in the next chunk. Overlap copies the words around the cut into both pieces, so the search can return the whole rule. The price is more text to store, repeated results, and a fuller prompt. I'd set a starting value and test it on questions with known answers.

## Say it in 2 minutes

Chunking cuts a long document into pieces before we store it for search. Each piece is embedded, which turns its text into numbers that stand for its meaning, and the search hands back whole pieces. If a cut lands in the middle of a rule, the rule can split across two chunks, and neither one reads as a full answer. Chunk overlap helps with that by repeating a little text at each boundary.

Take a bank's card fee policy. One chunk ends with the cash advance rate, and the next starts with the exception for Premier accounts. Without overlap, a customer who asks about that exception can get a chunk with half the rule. With 50 characters of overlap, the next chunk starts before the cut, so the whole rule sits in one piece.

The cost is real. The repeated text is stored and embedded twice, so the search index (the stored collection of pieces) grows, and the top results can repeat the same passage. LangChain gives a common starting point of 10% to 20% of the chunk size. I would treat that as a place to start testing, then check the failures against questions with known answers.

Overlap doesn't fix everything. A rule spread over a long section, or a fact far from the rule it changes, needs another fix, such as splitting on headings or keeping whole sections together.

## What is chunk overlap, in plain words?

A search system usually hands back whole chunks. So where a document is cut decides what the model can see when it answers. Chunk overlap is a small, deliberate repeat: the end of one chunk is copied to the start of the next.

Think of a hospital shift handover. The night nurse repeats the last hour of her shift to the day nurse, even though the day nurse can read the chart. The first minutes of a shift need that context. Overlap works the same way. The next chunk opens with the words the cut would otherwise have left behind.

Now a real case. A bank's card fee policy says cash advances cost a percentage, and the exception for Premier accounts sits right after it. If the cut falls between the two, the search can return a chunk that gives the rate and misses the exception. The customer then hears the wrong fee.

- **Chunk:** One piece of a document, stored and searched as a single unit.
- **Chunk size:** How big each piece is, counted in characters, or in tokens (the small units of text a model reads).
- **Chunk overlap:** Text repeated at the edge of two neighbouring chunks.
- **Boundary:** The point where one chunk ends and the next begins.
- **Retrieval:** Finding the chunks to show the model when a question comes in.

## How does overlap work, and where does it help?

The fixed-size chunker in the code below cuts the text and steps forward by the chunk size minus the overlap. With 100 characters per chunk and 50 repeated, each new chunk starts 50 characters after the last one, so it begins inside the chunk before it. The overlap has to reach back past the start of the rule, and the next chunk has to be long enough to hold all of it.

*Diagram, Overlap keeps a rule and its exception together: A rule and its exception sit either side of a cut. Without overlap, the cut splits them and no chunk holds the whole rule. With overlap, the edge is repeated, so one chunk holds the rule and its exception together.*
1. A plain cut falls wherever the length runs out.
2. Overlap starts the next chunk early, so the cut is repeated.
3. The cut falls in the middle of the rule, so the rule breaks.
4. The repeated edge keeps the rule and its exception together.

> "Chunk overlap repeats a portion of text between adjacent chunks so that an idea split at a boundary still appears whole in at least one chunk." (LangChain, chunking guide)
>
> "The choice of chunk size, chunk boundary, and chunk overlap can affect retrieval performance" (Anthropic, on contextual retrieval)

Microsoft's guidance describes the same method for fixed-size cuts, where you pick both the size and the amount of overlap.

Here is the idea in code. It is a made-up bank fee policy, cut into 100-character chunks, using only the standard library.

```python
# A made-up bank fee policy, cut into 100-character chunks. Overlap repeats the edge of each cut.
POLICY = (
    "Cash advances cost 4% of the amount, minimum 10 units. "
    "Premier accounts pay no cash advance fee in the first 30 days. "
    "Disputed charges are paused until the bank decides."
)
RULE = "Premier accounts pay no cash advance fee in the first 30 days."

def chunk(text, size, overlap):
    if overlap >= size:
        raise ValueError("overlap must be smaller than size")
    step = size - overlap
    starts = [i for i in range(0, len(text), step) if i == 0 or i + overlap < len(text)]
    return [text[i:i + size] for i in starts]

for overlap in (0, 50):
    parts = chunk(POLICY, 100, overlap)
    whole = any(RULE in p for p in parts)
    stored = sum(len(p) for p in parts)
    print(f"overlap {overlap}: {len(parts)} chunks, {stored} characters stored, rule whole: {whole}")
    for p in parts:
        print("  |" + p + "|")
```

Output:

```text
overlap 0: 2 chunks, 169 characters stored, rule whole: False
  |Cash advances cost 4% of the amount, minimum 10 units. Premier accounts pay no cash advance fee in t|
  |he first 30 days. Disputed charges are paused until the bank decides.|
overlap 50: 3 chunks, 269 characters stored, rule whole: True
  |Cash advances cost 4% of the amount, minimum 10 units. Premier accounts pay no cash advance fee in t|
  |its. Premier accounts pay no cash advance fee in the first 30 days. Disputed charges are paused unti|
  |he first 30 days. Disputed charges are paused until the bank decides.|
```

The first run cuts the rule in two, so the check says no. The second repeats 50 characters at each cut, and the rule sits whole in one chunk. The price is visible too: 269 characters are stored instead of 169.

## What does overlap cost, and what does it not fix?

1. **More to store and embed:** Repeated text is stored and embedded again, so the index grows. In the example, 50 characters of overlap adds about 59% more text to store.
2. **Repeated search results:** Two neighbouring chunks share words, so the top results can hold the same passage twice and push out a second source.
3. **A fuller prompt:** Each retrieved chunk brings its repeat into the prompt, which uses up the space the model reads at once, its context window.
4. **What overlap does not fix:** A rule spread over a long section, or a fact far from the rule it changes, needs more than a few repeated lines. Split on headings, or keep whole sections together.

There is no fixed right value. LangChain says that "there is no universal best value" for chunk size. Its guide gives a common starting point of 10% to 20% of the chunk size, as a place to begin testing.

### How would you choose the overlap for a fee-policy bot?

Start with about 50 questions that real customers ask, each with the right answer and the policy section it needs. A bank's fee bot is judged on the wrong fee, so the test has to include the exceptions.

1. **Try a few settings:** Keep the chunk size near the length of one policy section. Then try overlaps of about 10% and 20% of that size, and zero overlap as the control.
2. **Score the misses:** For each question, check whether the chunk holding the answer was returned. Overlap only helps where the misses are cuts through a rule.
3. **Keep the cheapest setting that passes:** A bigger overlap that adds almost nothing to the score is extra storage and prompt cost with no gain.
4. **Recheck when documents change:** New fee tables or a new product bring new cut points, so run the same questions again.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: the end of one chunk repeated at the start of the next.
- [ ] Why: a cut can split a rule, and overlap keeps it whole in one chunk.
- [ ] How it's sized: chunk size minus overlap is the step between chunks.
- [ ] The costs: more text stored, repeated results, a fuller prompt.
- [ ] What it does not fix: a bad split elsewhere, or context far apart.
- [ ] How you'd choose it: test on questions with known answers.

**Common traps**

- Trap: "More overlap is always better." Better: Overlap repeats text, so it costs storage and prompt space. Raise it only when the test shows misses at the cuts.
- Trap: "Overlap makes the chunks mean the same thing." Better: It only copies the words at the edge. Each chunk is still embedded as its own piece of text.
- Trap: "Overlap fixes any bad split." Better: It helps when the overlap reaches back past the start of the idea. Context far apart needs other fixes, such as splitting on headings.

## Can you spot the problem?

**Spot the broken setting:** A team reviews the chunker config for a claims-policy search. Which setting does this chunker refuse outright?

A. chunk_size=800, chunk_overlap=120
B. chunk_size=800, chunk_overlap=0
C. chunk_size=800, chunk_overlap=800
D. chunk_size=400, chunk_overlap=60

**Answer:** C. In this chunker the step is size minus overlap, so equal values give a step of zero and the window never moves forward. The guard in the code above refuses that setting. Zero overlap is allowed, but it can cut rules.

**Quick check:** A customer asks whether the Premier fee exception applies. The rule and its exception were cut apart, and neither chunk holds both. What helps most?

A. A bigger model
B. Overlap across the cut, so one chunk holds both
C. A lower temperature
D. A longer system prompt

**Answer:** B. Overlap copies the words around the cut into both neighbours, so the search can return one chunk with the rule and its exception. Model size, temperature and the prompt do not change which chunks the search returns.

## Can you answer these from memory?

**Flash cards**

- **What is chunk overlap?** Text repeated at the edge of two neighbouring chunks.
- **Why use it?** So an idea cut at a boundary still appears whole in one chunk.
- **How far does each step move?** Chunk size minus overlap.
- **What does it cost?** Repeated text stored and embedded twice, and repeated search results.
- **Overlap equal to chunk size?** In this chunker the step is zero, so the window never moves. The guard refuses it.
- **A common starting point?** About 10% to 20% of the chunk size, then test.

## Likely follow-up questions

- Q113 What is chunking, and why does size matter? https://designervenkat.online/interview/ai/what-is-chunking-in-rag
- Q114 Fixed vs recursive vs semantic chunking? https://designervenkat.online/interview/ai/fixed-vs-recursive-vs-semantic-chunking
- Q131 Retrieval metrics: recall@k, MRR, nDCG? https://designervenkat.online/interview/ai/retrieval-metrics-recall-at-k-mrr-ndcg
- Q476 Write a chunker with overlap. (full answer coming)
- Q111 What is RAG, and why use it? https://designervenkat.online/interview/ai/what-is-rag

## Learn it in depth

- [Chunking](https://designervenkat.online/learn/ai-engineering/chunking)
