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.

How Do You Debug a RAG Bot That Missed It?

How to find the stage where a RAG bot lost a true answer: the index, the search, the prompt or the model, explained simply for your AI interview.

In short

Don't guess at a fix. Trace the one question that failed, stage by stage: is the text in the index, did search return it near the top, did it reach the prompt, and did the model use it? Fix the first stage that broke, then keep the question as a test.

12 min readIntermediateVery 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.

When a bot misses an answer that is in the docs, I don't rewrite the prompt yet. I take that one question and trace it. First, is the right text in the index? Second, does search return it near the top? Third, does it reach the prompt? Fourth, does the model use it? The first stage that fails gets the fix, and the question becomes a test so it can't slip back in.

What is debugging a RAG bot, in plain words?

RAG stands for retrieval-augmented generation. Anthropic describes it this way: "RAG is a method that retrieves relevant information from a knowledge base and appends it to the user's prompt." The bot searches your documents first, then the language model writes the answer from what search found. The bot does not keep your documents in memory. It only sees what search hands it for each question.

Picture a new claims clerk asked for one clause in a policy. The clause sits in a box in the back room that she never opened, so she says it isn't there. She didn't misread anything. She never got the box. A miss in a bot often works the same way: the right text never reached the model.

Our example is an HR policy bot for a 3,000-person logistics firm, built over its staff handbook. Debugging means finding which step lost the text: the index, the search, the prompt, or the model's reading of it.

Key words

Chunk
A short piece of a document, stored and searched as one unit.
Index
The store that holds every chunk together with its meaning code, called an embedding.
Top-k
How many search results go on to the model, for example the top 3.
Prompt
Everything the model reads before it writes one answer, including the chunks.

How do you trace one missed answer?

Start with one real question that failed, and work out which chunk holds the right answer. Then walk the path below from left to right, and stop at the first stage that broke.

Trace one missed answer, stage by stage

Wrong answer

the docs held the right answer

Search

Chunk in the index

if not, reading or cutting lost it

In the top results?

run search alone, with no model

Prompt and answer

Chunk in the prompt?

print the exact prompt sent

Answer uses it?

compare the answer with the source

Fix that stage

then add a test for this question

  1. 1Start with the wrong answer and find the chunk that held the fact.
  2. 2If that chunk is stored, check whether search ranks it near the top.
  3. 3Only the top few results go on, so check what reached the prompt.
  4. 4If it reached the prompt, check whether the answer used it.
  5. 5The first stage that broke gets the fix, then a test.
Read the path left to right and stop at the first stage that broke. Often the right chunk never reached the top results, or was cut before the prompt. Fix that stage, then keep the question as a test.
  1. 1

    Check the index

    Search the stored text for a sentence from the right passage. If it is missing, the step that read the file or cut it into chunks lost it, so look there first.

  2. 2

    Run search alone

    Ask the search your exact question, with no model. Note the rank of the right chunk. Outside the top few, the bot never had a chance to use it.

  3. 3

    Print the prompt

    Log the exact text the model received for that question. If the chunk is missing there, a cut-off or a filter dropped it.

  4. 4

    Check the answer against the source

    If the chunk was in the prompt and the answer still went wrong, the model read it badly. Check whether another chunk contradicted it.

Here is the worked case. An employee asks, "How many weeks of paid parental leave do UK staff get?" The bot says 12 weeks. The 2026 handbook says 26 weeks, in a table under section 14. The 2024 handbook also says 12 and is still in the index, so both versions are there. The numbers are made up for this example.

Search alone shows the fault. The old 2024 chunk ranks first, the right table ranks fourth, and the bot sends only the top three to the model. So the model never had the 26 weeks to read.

Python
# A made-up search result for one question. Did the right chunk make the top 3?
QUESTION = "How many weeks of paid parental leave do UK staff get?"
RIGHT = "handbook-2026-14b"
RESULTS = [
    ("handbook-2024-09a", 0.83),
    ("handbook-2026-12c", 0.81),
    ("handbook-2026-03a", 0.78),
    ("handbook-2026-14b", 0.74),
    ("handbook-2026-14a", 0.70),
]
TOP_K = 3

def trace(question, results, right, k):
    print("Question:", question)
    ids = [chunk for chunk, _ in results]
    rank = ids.index(right) + 1 if right in ids else None
    print("Right chunk rank:", rank)
    for chunk, score in results[:k]:
        old = " (2024, old)" if "2024" in chunk else ""
        print(f"  {score:.2f} {chunk}{old}")
    if rank is None or rank > k:
        print("Verdict: not sent to the model, so it never saw the answer")

trace(QUESTION, RESULTS, RIGHT, TOP_K)

Output

