download

A RAG answer is wrong. Was it retrieval or generation?

System design~12 minReviewed 1 Nov 2026Free · No sign-in

Question

A food delivery app's support bot retrieves the top 3 chunks from the help center for each question. Then an LLM writes the answer from them.

A user asks how long they have to report a missing item. The bot says 7 days. The help center says 48 hours.

The team keeps a golden set: real questions, each labelled with the chunk that holds the answer. Here are 6 of them:

questionanswer is intop 3 retrievedanswer right?
refundrefund-2refund-1, refund-2, fees-1yes
missing itemmissing-1refund-1, late-3, fees-2no
late orderlate-2late-2, late-1, refund-1no
tiptips-1tips-1, fees-1, fees-2yes
cancelcancel-1fees-3, late-1, refund-3yes
allergensfood-4food-1, food-4, food-2yes

For each wrong answer, which stage failed? What would you measure for each stage? What is odd about cancel?

Show hints (3)
  1. "TWO QUESTIONS"

    For each question: did the chunk with the answer reach the model? If it did, does the answer say what that chunk says?

  2. "COUNT THE HITS"

    Recall@3 is the share of questions whose answer chunk made the top 3. Count them.

  3. "THE LUCKY ONE"

    For cancel, the answer chunk was not retrieved, yet the answer is right. Where did the model get it, and will that still work next month?

Show checked explanation

Check the stages in order. If the chunk with the answer is not in the top 3, retrieval failed: missing item and cancel. If it is there but the answer is wrong, generation failed: late order. Track retrieval recall@3, here 4/6, and whether answers stick to the retrieved chunks. cancel is right by luck.

"SOLUTION · PYTHON"
golden = [  # (question, chunk with the answer, top 3 retrieved, answer right?)
    ("refund", "refund-2", ["refund-1", "refund-2", "fees-1"], True),
    ("missing item", "missing-1", ["refund-1", "late-3", "fees-2"], False),
    ("late order", "late-2", ["late-2", "late-1", "refund-1"], False),
    ("tip", "tips-1", ["tips-1", "fees-1", "fees-2"], True),
    ("cancel", "cancel-1", ["fees-3", "late-1", "refund-3"], True),
    ("allergens", "food-4", ["food-1", "food-4", "food-2"], True),
]
hits = right = 0
for question, chunk, top3, ok in golden:
    hits += chunk in top3
    right += ok
    if chunk not in top3:
        print(f"{question}: retrieval miss" + (" (lucky guess)" if ok else ""))
    elif not ok:
        print(f"{question}: generation miss")
print(f"recall@3: {hits}/{len(golden)}, answers right: {right}/{len(golden)}")
"OUTPUT"
missing item: retrieval miss
late order: generation miss
cancel: retrieval miss (lucky guess)
recall@3: 4/6, answers right: 4/6

Code run on CPython 3.12 against the example above. Checked by an editor other than the author.

Walkthrough

A RAG answer goes through two stages, and each can fail. Check them in order.

1. Did the right chunk reach the model? If not, retrieval failed. The model never saw the fact, so no prompt can fix it. The share of questions whose answer chunk is in the top k is recall@k.

2. Does the answer say what the chunks say? If the chunk was there and the answer is still wrong, generation failed. The model ignored it, mixed it up with another chunk, or guessed. An answer that the retrieved chunks fully support is called faithful, or grounded.

questionchunk in top 3?answer right?stage to fix
refundyesyesnone
missing itemnonoretrieval
late orderyesnogeneration
tipyesyesnone
cancelnoyesretrieval
allergensyesyesnone

Recall@3 is 4/6 and 4 of 6 answers are right, but they don't fail on the same questions. missing item never got its chunk, so its 7 days came from the wrong place. late order had its chunk in first place and still went wrong.

cancel is the trap. The answer is right, but its chunk was not retrieved. The model answered from its training data, or guessed. When the cancel policy changes, the bot will keep giving the old rule.

Each stage has its own fixes:

  • Retrieval: check how the docs are chunked, add keyword search next to vectors, rewrite the query, retrieve more and rerank.
  • Generation: tell the model to answer only from the chunks and to say when they don't cover the question. Ask it to cite the chunk it used, and check the citation.

Common mistakes

  • Scoring only the final answers. cancel passes, so you miss a retrieval bug that shows up when the policy changes.
  • Rewriting the prompt while retrieval recall is low. The model can't use a chunk it never saw.
  • Labelling the golden set with chunk ids only. Re-chunking the docs changes the ids. Store the document and the answer text too.
  • Inventing the golden set questions. Real users phrase things differently. Take questions from logs, including failed ones.

Follow-up questions

  • "In production you have no labels. How do you watch quality?" Sample live answers daily. An LLM judge checks that each claim is supported by the retrieved chunks. Send low scores and a random sample to humans. Watch thumbs-down and hand-offs to human agents. Add each real failure, labelled, to the golden set.
  • "Recall@3 is high, but answers are still wrong. Where do you look?" At generation, with the chunks the model saw. Two chunks may disagree, like an old and a new policy. The right chunk may be buried among weak ones, or the prompt lets the model use its own knowledge. Remove outdated docs, send fewer, better chunks, and require citations.

What a strong answer covers

Checks retrieval first, then generation. Measures recall@k on a labelled golden set, apart from faithfulness. Sees a right answer with no supporting chunk as a hidden retrieval bug. Fixes each stage its own way.

Open in interactive practice deck →

Original OfferVibe question. Topic idea from System Design with AI Interview Guide (Rohit Bhardwaj, 2026); text, examples and code are our own.
© 2026 OfferVibe · Text CC BY-NC-SA 4.0 · code MITFree to share and adapt with credit, not for commercial use. Code samples are free for any use.