# What is RAG evaluation? Metrics for retrieval and answers

URL: https://sdclabs.com/glossary/rag-evaluation/

> RAG evaluation scores retrieval and generation separately so you know which half to fix. Key metrics, how to read them together, and a runnable Ragas check.

# What is RAG evaluation?

[Sergey Almyashev](https://sdclabs.com/author/almyashev/) 2026-12-04

Definition

RAG evaluation is the testing of a retrieval-augmented generation system in two halves: retrieval, scored on whether the chunks that answer a question are found and ranked near the top, and generation, scored on whether the answer is grounded in those chunks, relevant and correct. Scoring each half separately shows which one to fix.

## What does RAG evaluation measure?

A RAG system has two parts that fail in different ways, so it gets two sets of scores:

| Half | Question it answers | Typical metrics | Needs |
|---|---|---|---|
| Retrieval | Did the search return the chunks that answer the question, near the top? | Context precision, context recall | Questions with the relevant chunks labeled |
| Generation | Did the model use those chunks well? | Groundedness (sometimes called faithfulness), relevance, completeness, correctness | The answer, the retrieved chunks and often a reference answer |

The [Ragas paper](https://arxiv.org/abs/2309.15217) (first posted in September 2023, revised in April 2025) framed RAG evaluation along these lines: whether retrieval finds relevant context, whether the model uses it faithfully, and the quality of the answer itself. Generation metrics are covered in our entry on [groundedness](https://sdclabs.com/glossary/groundedness/) . This page is about the split, the retrieval side and reading the two together.

## Which half failed? Reading retrieval and generation scores together

The value of two sets of scores is diagnosis. A single answer-quality number tells you something is wrong, not where.

| Retrieval score | Answer score | Likely cause | Fix first |
|---|---|---|---|
| Low recall | Low | The answering chunk never reached the model | Chunking, [embeddings](https://sdclabs.com/glossary/embeddings/) , query rewriting, top-k |
| High recall, low precision | Mixed | The right chunk is there, buried in noise | Reranking or a smaller top-k |
| High | Low | The model had what it needed and still got it wrong | Prompt and model, then generation evals |
| High | High, but users complain | The eval set no longer matches real questions | The test set |

Microsoft's architecture guide [Large language model end-to-end evaluation](https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/rag/rag-llm-evaluation-phase) (last updated 2025-11-21) gives a similar grid for two of its generation metrics. When completeness is high but utilization is low, the returned data answers the question but includes irrelevant chunks, and it suggests reducing the top-k value. When both are low, it suggests revisiting the chunking strategy, for example larger chunks if you use fixed-size chunking.

The same guide adds a warning that shapes how you set targets: model responses are nondeterministic, so it suggests a target range instead of a single target.

## Which retrieval metrics should you use?

Ragas defines two retrieval metrics that work as a starting point:

- **[Context precision](https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/context_precision/)** checks whether relevant chunks rank above irrelevant ones. It is the mean of precision@k taken at each rank that holds a relevant chunk, so a relevant chunk at rank 1 scores higher than the same chunk at rank 4.
- **[Context recall](https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/context_recall/)** checks how many of the relevant chunks, or pieces of information, were retrieved at all. The Ragas docs note that recall always requires a reference to compare against.

Each comes in several versions. LLM-based versions judge relevance against a reference answer or the generated response. Non-LLM versions compare text with string distance measures. ID-based versions compare chunk IDs with a labeled list and need no model at all. Note the gap with the paper's original goal: Ragas began as a framework for reference-free evaluation, but recall cannot be measured without a reference.

## Example: score two retrievers against labeled chunk IDs

This script scores two retriever configurations on three questions whose answering chunks a reviewer has labeled. It uses Ragas' ID-based metrics, so it calls no model. Precision@4 uses the rank-aware Context Precision formula from the Ragas docs, with chunk IDs as the relevance judgment. The two runs are illustrative lists, not output from real retrievers.

# Score the retrieval half of a RAG system against chunk IDs labeled in a golden set. # Ragas ID-based metrics need no LLM and no API key. import asyncio from ragas import SingleTurnSample from ragas.metrics import IDBasedContextPrecision, IDBasedContextRecall # Reviewers marked which chunks answer each question (reference IDs). GOLDEN = { "How long do I have to return an item?": ["returns#1"], "Can I get cash back for a gift?": ["returns#4", "gifts#2"], "Who pays return shipping?": ["shipping#3"], } # Top-4 chunk IDs from two retriever configurations, best match first. RUNS = { "vector only": {"How long do I have to return an item?": ["faq#9", "returns#2", "returns#3", "returns#1"], "Can I get cash back for a gift?": ["gifts#2", "gifts#1", "faq#2", "returns#7"], "Who pays return shipping?": ["shipping#1", "faq#4", "returns#2", "shipping#5"]}, "hybrid + reranker": {"How long do I have to return an item?": ["returns#1", "returns#2", "faq#9", "returns#3"], "Can I get cash back for a gift?": ["gifts#2", "returns#4", "gifts#1", "faq#2"], "Who pays return shipping?": ["shipping#3", "shipping#1", "faq#4", "returns#2"]}, } def precision_at_k(retrieved, relevant): """Rank-aware Context Precision@K (Ragas formula), with IDs as the relevance judgment.""" hits, total = 0, 0.0 for k, chunk in enumerate(retrieved, start=1): if chunk in relevant: hits += 1 total += hits / k # precision@k, counted only at ranks that hold a relevant chunk return total / hits if hits else 0.0 async def score(name, run): p, r, rows = IDBasedContextPrecision(), IDBasedContextRecall(), [] for question, relevant in GOLDEN.items(): s = SingleTurnSample(retrieved_context_ids=run[question], reference_context_ids=relevant) row = (await p.single_turn_ascore(s), await r.single_turn_ascore(s), precision_at_k(run[question], relevant)) rows.append(row) print(f"{name:18} {question[:22]:22} {row[0]:>6.2f} {row[1]:>6.2f} {row[2]:>6.2f}") mean = [sum(col) / len(rows) for col in zip(*rows)] print(f"{name:18} {'MEAN':22} {mean[0]:>6.2f} {mean[1]:>6.2f} {mean[2]:>6.2f}") # Sanity check against the examples in the Ragas docs (expected 0.5 and 0.25). doc = lambda ret, ref: SingleTurnSample(retrieved_context_ids=ret, reference_context_ids=ref) print("docs check:", asyncio.run(IDBasedContextPrecision().single_turn_ascore(doc(["doc_1", "doc_2", "doc_3", "doc_4"], ["doc_1", "doc_4", "doc_5", "doc_6"]))), asyncio.run(IDBasedContextRecall().single_turn_ascore(doc(["doc_1", "doc_2", "doc_3"], ["doc_1", "doc_4", "doc_5", "doc_6"])))) print(f"{'run':18} {'question':22} {'id_P':>6} {'id_R':>6} {'P@4':>6}") for name, run in RUNS.items(): asyncio.run(score(name, run))
We ran it with ragas 0.4.4 on Python 3.11 as RAGAS_DO_NOT_TRACK=true python -W ignore::DeprecationWarning retrieval_eval.py. The environment variable turns off Ragas usage analytics. Without the -W flag, Ragas prints a warning for each import: "Importing IDBasedContextPrecision from 'ragas.metrics' is deprecated and will be removed in v1.0 and has no direct equivalent in 'ragas.metrics.collections'." Output:

docs check: 0.5 0.25 run question id_P id_R P@4 vector only How long do I have to 0.25 1.00 0.25 vector only Can I get cash back fo 0.25 0.50 1.00 vector only Who pays return shippi 0.00 0.00 0.00 vector only MEAN 0.17 0.50 0.42 hybrid + reranker How long do I have to 0.25 1.00 1.00 hybrid + reranker Can I get cash back fo 0.50 1.00 1.00 hybrid + reranker Who pays return shippi 0.25 1.00 1.00 hybrid + reranker MEAN 0.33 1.00 1.00
The first line reproduces the Ragas docs examples, so the metrics behave as documented. Three readings matter:

- **ID precision has a ceiling.** With one relevant chunk in a top 4, the best possible ID precision is 0.25. A mean of 0.33 is a perfect run here, not a weak one.
- **Rank matters, and only one metric sees it.** On the returns question, both runs found the right chunk, so ID precision and recall are equal. The rank-aware score drops to 0.25 because the vector-only run put it last.
- **Recall finds the dead question.** The vector-only run never retrieved the shipping chunk, so no prompt fix can save that answer. That is a retrieval bug.

Because the Ragas warning says the ID-based classes have no direct replacement, pin the Ragas version in CI, or keep a few lines of your own code like precision_at_k above.

## What do you need to build a RAG evaluation set?

- **Real questions** from search logs, tickets or chat history, each with the IDs of the chunks that answer it. That labeling is what makes recall measurable. A [golden dataset](https://sdclabs.com/glossary/golden-dataset/) is the place to keep them.
- **A reference answer** for the generation metrics that need one.
- **Questions your documents cannot answer,** so you can test that the system says so instead of inventing an answer.
- **Stable chunk IDs.** Re-chunking the corpus changes IDs, so re-label or map old IDs before you compare runs.

## What should you check before trusting RAG evaluation scores?

1. **Retrieval and generation are scored separately,** so a drop points to one half.
1. **Labels match the current corpus,** not last quarter's documents.
1. **LLM judges agree with people** on a hand-labeled sample. Our [LLM evaluation guide](https://sdclabs.com/blog/llm-evaluation/) covers judge calibration.
1. **Targets are ranges,** with several runs per change, because answers vary between runs.
1. **For [agentic RAG](https://sdclabs.com/glossary/agentic-rag/) ,** Microsoft's guide adds tool selection accuracy, the number of tool calls per request and end-to-end latency to the list.

Our [AI testing services](https://sdclabs.com/services/ai-testing/) give you a regression suite that tells you what got better and what broke before a new model, prompt or retrieval setting reaches users.

## Sources

1. [Ragas: Automated Evaluation of Retrieval Augmented Generation](https://arxiv.org/abs/2309.15217) , arXiv (Es et al.), 2309.15217 v2, 2025-04-28
1. [Context Precision](https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/context_precision/) , Ragas documentation, 2026-11-13
1. [Context Recall](https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/context_recall/) , Ragas documentation, 2026-11-13
1. [Large language model end-to-end evaluation](https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/rag/rag-llm-evaluation-phase) , Microsoft Learn (Azure Architecture Center), 2025-11-21
1. [Optimizing LLM Accuracy](https://developers.openai.com/api/docs/guides/optimizing-llm-accuracy) , OpenAI API docs, 2026-11

## Frequently asked questions

### Can you evaluate RAG without ground truth?

Partly. Groundedness and some context precision variants compare against the generated answer, so they need no reference. Context recall always needs a reference: labeled chunks or a reference answer.

### What is the difference between RAG evaluation and LLM evaluation?

RAG evaluation is LLM evaluation plus the retrieval step. In OpenAI's words, "the only difference with RAG is you now have the retrieval axis to consider."

### Which tools are used for RAG evaluation?

Ragas offers LLM-based, string-based and ID-based metrics. Microsoft's RAG guide also points to MLflow and Microsoft Foundry evaluators. For ID-based retrieval checks, a test runner and a few lines of your own code are enough.

### How often should you run RAG evaluation?

On every change to chunking, embeddings, retrieval settings, prompts or the model, and after large updates to the document corpus. Run several trials per change, since answers vary between runs.

Services

- [AI testing services](https://sdclabs.com/services/ai-testing/)
- [Generative AI](https://sdclabs.com/services/generative-ai/)

Read next

- [Is your LLM evaluation measuring your app or your judge?](https://sdclabs.com/blog/llm-evaluation/)
- [Can you trust what your AI product says? Testing AI in 2026](https://sdclabs.com/blog/ai-testing-challenges/)

Related terms

- [Groundedness (LLM)](https://sdclabs.com/glossary/groundedness/)
- [Golden dataset](https://sdclabs.com/glossary/golden-dataset/)
- [Hybrid search](https://sdclabs.com/glossary/hybrid-search/)

[Sergey Almyashev](https://sdclabs.com/author/almyashev/) Chief Operating Officer14+ years in QA, automated, exploratory and performance testing, and continuous integration and delivery within Scrum, helping teams in product and outsourcing companies organize teams, processes and tools.[LinkedIn](https://www.linkedin.com/in/sergeyalmyashev/)

## Building with AI agents? Talk to an engineer.

[Start a project](https://sdclabs.com/contact/) [Book a call with the CEO](https://calendly.com/sdclabs/60min)
