World’s largest virtual agentic engineering & quality conference
RAG testing explained: retrieval and generation metrics, how to build an evaluation dataset, framework selection, CI/CD gating, and production monitoring.

Anubhav Singhmaar
Author

Devansh Bhardwaj
Reviewer
Last Updated on: August 7, 2026
To build the RAGTruth corpus, researchers collected nearly 18,000 responses generated by retrieval-augmented language models and annotated them by hand at both the response and the word level. The scale of that annotation effort is the point. Deciding whether a grounded answer actually stayed grounded is hard enough that a benchmark needed word-level human labels to settle it.
That is the problem RAG testing solves at a smaller scale inside your own pipeline. A retrieval-augmented system can return a fluent, confident, factually reasonable answer that has nothing to do with the documents it retrieved, and no conventional test will notice.
TL;DR
RAG evaluation measures whether a retrieval-augmented generation system finds the right context for a question and then answers using only that context. It is two assessments wearing one name, and keeping them separate is the whole discipline.
The academic literature settled on this split early. The survey Evaluation of Retrieval-Augmented Generation by Yu and colleagues organizes the field around exactly two components, retrieval and generation, and proposes a unified process for assessing each. Every practical framework you will meet later in this article inherits that structure.
A standalone language model has one place to go wrong. A RAG system has two, and they fail independently, which produces failure combinations that a single accuracy score cannot distinguish.
| Retrieval | Generation | What the user sees | What to fix |
|---|---|---|---|
| Good | Good | A correct answer traceable to a real source document. | Nothing. Lock this behavior in with a regression case. |
| Good | Bad | A wrong answer even though the right document was sitting in the context window. | Prompt design, context ordering, or the generator model itself. |
| Bad | Good | An honest refusal, or an answer grounded in irrelevant context. | Chunking, embedding model, top-k, or the index itself. |
| Bad | Bad | A confident answer invented from parametric memory. | Both halves. Start with retrieval, since generation cannot be judged on bad context. |
The second row is the one teams miss. When retrieval works and the answer is still wrong, a retrieval-only dashboard shows green while users report nonsense. This is also why the broader practice of AI model testing treats component isolation as a first principle rather than an optimization.
Retrieval metrics come from information retrieval, so they are older and better understood than anything on the generation side. They answer one question in different ways: did the right chunk make it into the context window?
| Metric | What it measures | Use it when |
|---|---|---|
| Context precision | The proportion of retrieved chunks that are actually relevant to the question. | Noise is drowning the signal and the context window is filling with junk. |
| Context recall | The proportion of the information needed to answer that was successfully retrieved. | Answers are incomplete or the model refuses questions your corpus can answer. |
| Hit rate | How often at least one relevant chunk appears in the top-k results. | You need one blunt number to track across index changes. |
| NDCG@k | Whether relevant chunks rank near the top, not merely somewhere in the results. | Position matters because the generator weights early context more heavily. |
Precision and recall pull against each other. Raising top-k almost always lifts recall and depresses precision, so track both and pick the operating point your generator tolerates rather than maximizing either alone.
Generation metrics are newer, fuzzier, and usually computed by a second language model acting as judge. They matter because a RAG system that retrieves perfectly can still fabricate.
| Metric | Question it answers | Failure it catches |
|---|---|---|
| Faithfulness | Is every claim in the answer supported by the retrieved context? | The model answered from memory instead of from your documents. |
| Answer relevancy | Does the answer address the question that was asked? | A technically grounded response to a question nobody asked. |
| Answer correctness | Does the answer match the known ground truth? | Confidently wrong output on questions you already have answers for. |
Faithfulness is the metric worth understanding deeply, because it is counterintuitive. An answer can be true in the world and still fail faithfulness if the retrieved context did not support it. That is the correct outcome. A system that gets lucky from parametric memory today will be wrong tomorrow when the question moves outside what the model happens to remember.
Note: Hallucination detection and context awareness are two of the nine quality dimensions TestMu AI's Agent Testing scores automatically when it evaluates a chat or voice agent. Try TestMu AI free!
Component evaluation scores the retriever and the generator separately. End-to-end evaluation scores only the final answer. Mature setups run both, for different audiences and at different moments.
The same layering applies to multi-step systems where a planner decides what to retrieve. If your architecture routes retrieval through an agent, the evaluation surface widens further, which is covered in agentic RAG.
Every metric above needs questions to run against, and dataset quality caps evaluation quality. A weak dataset produces confident scores that mean nothing.
Coverage beats volume. Five hundred paraphrases of one question exercise a single retrieval path repeatedly, while eighty questions spanning eighty topics find real gaps.
Everything above assumes you have labeled answers. Most teams starting out do not, and waiting until a labeled set exists is how RAG evaluation gets postponed indefinitely. A useful subset of metrics needs no ground truth at all.
Context recall and answer correctness are the two that genuinely need references, because both ask what a right answer would have contained. Reference-free scoring is what makes production sampling practical, since live traffic never arrives with labels attached.
The tradeoff is real. Reference-free metrics tell you whether the system was internally consistent, not whether it was right. A RAG pipeline that retrieves the wrong document and then answers it faithfully scores well on every reference-free metric while being useless, which is why a small labeled set still earns its cost.
Several open-source frameworks implement the metrics above. They overlap heavily on the core scores, so selection usually turns on where the results need to land rather than on which metrics exist.
| Framework | Shape | Best fit |
|---|---|---|
| RAGAS | Reference-light metric library centered on faithfulness and context scores. | Getting numbers quickly without building a labeled set first. |
| DeepEval | Assertion-style API modelled on unit testing, with pass and fail thresholds. | Teams that want evaluation to behave like a test suite in CI. |
| TruLens | Instrumentation and tracing over app runs, with feedback functions. | Debugging why a specific chain produced a specific answer. |
| Phoenix | Open-source observability with tracing built on OpenTelemetry. | Connecting evaluation to an existing observability stack. |
Pick on integration surface, not metric count. If evaluation results need to block a merge, an assertion-shaped framework saves weeks of glue code. If they need to explain a single bad answer, tracing matters more than scoring.
One caution that applies to all of them. Most generation metrics are computed by a judge model, so the judge is now part of your test infrastructure. Version it, and re-baseline your thresholds when it changes, exactly as you would for any other dependency.
Evaluation that runs when someone remembers to run it is a report. Evaluation wired into the pipeline is a gate. The difference decides whether a chunking change ships broken.
Treat each metric as an assertion with a threshold, the same way an integration test asserts a status code:
# Fail the build when grounding regresses.
THRESHOLDS = {
"faithfulness": 0.85,
"answer_relevancy": 0.80,
"context_recall": 0.75,
}
def assert_rag_quality(scores):
failures = [
f"{name}: {scores[name]:.2f} < {floor:.2f}"
for name, floor in THRESHOLDS.items()
if scores[name] < floor
]
if failures:
raise AssertionError("RAG quality gate failed -> " + "; ".join(failures))
print("RAG quality gate passed")Three practical rules keep the gate usable. Set thresholds from a measured baseline rather than from ambition, run the full set nightly and a fast subset per pull request, and alert on score deltas between runs instead of only on absolute values.
The cost problem shows up immediately, because judge-model calls are slow and every question multiplies them. Running the suite on TestMu AI's HyperExecute orchestration cloud spreads those cases across just-in-time infrastructure using matrix and auto-split strategies, which the platform reports as up to 70% faster execution than a traditional grid. Setup lives in the HyperExecute documentation.
Metric scores describe the pipeline. Users interact with an application wrapped around it, and that wrapper has failure modes no evaluation metric will ever report. Testing RAG applications means covering the layer between a good score and a good experience.
The last two are the ones that turn a quality problem into a security problem, and neither is visible in a faithfulness score. A conversational front end adds another layer on top, where turn-level context handling and refusal behavior need their own coverage.
A RAG system degrades without anyone touching the code, which makes pre-launch thresholds a starting condition rather than a guarantee. Three drifts cause most of it.
Sampling a small percentage of live traffic through the same faithfulness and relevancy scoring used in CI is usually enough to see these early. Watch retrieval scores especially, because corpus and query drift both surface there before users complain. The same logic drives LLM testing generally, where post-deployment measurement is treated as part of the test plan rather than an operations afterthought.
Note: Failure patterns are easier to act on when they are aggregated across runs rather than read one report at a time. TestMu AI's Test Insights surfaces those patterns across your suite history.
The last two are the expensive ones, because both manufacture phantom regressions that consume engineering time before anyone questions the measurement itself. Teams building conversational interfaces on top of retrieval hit the same trap, which is why chatbot testing emphasizes changing one variable per run.
Build the fifty-question dataset first, before choosing a framework or arguing about metrics. Record the expected source document alongside each answer, because that single field is what makes retrieval measurable and it is the piece teams most often skip.
From there, score retrieval and generation separately, set thresholds from a measured baseline, and put those thresholds in the pipeline so a regression blocks a merge instead of reaching users. Keep sampling after launch, since corpus and query drift arrive without a deploy.
If your retrieval layer sits behind a chat or voice interface, the answer quality your users actually experience is an agent problem as much as a retrieval one. TestMu AI's Agent Testing scores that surface with autonomous evaluators rather than fixed scripts, and the approach to defining scenarios and thresholds is covered in AI agent evaluation.
Author
Anubhav Singhmaar is an AI Product Manager at TestMu AI driving Kane CLI, the command-line tool that brings browser automation to the terminal, turning natural-language flows into runs in a real Chrome browser that return pass or fail with shareable proof. He owns the roadmap and prioritization and works with engineering to ship developer-facing features. Before TestMu AI, he spent over four years at Sprinklr owning enterprise voice AI across APAC and EMEA. A mechanical engineer turned product manager, he grounds guidance in real QA workflows.
Reviewer
Devansh Bhardwaj is a Community Evangelist at TestMu AI with 4+ years of experience in the tech industry. He has authored 30+ technical blogs on web development and automation testing and holds certifications in Automation Testing, KaneAI, Selenium, Appium, Playwright, and Cypress. Devansh has contributed to end-to-end testing of a major banking application, spanning UI, API, mobile, visual, and cross-browser testing, demonstrating hands-on expertise across modern testing workflows.
Did you find this page helpful?
More Related Blogs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance