Sub topic 3
Building an Evaluation Set with Relevance Labels
This chapter assumes you know how a RAG pipeline works (chunking, embedding, vector search, prompting an LLM), can read Python, and know precision and recall from classification. Every retrieval metric in the next chapters needs a set of questions with known right answers. Here you build that set.
What an evaluation set contains
An evaluation set is a list of test questions, each paired with the labels you score against. A useful record has these fields:
- A question, written the way real users write.
- The relevant document or chunk IDs, which are the passages that contain the information needed to answer.
- Optionally, a graded relevance score for each passage (for example 0 to 3), which nDCG needs later.
- Optionally, a reference answer, which lets you check correctness as well as faithfulness.
eval_set = [
{
"id": "q001",
"question": "How long does the warranty last?",
"relevant": {"warranty#c2": 3, "returns#c5": 1},
"reference_answer": "The warranty lasts 24 months.",
},
{
"id": "q002",
"question": "Does the warranty cover water damage?",
"relevant": {"warranty#c3": 3},
"reference_answer": "No. Only manufacturing defects are covered.",
},
]
for item in eval_set:
print(item["id"], len(item["relevant"]), "labelled passages")Label chunk IDs that stay stable. If you re-chunk your corpus, the labels point at nothing. Many teams label at the document or section level and map chunks to those parents, so labels survive chunking changes.
Where the questions come from
Use a mix of sources, in this order of preference:
- Real queries. Sample from search logs or support tickets. They show the true wording and the true spread of topics.
- Expert-written questions. Ask domain staff for the hard cases that logs may not yet contain.
- LLM-generated questions. Give a model a passage and ask for questions it answers. This is fast, and the passage is the relevant label by construction. The questions tend to copy the passage's wording, so they are easier than real ones. Treat them as a supplement.
Include questions the corpus cannot answer. A good system should say it does not know, and you cannot test that without such cases. Those records have an empty relevant set, so recall is undefined for them. Report them separately.
Labelling the passages
You cannot read the whole corpus for every question. A common method is pooling. Run several retrievers (dense, keyword, hybrid) and collect the union of their top results. A person then labels only that pool. Passages outside the pool count as not relevant.
Pooling has a known bias. If you label only what your current retriever finds, a future retriever that finds a good unlabelled passage is penalised for it. Add new pooled results to the labels when you change the retriever.
Write a short labelling guide with examples of each grade. For instance, 3 means the passage answers the question fully, 2 means it answers part, 1 means it is related background, and 0 means it is unrelated. Have two people label a sample, then check how often they agree. Low agreement usually means the guide is vague, not that the labellers are careless.
Common errors
- Too few questions. Fifty questions give wide uncertainty. Later chapters show how to measure that. Start with 100 to 200 and grow it.
- Tuning on the test set. Split the data. Use the development set to adjust the system and the held-out set for final checks.
- Narrow coverage. If all questions are short factual lookups, you will miss failures on multi-step or comparison questions. Tag each record by type so you can report per type.
- Silent label drift. When documents change, labels go stale. Record the corpus version with the set.
Exercise
A team labels relevant passages only from the top 5 results of their current dense retriever. They then add a keyword retriever and its recall@5 comes out lower. Give a likely cause and one fix.
Show answer
The labels are biased toward the dense retriever (pooling bias). The keyword retriever may return relevant passages that were never labelled, and they count as misses. Fix it by pooling the top results of both retrievers, labelling the new passages, and re-scoring.