On this page
Building a retrieval-augmented generation (RAG) prototype takes an afternoon. Knowing whether it is good enough to put in front of users, and whether yesterday's prompt tweak made it better or worse, takes systematic evaluation. Without it, teams end up judging quality by trying a handful of questions by hand, which misses regressions and gives no way to compare options.
This guide covers RAG evaluation in production: separating retrieval from generation, choosing metrics, building a trustworthy test set, using LLM-as-judge carefully, and how three popular open-source frameworks (Ragas, TruLens and DeepEval) fit into the workflow.
Why RAG needs its own evaluation approach
A RAG pipeline has at least two stages that can fail independently:
- Retrieval: chunking, embedding, search and reranking decide which passages reach the model.
- Generation: the LLM turns the question and retrieved passages into an answer.
If an answer is wrong, you need to know which stage caused it. A perfect generator cannot answer correctly from irrelevant passages, and perfect retrieval does not help if the model ignores the context or invents details. Good evaluation measures each stage separately, then measures the end-to-end result.
The core metrics
Retrieval metrics
- Context precision: of the passages retrieved, how many are relevant, and are the relevant ones ranked near the top?
- Context recall: did retrieval find all the information needed to answer the question?
- Classic IR metrics: hit rate, recall@k, mean reciprocal rank (MRR) and nDCG, when you have labelled relevant documents for each question.
Generation metrics
- Faithfulness (groundedness): is every claim in the answer supported by the retrieved context? This is the main hallucination check.
- Answer relevance: does the answer address the question that was asked, without padding or drifting?
- Answer correctness: does the answer match a reference answer, when you have one?
Operational metrics
Quality is only part of production readiness. Track latency (especially p95), cost per query, token usage, refusal rate and the rate of "I don't know" responses on questions that genuinely have no answer in your corpus.
Building an evaluation set you can trust
The test set matters more than the framework. A practical approach:
- Collect real questions from logs, support tickets, or user interviews. If you have none yet, write questions the way a user would phrase them, not the way the document is written.
- Cover the distribution: simple factual lookups, multi-hop questions that need several passages, comparisons, questions with outdated information, and questions that should be refused because the answer is not in the corpus.
- Add reference answers and source passages for at least a core subset, so you can measure correctness and retrieval recall directly.
- Use synthetic generation carefully. Frameworks can generate questions from your documents, which is a fast way to bootstrap, but review a sample by hand and remove questions that are trivial or unrealistic.
- Version the set alongside your code, and add every important production failure as a new test case.
Fifty to a hundred well-chosen cases are enough to start making decisions.
LLM-as-judge: useful, with caveats
Most RAG metrics for faithfulness and relevance are computed by asking an LLM to judge an answer. This scales far better than human review, but it has known weaknesses:
- Bias towards longer or more confident answers and towards outputs similar in style to the judge's own.
- Inconsistency between runs, especially with vague rubrics.
- Self-preference when the judge and the generator are the same model family.
Mitigate these by writing explicit rubrics, asking for a short justification before the score, using a fixed judge model and prompt when comparing system versions, and checking agreement with human labels on a sample. When the judge and humans disagree often, fix the rubric before trusting the numbers.
Ragas, TruLens and DeepEval compared
| Ragas | TruLens | DeepEval | |
|---|---|---|---|
| Focus | RAG-specific metrics and test-set generation | Tracing and feedback functions on app runs | Unit-test style LLM evaluation |
| Typical metrics | Faithfulness, answer relevancy, context precision, context recall | Context relevance, groundedness, answer relevance (the "RAG triad") | Faithfulness, answer relevancy, contextual precision and recall, G-Eval custom criteria, hallucination |
| Workflow fit | Notebook experiments and batch evaluation | Instrumenting an app and inspecting runs in a dashboard | pytest-style tests in CI pipelines |
| Strength | Quick start for RAG evaluation | Visibility into individual traces | Easy regression gating |
All three are actively developed, and their metric names and APIs change over time, so check current documentation before committing. In practice, the choice matters less than having a fixed test set, consistent metrics and a habit of running them. Many teams pair one framework with tracing from an observability tool and a few custom checks specific to their domain.
Putting evaluation into your workflow
During development
Run the full evaluation set whenever you change chunk size, embedding model, retrieval parameters, reranker or prompts. Record results in a simple table so you can compare runs. Change one variable at a time.
In CI
Select a smaller regression suite that runs in a few minutes. Fail the build if faithfulness or answer correctness drops below a threshold, or falls by more than a set margin from the last release.
In production
Sample live traffic for automated scoring, collect user feedback (thumbs up or down, follow-up questions, escalations), and review low-scoring traces each week. Add representative failures to the test set so the same problem cannot return unnoticed.
Common mistakes
- Only measuring end-to-end quality, so you cannot tell whether retrieval or generation broke.
- Evaluating on questions written from the documents rather than from user needs, which overstates retrieval quality.
- Changing the judge model between comparisons, making scores incomparable.
- Ignoring unanswerable questions, which hides hallucination problems.
- Optimising a metric rather than the user experience it was meant to reflect.
Show it in your portfolio
A RAG project with a real evaluation section stands out sharply among AI portfolios, because most stop at a demo. Include your test set design, metrics before and after each improvement, and what you learned in the README, following the structure in our GitHub portfolio guide. Then describe the results on your resume and check the wording with the free ATS resume checker. For context on how employers combine LLM, RAG and MLOps skills, read our machine learning engineer job market analysis, and browse AI and ML roles to see what teams are asking for now.
FAQs
What is the most important metric for a RAG system?
There is no single one. Measure retrieval quality (did you fetch the right passages?) and generation quality (is the answer faithful to those passages and does it address the question?) separately, so you know which part to fix. Faithfulness and context recall are often the most informative starting pair.
How large should a RAG evaluation set be?
Start with 50 to 100 carefully chosen questions that reflect real user intent, including hard and unanswerable ones. A small, high-quality set you trust is more useful than thousands of synthetic questions nobody has reviewed. Grow it as you find failures in production.
Can I trust LLM-as-judge scores?
Use them as a scalable signal, not ground truth. Validate the judge against human labels on a sample, keep the judge model and prompt fixed when comparing versions, and watch for known biases such as favouring longer answers.
Should evaluation run in CI?
Yes, for a fixed regression set. Running a small evaluation suite on every change to prompts, chunking or retrieval settings catches quality drops before they reach users. Larger evaluations can run on a schedule.
Which framework should I choose: Ragas, TruLens or DeepEval?
Choose based on workflow. Ragas is convenient for RAG-specific metrics and test-set generation, DeepEval fits teams that want pytest-style tests in CI, and TruLens emphasises tracing and feedback functions on live application runs. Many teams use one framework plus their own custom checks.
Check your resume before you apply
Score your resume against any job description and see exactly which keywords are missing. Free.