ContentsRAG from Scratch to TRECAdisak Sukul · Iowa State University

Start here

Part 1 · Foundations

Part 2 · Finding the evidence

Part 3 · Writing the answer

Part 4 · Judging RAG

Part 5 · TREC and the 2026 tracks

Part 6 · Case studies: our submissions

Part 7 · Beyond text: video

Part 8 · Streams and advanced RAG

Back matter

Part 1 · Foundations · Chapter 4

How we know a system is good

In one sentence: we turn “is it good?” into numbers by comparing what a system returned with what people judged relevant, and we compare systems on the same questions, against the middle of the field, with a check that the difference is not luck.

Why you should care

Every result in this book is a number with a name: set precision, recall, nDCG, nugget gain. If you do not know what a number rewards, you cannot tell good news from bad. One of our own results looks bad on one measure and good on another, and both are true.

Words you need

Precision
Of the documents returned, the share that are relevant.
Recall
Of all the relevant documents that exist, the share that were returned.
Set measure
A measure that looks only at which documents were returned, not at their order.
Ranked measure
A measure that gives more credit for relevant documents near the top.
Cutoff (“at k”)
Only the top k documents are scored, as in precision at 10.
nDCG
Normalized discounted cumulative gain. A ranked measure from 0 to 1 that also handles “very relevant” against “a little relevant”.
Track median
The middle score among all submitted runs. Half the runs are above it.
Paired comparison
Comparing two systems topic by topic on the same topics.

Core The idea

Precision and recall

You search for a topic. The system returns 10 documents. Judges say 4 of them are relevant. In the whole collection, 20 relevant documents exist.

precision = relevant returned / returned = 4 / 10 = 0.40
recall    = relevant returned / relevant that exist = 4 / 20 = 0.20

Precision asks: how much of what I got is useful? Recall asks: how much of what is useful did I get?

The two pull against each other. Return more documents and recall can only go up or stay the same, while precision usually falls. Return the whole collection and recall is perfect and precision is close to zero. So a recall number means little unless you also know how many documents were returned.

Order matters: ranked measures

Precision and recall, computed on the whole returned set, ignore order. A list with its four relevant documents at the top gets the same score as one with them at the bottom. A reader, or a language model, sees the top first. Ranked measures reward good order.

The most used one is nDCG. It works in three steps. Here is a list of four documents, with judged grades from 0 (not relevant) to 3 (very relevant):

RankGradeDiscount: divide by log2(rank + 1)Credit
131.0003.000
221.5851.262
302.0000.000
412.3220.431
DCG, the sum4.693
  1. Gain: each document earns its grade.
  2. Discount: the further down the list, the less the grade counts.
  3. Normalize: divide by the score of the best possible order of the same documents. Here the best order is 3, 2, 1, 0, which scores 4.762. So nDCG = 4.693 / 4.762 = 0.985.

An nDCG of 1 means the list is in the best possible order. This list lost a little because a grade-0 document sits above a grade-1 document.

One number is never enough

MeasureIt rewardsIt ignores
Set precisionReturning few off-target documentsOrder, and what you missed
Set recallFinding many of the relevant documentsOrder, and how much junk came along
nDCG at kPutting the best documents firstEverything below rank k
Nugget gainCovering the key facts at least onceRepeats, and how many documents it took

Compared with what? The median

A recall of 0.29 means nothing alone. Is that high? In a shared evaluation, organizers report the median for each measure: sort all runs by score and take the middle one. “Above the median” means better than half the field on that measure. Organizers often also give the best and the worst score.

The median is a fair first yardstick. It is not a ranking. Two runs just above and just below the median can be nearly the same.

Is the difference real?

System A scores 0.52 on average and system B scores 0.50. Is A better? Not yet. Some topics are easy and some are hard, and an average hides that. Compare the two systems topic by topic:

  • If A beats B on 41 of 50 topics, the difference is very unlikely to be luck.
  • If A beats B on 26 of 50, it is a coin flip, whatever the averages say.

