Checking a RAG system: did it find the right chunk, is the answer grounded
RAG & Vector Search · 10 questions
Short notes
Key idea
Check a RAG system in two halves. Retrieval: did the right chunk come back? Generation: is the answer correct and supported by the retrieved text (grounded)? Most failures are retrieval failures.
Syntax
- Test set: real questions, each with the chunk(s) that contain the answer and a reference answer.
- Hit rate @k: share of questions whose correct chunk is in the top k.
- MRR: average of 1 / (rank of the first correct chunk).
- Groundedness: every claim in the answer appears in the context (checked by a person or a judge model).
- Answer correctness: compared with the reference.
hit_at_5 = sum(gold in [h.id for h in search(q, 5)] for q, gold in tests) / len(tests)
Example
50 test questions: hit rate @5 = 72%. The misses are all about product codes. Adding keyword search lifts it to 92% before touching the prompt.
Traps
- Judging only final answers hides whether retrieval or generation broke.
- Test questions written from the chunks are too easy; use real user wording.
- A correct answer that isn't grounded came from the model's memory; it may be wrong next time.
- Re-run the set after every change.
Want the full lesson with step-by-step examples, a project and a certificate? RAG & Vector Search course, ₹180 →
- Question 1easy
The right chunk was in the prompt, but the answer contradicts it. Which part failed?
- Question 2medium
Which test question best checks a help-centre RAG system?
- Question 3medium
The right chunk was ranked 1st, 2nd, 4th and not found for four questions. What does this print?
ranks = [1, 2, 4, None] print(sum(1 / r if r else 0 for r in ranks) / len(ranks))
- Question 4hard
Using
goldandresultsfrom below, store the MRR over the top 3 (0 when the right chunk isn't in the top 3) inresult, rounded to 3 decimals.Store your answer in
result. - Question 5medium
You change the chunk size and the embedding model at the same time, and hit@3 rises. What's the problem?
Checking a RAG system: did it find the right chunk, is the answer grounded
Checking a RAG system: did it find the right chunk, is the answer grounded
Checking a RAG system: did it find the right chunk, is the answer grounded
Checking a RAG system: did it find the right chunk, is the answer grounded
Checking a RAG system: did it find the right chunk, is the answer grounded
5 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.