Testing AI Features: Evals, RAG & Hallucinations · Lesson 3 of 6 · Bonus module

Testing RAG: Retrieval vs Generation

RAG feeds the model documents, then asks it to answer from them. It fails in two completely different places — and calling both "the AI is wrong" is the mistake that gets bugs mis-assigned for weeks.

By Shahriyar · Updated

Two stages, two bugs

Same visible symptom — a wrong answer — opposite fixes. Every RAG test must say which stage failed, or the bug goes to the wrong team.

Score them separately

▸ The two-question test
chunks = retrieve(question)
answer = generate(question, chunks)

# stage 1 — retrieval
assert known_answer_doc in chunks        # was the answer even available?

# stage 2 — generation, given those chunks
assert judge(answer, chunks,
  "every claim is supported by the chunks, nothing invented")

Grounded in published RAG evaluation practice (retrieval and faithfulness metrics)

All lessons in Testing AI Features: Evals, RAG & Hallucinations

  1. You Can't assertEqual an LLM
  2. Golden Sets and Offline Evals
  3. Testing RAG: Retrieval vs Generation
  4. Measuring Hallucination
  5. Adversarial Testing: Jailbreaks and Injection
  6. Guardrails, CI, and the Interview Answer