Evaluate RAG answer quality
Mental model: evaluate retrieval before generation. A fluent generator cannot ground an answer in evidence it never received.
Mechanism: fixture → component scores → root-cause experiment
Use this playbook when a RAG prototype produces plausible answers and needs a disciplined quality check before deeper tuning or release.
Inputs
- A representative set of user questions.
- Retrieved chunks for each question.
- Generated answers, citations, latency, token counts, and model version.
- Expected answer or grading rubric for each question.
Procedure
- Pick 20-50 questions from real usage or realistic workflows.
- Mark the source documents or chunks that should support each answer.
- Run the current system and log query, retrieved chunks, answer, citations, latency, and cost.
- Score retrieval first: needed evidence present, ranking quality, and context noise.
- Score generation second: answer relevance, groundedness, citation support, and refusal behavior.
- Label each failure as missing evidence, wrong evidence, bad synthesis, weak citation, unsafe answer, or product mismatch.
- Group failures by root cause and choose one system change to test next.
- Add recurring failures to the regression suite.
Output
| Artifact | Contents |
|---|---|
| Eval summary | pass rate, top failure clusters, cost, latency |
| Failure table | question, retrieved context, answer, label, owner |
| Next experiment | one retrieval, prompt, chunking, reranking, or UI change |
Pitfall
Do not tune the prompt before checking retrieval. If the right evidence is missing from the context, the generator is being asked to solve the wrong problem.
Connects to: evaluating RAG systems · retriever vs generator eval · grounding and citations
Executable failure label
retrieved, supports_claim = False, False
print("retrieval failure" if not retrieved else "synthesis failure" if not supports_claim else "pass")
Run with python3; expected output is retrieval failure. Require evidence presence, citation support, answer quality, latency, and cost before promoting a change.