esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

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.

13 min readBeginnerVery common · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

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.

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.

Key words

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.

From handbook to answer

Leave handbook

120 pages, one long file

Chunker

cuts it into pieces, by size or heading

Chunk index

each piece saved for search

Search

finds the best few pieces

Model

writes the answer from them

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

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

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.

Too small or too big, same question

Chunks too small

Chunk 14

gives the days, not the grade

Chunks too big

Chunk 3, whole chapter

leave, travel and expenses

Model guesses

may give the wrong number

Rule buried

the model reads far more text

  1. 1With no grade in the chunk, the model may guess.
  2. 2The whole mixed chunk is read, and the one rule can get lost in it.
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.

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. 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. 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. 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. 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. 1

    Print the chunks it received

    Read the exact text the model saw for that question, before you change anything.

  2. 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. 3

    Cut by structure

    Keep each fee row with its heading and table header, so one chunk holds the whole rule.

  4. 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."

    BetterBigger 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."

    BetterA 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."

    BetterIt 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?

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?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q114Fixed vs recursive vs semantic chunking?12 min
  2. Q115What is chunk overlap?10 min
  3. Q116How do you choose an embedding model?12 min
  4. Q117What is a vector database?12 min
  5. Q141What is contextual retrieval?Coming soon
  6. Q146How do you pick top-k?11 min

Learn it in depth

Last updated on 26 November 2026

Building a bot on your own documents?

I design and build AI products and agents, including the search behind them. Book a short call and say what your documents look like and what the bot must answer.