# Evaluating retrieval before blaming the model

Published 2026-04-22 · Updated 2026-05-10 · Topics: RAG, AI

Measuring what the retriever returns before touching prompts or models.

When a RAG answer is wrong, the first suspect is usually the model, and the first fix is usually the prompt. Many wrong answers start earlier: the passage that held the answer never reached the model.

## Measure the retriever on its own

Take the questions your users actually ask, and mark for each one the passages that answer it. With that labelled set the retriever gets a score of its own, independent of any prompt.

```go
func RecallAtK(retrieved []string, relevant map[string]bool, k int) float64 {
	if len(relevant) == 0 {
		return 0
	}
	found := 0
	for i, id := range retrieved {
		if i == k {
			break
		}
		if relevant[id] {
			found++
		}
	}
	return float64(found) / float64(len(relevant))
}
```

The labelled set is a list of questions, each with the passages that answer it, as in [`labelled-set.json`](https://danielealbano.me/blog/evaluating-retrieval-before-blaming-the-model/labelled-set.json).

## What the numbers tell you

| Measure | When it is low |
|---|---|
| Recall at k | The answer is not among the passages the model sees. |
| Precision at k | The passages the model sees are mostly noise. |
| First relevant rank | The answer is there, but too far down the list. |

![The question goes to the retriever, which passes the top k passages to the model.](https://danielealbano.me/blog/evaluating-retrieval-before-blaming-the-model/pipeline.svg "The model sees only the top k passages.")

## Then the prompt

Only once recall holds does it make sense to change the prompt or the model, and then the labelled set tells you whether the change helped.

- Keep the labelled set in the repository, next to the code.
- Run it in CI, like any other test.
- Add every wrong answer users report as a new case.

[All articles](https://danielealbano.me/blog)

## Building something with RAG, search or AI? Write to me.

[Open the contact form](https://danielealbano.me/contact)

---

Every page of this site is available in Markdown: request its URL with the header `Accept: text/markdown`.