Counting wins and losses this way is called a sign test. It is the simplest check there is, and you can do it by hand.

Watch and read

We have not yet found a short video on these measures that we would recommend. One will be added when we do.

How we did it at TREC 2026

The RAG retrieval task reported set measures, computed from automatic judgments. Here are our three different document sets against the field of 114 runs from 27 teams.

Document setDocuments per narrativeSet precisionSet recallNugget gain
Track median1000.34990.10020.6268
Deep pool, reranked top 1001000.31300.13320.6291
BM25 + RRF, top 1001000.20040.08400.7139
Variable depth, the long list709.90.12290.29270.8309

Precision and recall on 82 narratives, nugget gain (AutoNuggetizer nuggets) on 25. Source: the RAG tab of our results dashboard.

Read the highlighted row with this chapter in mind. Its recall is almost three times the median. But it returns about 710 documents per narrative, seven times the median list. More documents can never lower recall. So that row shows a trade, and its precision, the lowest in the table, is the price.

We also used the win-and-loss check. Our deep pool has higher set precision than our plain fused list on 73 of 82 narratives, and lower on 5. Yet its nugget gain is lower on 18 of 25 narratives, higher on 4, and tied on the rest. A sign test on those 18 losses and 4 wins gives p = 0.0043, before any correction for running several tests. So the pattern is unlikely to be luck, even though we cannot yet explain it.

What surprised us

The measure could not see our experiment. Seven of our retrieval runs were scored, but they produced only three different sets of scores. Several runs returned the same 100 documents in a different order, because they tested different rerankers. Set measures ignore order, so those runs tied exactly. We had designed an experiment that the track's measures were blind to. Read how a task is scored before you decide what to submit.

Try it

  1. A system returns 20 documents, 5 of them relevant. 8 relevant documents exist. Compute precision and recall.
  2. Compute nDCG for the grades 1, 3, 0, 2 in that order. Then put them in the best order and confirm you get 1.
  3. System A beats system B on 14 of 20 topics. Toss a coin 20 times, several times over, and see how often you get 14 or more heads. Is A's lead convincing?
  4. Find one measure on our dashboard and write down, in one sentence each, what it rewards and what it ignores.

Check yourself

  1. A system returns every document in the collection. What are its recall and its precision, roughly?
  2. Two lists contain the same documents in different orders. Which measures can tell them apart?
  3. What does “above the track median” tell you, and what does it not tell you?
  4. Why compare systems topic by topic instead of by their averages only?
  5. Our long-list run has high recall. What must you check before calling it a good result?
Answers
  1. Recall is 1. Precision is close to 0.
  2. Ranked measures such as nDCG. Set precision and set recall cannot.
  3. The run is better than half the field on that measure. It does not say by how much, or whether the gap is larger than chance.
  4. Topics differ in difficulty. A small average gap can come from one or two topics. Wins and losses per topic show whether the gap is consistent.
  5. How many documents it returned, and its precision.

Go deeper

  • The sign test, exactly. If two systems were equal, each topic would be a fair coin. Ties are left out, which leaves 22 topics in our example. The chance of a split of 18 to 4 or more extreme, counting both directions, is the p-value: 0.0043 here. The test uses only the direction of each difference, not its size. The paired t-test and the randomization test use the size too.
  • Many tests, many false alarms. If you test twenty differences at the 0.05 level, expect one “significant” result by luck. Say how many tests you ran, as we do above with the words “before any correction”.
  • Average precision and MAP. Average precision takes the precision at each rank where a relevant document appears and averages them. Its mean over topics, MAP, was the standard TREC measure for many years.
  • Measures for unjudged documents. When many returned documents were never judged, standard measures treat them as not relevant. Measures such as bpref and judged-at-k were designed for this case.
  • Project idea. Take two runs and the qrels from any public test collection. Compute five measures. Find a pair of runs where the measures disagree about which run is better, and explain why.