World’s largest virtual agentic engineering & quality conference

WHENAUG 19-21
WHEREVirtual · Global
Register Now
AIAI Testing

RAG Testing: Metrics, Methods and Frameworks

RAG testing explained: retrieval and generation metrics, how to build an evaluation dataset, framework selection, CI/CD gating, and production monitoring.

Author

Anubhav Singhmaar

Author

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 has two failure surfaces, retrieval and generation, and they fail independently. Scoring only the final answer tells you something broke without telling you which half.
  • Retrieval quality is measured with context precision, context recall, hit rate, and NDCG@k. Precision and recall pull against each other, so track both rather than maximizing either.
  • Generation quality is measured with faithfulness, answer relevancy, and answer correctness. Faithfulness is the metric specific to RAG because it catches answers the model produced from memory instead of from the retrieved context.
  • Faithfulness and correctness are not the same thing. An answer can be true in the world and still fail faithfulness, and that is the correct outcome rather than a scoring bug.
  • Start with 50 to 100 real questions and record the expected source document beside each answer. That second field is what makes retrieval measurable, and it is the step teams most often skip.
  • Turn metrics into thresholds and fail the build on a regression, then keep sampling live traffic afterwards, because corpus drift, query drift, and upstream model updates all degrade a system that never changed.
  • Where retrieval sits behind a chat or voice interface, TestMu AI's Agent Testing scores each response across nine quality dimensions, including hallucination detection and context awareness, which are the same failures faithfulness scoring targets.

What Is RAG Evaluation?

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.

  • Retrieval evaluation asks whether the chunks returned by the vector search actually contain the answer.
  • Generation evaluation asks whether the model used those chunks honestly instead of improvising from memory.
  • End-to-end evaluation asks whether the user got a correct, useful response, which is what the business cares about but which tells you nothing about where a failure came from.

Why RAG Fails Differently From a Plain LLM

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.

RetrievalGenerationWhat the user seesWhat to fix
GoodGoodA correct answer traceable to a real source document.Nothing. Lock this behavior in with a regression case.
GoodBadA wrong answer even though the right document was sitting in the context window.Prompt design, context ordering, or the generator model itself.
BadGoodAn honest refusal, or an answer grounded in irrelevant context.Chunking, embedding model, top-k, or the index itself.
BadBadA 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

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?

MetricWhat it measuresUse it when
Context precisionThe 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 recallThe proportion of the information needed to answer that was successfully retrieved.Answers are incomplete or the model refuses questions your corpus can answer.
Hit rateHow often at least one relevant chunk appears in the top-k results.You need one blunt number to track across index changes.
NDCG@kWhether 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

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.

MetricQuestion it answersFailure it catches
FaithfulnessIs every claim in the answer supported by the retrieved context?The model answered from memory instead of from your documents.
Answer relevancyDoes the answer address the question that was asked?A technically grounded response to a question nobody asked.
Answer correctnessDoes 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

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 vs End-to-End Evaluation

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.

  • Component scores are diagnostic. When a build fails, they tell an engineer which half to open.
  • End-to-end scores are the release signal. They map to what a user experiences and belong on the dashboard leadership reads.
  • Running only end-to-end evaluation produces a number that moves without explaining itself, which is the most common way RAG evaluation programs stall.

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.

Building a RAG Evaluation Dataset

Every metric above needs questions to run against, and dataset quality caps evaluation quality. A weak dataset produces confident scores that mean nothing.

  • Start with 50 to 100 real questions taken from support tickets, search logs, or user interviews rather than invented ones.
  • Write the ground-truth answer and record which document should be retrieved for each. That second field is what makes retrieval metrics computable.
  • Expand with synthetic questions generated from your corpus, then spot-check a sample by hand. Generated pairs drift toward the easy, well-covered parts of the index.
  • Deliberately include questions your corpus cannot answer, so you can measure whether the system refuses instead of inventing.
  • Add every production failure to the set as it is found, which turns the dataset into a growing regression suite.