Question: How many weeks of paid parental leave do UK staff get?
Right chunk rank: 4
  0.83 handbook-2024-09a (2024, old)
  0.81 handbook-2026-12c
  0.78 handbook-2026-03a
Verdict: not sent to the model, so it never saw the answer

Read the trace before you touch the prompt. The scores are made up. The habit is real: look at the ranks and what was sent first.

What usually causes a miss, and how is it fixed?

Misses can come from a few common causes, and each one has a fix at the stage where it starts. Chunking alone can change the result. Anthropic notes that "the choice of chunk size, chunk boundary, and chunk overlap can affect retrieval performance."

Three common causes, each with a fix

The cause

Table split in two

the number is cut from its heading

Exact code missed

meaning search skips the policy ID

Old version ranks higher

the 2024 handbook wins the search

The fix

Keep tables whole

keep each table in one chunk

Add keyword search

exact codes and IDs are matched

Filter by version

only the current handbook is searched

  1. 1A table cut in two loses its heading, so the number has no context. Keep each table in one chunk.
  2. 2Meaning search can skip an exact code. Keyword search matches the text, and the two lists are merged.
  3. 3An old handbook competes on equal terms. A version filter keeps it out of the search.
Three common causes in a document bot, each shown next to the fix that targets it. Read each arrow as one pair of cause and fix. Fix the cause where it starts, then measure again.
  • Meaning only

    Misses exact codes

    A policy ID like HR-PL-26 means little to a meaning search, so it can rank low.

  • With keyword search

    Finds the exact code

    A keyword index finds the exact text, and its results are merged with the meaning results.

  • “While embedding models excel at capturing semantic relationships, they can miss crucial exact matches.”

    Anthropic, on contextual retrieval

  • “significantly degrades when models must access relevant information in the middle of long contexts”

    The Lost in the Middle paper, 2023

The second card is about the prompt. When many chunks go in, the right one can sit in the middle, where models use it less well. Put the strongest chunks first, and keep the count small enough that the right one is easy to find.

Query wording matters too. OpenAI's file search can rewrite a question before it searches: "Certain query styles yield better results, so we've provided a setting to automatically rewrite your queries for optimal performance."

Old versions are a separate cause. A search over two handbooks has no reason to prefer the new one, unless you filter by version or effective date. Then the old text never competes.

Tip

Check the rank before you raise the number of chunks. A bigger top-k can help, but it also gives the model more text to read, and the right answer can still get lost in it.

How do you stop the same miss coming back?

Turn the failed question into a test. Keep a set of real questions, each with the chunk that must win. Run the set after every change to the chunker, the embedding model, the filters or the prompt.

Test search and answers apart. A search test asks whether the right chunk reached the top few. An answer test gives the model the right chunk and asks whether it answered correctly. A failing search test points at search. A failing answer test points at the prompt or the model.

Anthropic reported in September 2024 that its contextual retrieval method "can reduce the number of failed retrievals by 49% and, when combined with reranking, by 67%." Those are one company's numbers on its own data, so measure your own.

Barnett and his co-authors put it bluntly: "validation of a RAG system is only feasible during operation." So real questions from users belong in the test set too, and every new miss from live use should be added.

Tip

Run the evals after every fix, even a small one, and keep the whole set.

What does the interviewer want to hear?

A strong answer covers

  • A method, not a guess: trace one failed question.
  • The stages in order: index, search rank, prompt, model.
  • Rank and prompt checks before touching the model.
  • Version and date filters for old documents.
  • A regression test set, split into search tests and answer tests.
  • Honest limits: some misses need the documents fixed, not the bot.

Common traps

  • Trap"Make the prompt stricter."

    BetterA stricter prompt can't fix a chunk the model never saw. Check the stages first.

  • Trap"Switch to a bigger model."

    BetterA bigger model reads the same missing text. Find out which stage lost it.

  • Trap"The embeddings are bad, so we need a new database."

    BetterOften the chunk was cut or filtered out. Check the stage before you replace anything.

Can you spot where the miss happened?

Spot the stage

The fee bot says £25. The 2026 table says £30. Which trace line shows where it went wrong?

Quick check

The right chunk ranks 9th of 50 results, and the bot sends only the top 5 to the model. What is the first change to try?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q131Retrieval metrics: recall@k, MRR, nDCG?12 min
  2. Q133What are common RAG failure modes?11 min
  3. Q126Rerankers: cross-encoder vs bi-encoder?12 min
  4. Q129What is metadata filtering?10 min
  5. Q132Generation metrics: faithfulness, answer relevance?10 min
  6. Q152How do you handle conflicting sources?Coming soon

Learn it in depth

Last updated on 26 November 2026

Building a bot over your own documents?

I design and build AI assistants that answer from company documents, with the search, the checks and the tests in place. Book a short call and tell me what your bot needs to answer.