Lesson 26.3 · 3 of 7 · 4 min read · Reviewed 24 Nov 2026
Building a RAG test set
By the end, you can
- Build a test set for a RAG system.
- Cover answerable, unanswerable and multi-hop questions.
What each case holds
{
"id": "rag-112",
"question": "Can I return sale shoes I've worn once?",
"relevant_chunks": ["pol-4.3", "pol-4.4"],
"reference": "No, unless they are faulty: sale items are final, and worn footwear is accepted only if faulty.",
"tags": ["multi-chunk", "policy"]
}
A balanced mix
| Type | Share | Example |
|---|---|---|
| Single fact | 40% | “What’s the refund window?” |
| Multi-chunk or multi-hop | 20% | “Who leads the team that owns billing?” |
| Comparison | 10% | “Plan A vs plan B storage limits” |
| Unanswerable | 15% | “What’s the CEO’s home address?” |
| Recently changed facts | 10% | “Refund window (updated last week)” |
| Exact terms and codes | 5% | “What does error E-4012 mean?” |
Sources of questions
- Real user questions from logs (redactedRedaction: Removing or masking sensitive data, such as PII or secrets, before it is stored, logged or sent.)
- Questions written by people who know the documents
- Model-generated questions from chunksChunking: Splitting documents into smaller passages before embedding and indexing them., reviewed by people (watch for questions that copy the chunk’s wording too closely, which makes retrieval look easier than it is)
Keep it fresh
When documents change, update affected references (chapter 17). Re-run retrieval and answer metrics on every change to chunking, embedding modelEmbedding model: A model trained to turn text (or images) into embeddings for search and comparison, rather than to generate text., index or prompts (chapter 20).
Key points
- A RAG test set needs questions, the passages that answer them, and reference answers or criteria.
- Include questions the documents can't answer, to test honest refusals.
- Tag by type (single fact, multi-hop, comparison, recent change) and report per tag.
Report a RAG test set per tag
Turn a flat list of graded test cases into a per-tag report that exposes weak spots and missing case types.
You will have: A script that prints accuracy per tag, the overall score, and any required tag with no cases.
Steps
- Read the graded cases: each has tags and a pass or fail.
- Count passes and totals per tag.
- Print each tag's accuracy, sorted from weakest to strongest.
- Check the set against the required tags and print any that are missing.
- Compare the overall score with the weakest tag and write one sentence on what to fix first.
Done when
- The report shows multi-hop as the weakest tag at 0.33.
- It warns that the unanswerable tag has no cases.
- The overall score prints and is higher than the weakest tag.
Open in the Playground No API key needed.
Starter code (Python)
RESULTS = [
{"id": "r1", "tags": ["single-fact"], "passed": True},
{"id": "r2", "tags": ["single-fact"], "passed": True},
{"id": "r3", "tags": ["single-fact"], "passed": True},
{"id": "r4", "tags": ["single-fact"], "passed": False},
{"id": "r5", "tags": ["multi-hop"], "passed": False},
{"id": "r6", "tags": ["multi-hop"], "passed": True},
{"id": "r7", "tags": ["multi-hop", "recent-change"], "passed": False},
{"id": "r8", "tags": ["comparison"], "passed": True},
{"id": "r9", "tags": ["recent-change"], "passed": True},
{"id": "r10", "tags": ["exact-code"], "passed": True},
]
REQUIRED = ["single-fact", "multi-hop", "comparison", "unanswerable", "recent-change", "exact-code"]
def per_tag(results):
# TODO: return {tag: (passed, total)}
return {}
overall = sum(r["passed"] for r in RESULTS) / len(RESULTS)
print(f"overall = {overall:.2f}")
for tag, (p, t) in sorted(per_tag(RESULTS).items()):
print(f"{tag:14} {p}/{t}")
# TODO: print required tags with no cases
Show a solution
RESULTS = [
{"id": "r1", "tags": ["single-fact"], "passed": True},
{"id": "r2", "tags": ["single-fact"], "passed": True},
{"id": "r3", "tags": ["single-fact"], "passed": True},
{"id": "r4", "tags": ["single-fact"], "passed": False},
{"id": "r5", "tags": ["multi-hop"], "passed": False},
{"id": "r6", "tags": ["multi-hop"], "passed": True},
{"id": "r7", "tags": ["multi-hop", "recent-change"], "passed": False},
{"id": "r8", "tags": ["comparison"], "passed": True},
{"id": "r9", "tags": ["recent-change"], "passed": True},
{"id": "r10", "tags": ["exact-code"], "passed": True},
]
REQUIRED = ["single-fact", "multi-hop", "comparison", "unanswerable", "recent-change", "exact-code"]
def per_tag(results):
out = {}
for r in results:
for t in r["tags"]:
p, n = out.get(t, (0, 0))
out[t] = (p + r["passed"], n + 1)
return out
overall = sum(r["passed"] for r in RESULTS) / len(RESULTS)
print(f"overall = {overall:.2f}")
tags = per_tag(RESULTS)
for tag, (p, t) in sorted(tags.items(), key=lambda kv: kv[1][0] / kv[1][1]):
print(f"{tag:14} {p}/{t} = {p / t:.2f}")
missing = [t for t in REQUIRED if t not in tags]
for t in missing:
print(f"WARNING: no cases tagged {t}")
weakest = min(tags, key=lambda t: tags[t][0] / tags[t][1])
print(f"Fix first: {weakest}, and add {', '.join(missing)} cases.")