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.

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.

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.
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.