Coverage beats volume. Five hundred paraphrases of one question exercise a single retrieval path repeatedly, while eighty questions spanning eighty topics find real gaps.

RAG Evaluation Without Ground Truth

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.

  • Faithfulness compares the answer against the retrieved context, both of which your system already produces at runtime, so no reference answer is required.
  • Answer relevancy compares the answer against the question, which again needs nothing you do not already have.
  • Context relevance scores each retrieved chunk against the question, giving a retrieval signal without a labeled document set.

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.

Choosing a RAG Evaluation Framework

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.

FrameworkShapeBest fit
RAGASReference-light metric library centered on faithfulness and context scores.Getting numbers quickly without building a labeled set first.
DeepEvalAssertion-style API modelled on unit testing, with pass and fail thresholds.Teams that want evaluation to behave like a test suite in CI.
TruLensInstrumentation and tracing over app runs, with feedback functions.Debugging why a specific chain produced a specific answer.
PhoenixOpen-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.

Automate web and mobile tests with KaneAI by TestMu AI

Gating RAG in CI/CD

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.

Testing RAG Applications, Not Just RAG Pipelines

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.

  • Empty retrieval. When the index returns nothing above the similarity threshold, does the interface say so, or does it silently pass an empty context to the model and render whatever comes back?
  • Citation rendering. If the answer cites sources, the links must resolve to the documents actually retrieved for that response, not to a plausible-looking search result.
  • Latency budgets. Retrieval plus generation plus reranking compounds, and a response that arrives after the user has left is a failure the accuracy metrics score as a pass.
  • Indirect prompt injection. Retrieved documents are untrusted input. A corpus that anyone can contribute to is an instruction channel into your model, and it should be tested as one.
  • Access control on retrieval. The retriever must respect the permissions of the user asking, or the system becomes an efficient way to surface documents that person could not otherwise open.

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.

Monitoring RAG in Production

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.

  • Corpus drift, where documents are added, revised, or deprecated and the index quietly stops matching reality.
  • Query drift, where users move toward topics the corpus was never built to cover and retrieval starts returning near-misses.
  • Model drift, where a hosted generator or embedding model is updated upstream and behavior shifts under a version you did not choose.

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

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.

Common RAG Testing Mistakes

  • Measuring only the final answer, which produces a score that moves without telling you whether retrieval or generation caused it.
  • Treating faithfulness and correctness as the same metric. A faithful answer to bad context is wrong, and a correct answer from parametric memory is ungrounded. Both need separate tracking.
  • Evaluating on questions written by the team that built the index, which encodes the same assumptions the retriever already makes.
  • Never testing unanswerable questions, so refusal behavior stays unmeasured until a user reports a confident fabrication.
  • Changing chunk size, embedding model, and prompt in one commit, which makes any score movement impossible to attribute.
  • Leaving the judge model unpinned, so thresholds shift when the judge changes and the team debugs a regression that never happened.

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.

Test across 3000+ browser and OS environments with TestMu AI

Conclusion

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

Blogs: 4

  • Linkedin

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

Reviewer

  • Linkedin

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.

Open in ChatGPT Icon

Open in ChatGPT

Open in Claude Icon

Open in Claude

Open in Perplexity Icon

Open in Perplexity

Open in Grok Icon

Open in Grok

Open in Gemini AI Icon

Open in Gemini AI

Copied to Clipboard!
...

3000+ Browsers. One Platform.

See exactly how your site performs everywhere.

Try it free
...

Write Tests in Plain English with KaneAI

Create, debug, and evolve tests using natural language.

Try for free
...
TestMu Conf 2026

World's largest virtual agentic engineering & quality conference

...

AUG 19-21, 2026

REGISTER NOW

RAG Testing FAQs

Did you find this page helpful?

More Related Blogs

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests