# What Is Chunking in RAG?

> What chunking is in RAG, why chunk size can change a bot's answers, and how to pick and test a size, explained simply for your AI interview.

**In short:** Chunking means cutting documents into smaller pieces that a RAG system can search and return one at a time. Size matters: too small and a chunk loses its context, too big and it mixes topics and wastes space in the prompt.

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

## Say it in 30 seconds

Chunking means cutting a long document into smaller pieces before a RAG system stores them. When someone asks a question, the system searches those pieces and passes the best few to the model. Size matters. Too small, and a chunk loses the rule it belongs to, such as a grade and its leave days. Too big, and it mixes several topics and crowds the prompt. There is no perfect number, so I test a few sizes on real questions and measure which one finds the right text.

## Say it in 2 minutes

RAG, or retrieval-augmented generation, means the system searches your documents for the right text and gives that text to the model along with the question. Before it can search, it has to cut the documents into pieces. Those pieces are called chunks. Each chunk is indexed on its own, so each one is found or missed on its own. That makes chunk size one of the first design choices.

Size cuts both ways. If chunks are too small, a piece can lose its subject. In a made-up leave policy, the line about grade 5 staff getting 25 days can end up away from the words that name the grade. If chunks are too big, one chunk covers leave, travel and expenses, so the search gets blurred, and the model has to read far more than it needs. Microsoft's guidance warns that oversized chunks are expensive and do not give the best results.

Overlap is one common way to soften a cut in the wrong place. Neighbouring chunks share some text, so a sentence cut at one edge can appear whole in the next chunk, if the overlap is long enough to carry it. Overlap costs storage and repeats text, so it is a trade-off as well.

There is no magic number. I would start from the document's structure, such as its sections and paragraphs, then test the size on real questions and measure whether the right text comes back. A new size can mean cutting and indexing everything again, so I would decide it early and test it often.

## What is chunking, in plain words?

A chunk is a short piece of a longer document, cut out so that a search can find it on its own. Think of a new hire reading a 300-page staff handbook. She does not memorise the whole book. She goes to the section she needs, such as leave or expenses, and reads that. Chunking gives an AI system the same kind of sections.

Picture an HR assistant built for a mid-size company on its 120-page leave and benefits handbook. An employee asks a question. The system searches the chunks, sends the best few to the model, and the model writes the answer from them. How the handbook was cut decides what the search can find.

- **Chunk:** A piece of a document that is indexed and retrieved as one unit.
- **Chunk size:** How much text each chunk holds, counted in tokens or words.
- **Overlap:** Text that two neighbouring chunks share, so a sentence cut at an edge can appear whole in one of them.
- **Retrieval:** The search step that finds the chunks most related to the question.

RAG stands for retrieval-augmented generation. Anthropic's September 2024 post on contextual retrieval describes it as a method that fetches information from a knowledge base and adds it to the prompt, so the model can answer from your documents.

## How does chunking fit into a RAG system?

Chunking happens before anyone asks a question. It runs when the documents go in, and again whenever those documents are changed or re-cut. Anthropic's September 2024 post on contextual retrieval describes the steps: break the knowledge base into smaller chunks of text, usually no more than a few hundred tokens, turn each chunk into an embedding (a list of numbers that stands for its meaning), store the embeddings where they can be searched by meaning, then add the most relevant chunks to the prompt.

*Diagram, From handbook to answer: Chunking happens when the handbook goes in. Each question then searches the saved chunks, and only the best few reach the model.*
1. The handbook is cut into chunks.
2. Each chunk is saved so it can be searched.
3. The question finds the closest chunks.
4. Those chunks go to the model with the question.

## Why does chunk size change the answer?

Too small is the first failure. Microsoft warns that chunks which are too small and do not hold enough context can lead to poor answers. Anthropic makes a similar point: when individual chunks lack sufficient context, it can lead to problems.

- **Too small: The rule loses its subject.** A cut can split the grade from the days. Then no single chunk holds the rule.
- **Too big: The rule drowns.** One chunk covers leave, travel and expenses. The model reads far more than it needs.
- **Right size: The rule stays whole.** A section with its heading holds the rule, so the search can find it and the model reads just that.

Too big is the second failure. A chunk that covers several topics has to carry all of them in one meaning, so a search can match it for the wrong questions. It also fills the prompt. Microsoft says oversized chunks are expensive, may overwhelm a model's token limits, and do not produce the best results.

Here is a small demo of the first failure. It cuts a made-up leave policy into chunks of words, so you can see where the cuts land. Real chunks are bigger and are counted in tokens.

An HR assistant gets this question: How many leave days do grade 5 staff get?

```python
# A made-up leave policy, cut into chunks of words (a simplified pipeline that counts words).
POLICY = (
    "Annual leave. Staff in grades 1 to 4 get 20 days a year. "
    "Grades 5 and above get 25 days a year. "
    "Unused leave can carry over for three months. "
    "Travel claims. Submit receipts within 30 days of the trip."
)
words = POLICY.split()

def chunks(size, overlap):
    step = size - overlap
    return [" ".join(words[i:i + size]) for i in range(0, len(words), step)]

for size in (6, 12):
    parts = chunks(size, overlap=2)
    print(f"size {size} words, overlap 2: {len(parts)} chunks")
    for n, text in enumerate(parts, 1):
        print(f"  {n}. {text}")
    rule_in_one = any("Grades 5" in p and "25 days" in p for p in parts)
    print(f"  one chunk holds both 'Grades 5' and '25 days': {rule_in_one}")
print(f"total words in policy: {len(words)}")
```

Output:

```text
size 6 words, overlap 2: 10 chunks
  1. Annual leave. Staff in grades 1
  2. grades 1 to 4 get 20
  3. get 20 days a year. Grades
  4. year. Grades 5 and above get
  5. above get 25 days a year.
  6. a year. Unused leave can carry
  7. can carry over for three months.
  8. three months. Travel claims. Submit receipts
  9. Submit receipts within 30 days of
  10. days of the trip.
  one chunk holds both 'Grades 5' and '25 days': False
size 12 words, overlap 2: 4 chunks
  1. Annual leave. Staff in grades 1 to 4 get 20 days a
  2. days a year. Grades 5 and above get 25 days a year.
  3. a year. Unused leave can carry over for three months. Travel claims.
  4. Travel claims. Submit receipts within 30 days of the trip.
  one chunk holds both 'Grades 5' and '25 days': True
total words in policy: 40
```

The 40-word policy becomes 10 chunks at 6 words and 4 chunks at 12 words. At 6 words, no chunk holds both the grade and the number of days, even with a 2-word overlap. At 12 words, one chunk does. At real sizes the trade-off is the same: the cut has to keep the rule whole.

*Diagram, Too small or too big, same question: The same question can fail two ways. A chunk that is too small drops the grade, so the model may guess or miss the rule. A chunk that is too big hides the rule among other topics.*
1. With no grade in the chunk, the model may guess.
2. The whole mixed chunk is read, and the one rule can get lost in it.

## How do you choose a size and overlap?

There is no single right size. Microsoft calls the chunking approach a semipermanent choice. Changing the strategy can significantly affect downstream processes.

> "Your chunking approach is a semipermanent choice in your overall solution design." (Microsoft)
>
> "The choice of chunk size, chunk boundary, and chunk overlap can affect retrieval performance" (Anthropic)

Fixed-size chunking is the low-effort method. Microsoft describes it as breaking a document into chunks based on a fixed number of characters or tokens, with overlap between them, and rates its effort and cost as low. Because the cut follows a count, not the document, you must choose the fixed size of the chunks and the amount of overlap with care.

OpenAI's retrieval guide says that when you add a file to a vector store, the file is automatically chunked, embedded and indexed. Its vector stores serve as indices for your data. By default the chunks are 800 tokens with 400 tokens of overlap. That default belongs to its own tool, and other systems can choose other sizes.

1. **Split on structure first:** Cut on headings, sections and paragraphs, so a rule stays with its title. Use a fixed size only where the structure runs out.
2. **Pick a size and an overlap:** Start from the document's shape, then try a few sizes. Overlap can keep a sentence cut at one edge whole in a neighbouring chunk, if the overlap is long enough.
3. **Measure on real questions:** Collect real questions from the people who will use the bot, mark the passage that answers each one, and check whether it comes back in the top results.
4. **Re-test after every change:** A new size can mean cutting and indexing again. Run the same questions each time, so you can see what got better and what got worse.

> **Tip:** Asked how to choose the size? Don't open with a number. Say you would start from the document's structure, then test on real questions and measure what comes back.

### How would you fix a bot that gives the wrong number?

A bank's fee assistant tells a customer that the late fee on a business card is 25 dollars. The fee schedule says 35. The bot is wrong, and the customer may act on it.

I would not start by changing the model. I would look at the chunks the search returned for that question first, because the answer can only be as good as the text it was given.

1. **Print the chunks it received:** Read the exact text the model saw for that question, before you change anything.
2. **Check where the cut fell:** If the fee name is in one chunk and its amount is in the next, the cut is the cause.
3. **Cut by structure:** Keep each fee row with its heading and table header, so one chunk holds the whole rule.
4. **Add the case to the test set:** Re-run the search test on that question and the others, so the fix is measured and the old failure stays covered.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: cutting documents into pieces that a search can return on their own.
- [ ] Why size matters: too small loses context, too big blurs the meaning and fills the prompt.
- [ ] Overlap, and why it is a trade-off in storage and repeated text.
- [ ] No universal size: start from the structure, then test on real questions.
- [ ] The cost of changing it: the chunks may need cutting and indexing again.
- [ ] A measured result when asked how you know it works.

**Common traps**

- Trap: "Bigger chunks always give better answers." Better: Bigger chunks hold more context, but they also blur the search and fill the prompt. The right size is a measured trade-off.
- Trap: "Use the default size and you are done." Better: A default is a starting point. Choose the size from the document's structure, then measure it on real questions.
- Trap: "Chunking is a detail, not a design choice." Better: It decides what the search can ever find, and a later change can mean re-indexing everything.

## Can you spot the problem?

**Spot the problem:** A customer asks the bot for the late fee on a business card. Which of the four chunks is most likely to make the bot quote the wrong amount?

A. Card fees are listed in the schedule. Each fee has a code, a name and an amount.
B. Section 4.2, business card fees: late payment fee.
C. Foreign transaction fee is 2.5 percent of the amount in the currency you spend.
D. For any fee question, contact the support team through the app.

**Answer:** B. This chunk ends on the fee's name, and the amount sits in the next chunk. The model may guess the amount. Keep each fee row with its heading, then test the fix on the late-fee question.

**Quick check:** Your search finds the leave page, but the grade 5 rule is missing from the answer. The chunk ends just before that rule. Which fix is most likely to help?

A. Use a bigger model
B. Lower the temperature (how random the wording is)
C. Cut by headings, so each rule stays with its title
D. Let the model answer from memory and drop the handbook

**Answer:** C. The cut is the cause, so the fix belongs in the chunking. A bigger model or a lower temperature cannot show text that was never in the chunk.

## Can you answer these from memory?

**Flash cards**

- **What is chunking?** Cutting documents into pieces that a search can find and return on their own.
- **Why can small chunks fail?** They can lose the context a rule needs, like its grade or its subject.
- **Why can big chunks fail?** They blur the search and fill the prompt with text the model does not need.
- **Is there one right size?** No. Start from the document's structure, then test on real questions.
- **What does overlap do?** Neighbouring chunks share text, so a cut sentence can appear whole in one of them.
- **What happens when you change the size?** The chunks may need cutting and indexing again, so decide early and measure.

## Likely follow-up questions

- Q114 Fixed vs recursive vs semantic chunking? https://designervenkat.online/interview/ai/fixed-vs-recursive-vs-semantic-chunking
- Q115 What is chunk overlap? https://designervenkat.online/interview/ai/what-is-chunk-overlap
- Q116 How do you choose an embedding model? https://designervenkat.online/interview/ai/how-do-you-choose-an-embedding-model
- Q117 What is a vector database? https://designervenkat.online/interview/ai/what-is-a-vector-database
- Q141 What is contextual retrieval? (full answer coming)
- Q146 How do you pick top-k? https://designervenkat.online/interview/ai/how-do-you-pick-top-k

## Learn it in depth

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