Evaluation
When RAG fails, separate missed retrieval from retrieved-then-invented. This chapter uses classroom checks: hit@k, a faithfulness heuristic, and “answer only from context.” These are not paper metrics and they do not replace spot-checking.
Write 20–50 Q&A pairs that depend on made-up facts in your corpus (order KH-8842, a “7 day” deadline). Trivia the web already knows cannot test retrieval.
Retrieval: hit@k
Label each question with the chunk id(s) that must appear. After retrieval, see whether the gold id is in the top k.
Low hit@k: fix chunking, the embedding model, k, and filters before swapping a larger chat model. High hit@k but angry users: the generation side.
Recall@k (multiple gold chunks) uses the same lists; hit@k is enough in class.
Faithfulness
Faithfulness asks: can each claim in the answer be supported by the context? It is not “does this sound helpful?” Two classroom layers:
1. Number / code scan (no model)
Every number and order id in the answer must appear in context. Invented 8 days or KH-0001 fail.
This will not catch “7 days” paraphrased as “a week,” but it catches the usual hallucinated digits.
2. Short judge prompt (optional, any LLM)
Do not score “was this useful.” Useful-but-unfaithful is still an incident for support bots.
“Answer only from context”
This is both a prompt rule and a test suite:
Put expect_unknown=True items in the regression set. Models love to “help” there.
Suggested loop
- Freeze chunking and the embedding model; measure hit@4.
- Read 10 full answers by hand (including should-refuse items).
- Run the token scan on every answer.
- Then touch rerank or hybrid search—one knob per change.
LangSmith, LlamaIndex evaluators, and Dify retrieval tests productize the same idea: LangChain RAG, LlamaIndex, Dify Knowledge Base. This course does not bind you to any of them.