Most developers evaluate RAG systems the expensive way: reading answers one by one and going by gut feeling. That works for five queries and collapses at fifty. RAGAS, the open-source Retrieval-Augmented Generation Assessment framework, takes a different approach. It uses an LLM as a judge to score your pipeline on four metrics that separate retrieval problems from generation problems, so a bad score points at the part you should actually fix.
RAG answers fail in two places
A RAG pipeline has two moving parts. The retriever fetches chunks from your knowledge base, and the generator writes an answer from those chunks. A bad answer can come from either half, and the repair depends on which one. Retrieval failure means the right document never reached the model. Generation failure means the model had the right context and still invented something.
Exact-match metrics like ROUGE or BLEU cannot tell you this. They compare the answer to a gold answer word by word, so a correct paraphrase scores low while a hallucination that happens to match the gold scores high. RAGAS-style metrics judge the answer against the retrieved context and the question instead, which is why they map to real repairs.
The four RAGAS metrics
1. Faithfulness
Faithfulness asks whether every claim in the answer can be derived from the retrieved context. The judge breaks the answer into atomic claims and checks each one against the context. The score is the share of supported claims: two supported claims out of three gives a faithfulness of 0.67. This is the hallucination metric. It needs no ground-truth answer, only the context you retrieved.
2. Answer relevance
Answer relevance asks whether the answer addresses the question. RAGAS computes it with a trick: the judge generates several questions that the answer could be responding to, then takes the average cosine similarity between those questions and the original query. It catches the long, fluent, fully grounded answer that never answers what was asked. Like faithfulness, it needs no ground truth.
3. Context precision
Context precision measures whether the chunks you retrieved were the right ones. The judge labels each retrieved chunk as relevant or not, given the question and the ground-truth answer. This metric needs a ground-truth answer, because without one there is no way to say which chunks mattered. Low precision means your retriever is dragging in noise: chunks ranked badly, split at the wrong boundaries, or fetched in excessive numbers.
4. Context recall
Context recall measures whether retrieval found everything the answer needed. The judge breaks the ground-truth answer into claims and checks how many are covered by the retrieved chunks. It also needs ground truth. Low recall means the knowledge is in your corpus but never made it into context: raise top-k, add chunk overlap, or check whether the documents are actually indexed.
Worked example: faithfulness by hand
The fastest way to trust a metric is to compute it once yourself. Take this query against a small docs corpus:
Question: What is the default Redis port, and how do you trigger a snapshot?
Retrieved chunks:
- Chunk 1: “Redis listens on TCP port 6379 by default.”
- Chunk 2: “The SAVE command forces Redis to write an RDB snapshot of the dataset to disk.”
Generated answer: “Redis uses port 6379 by default. The SAVE command writes an RDB snapshot to disk. Redis also ships with AOF persistence that logs every write operation.”
Split the answer into claims and check each against the chunks:
| Claim | Supported by context? |
|---|---|
| Redis uses port 6379 by default | Yes (chunk 1) |
| SAVE writes an RDB snapshot to disk | Yes (chunk 2) |
| Redis ships with AOF persistence logging every write | No |
Two of three claims are supported, so faithfulness = 0.67. Notice the third claim may be factually true in the real world, and that changes nothing here. Faithfulness is a grounding test, not a truth test: the question is whether the answer stayed inside what you retrieved.
The same idea in Python
Here is the faithfulness algorithm stripped to its skeleton, so you can see what any implementation is doing under the hood:
def compute_faithfulness(answer, contexts, llm):
# 1. Split the answer into atomic, checkable claims
claims = llm.extract_claims(answer)
# 2. Judge each claim against the retrieved context
supported = 0
for claim in claims:
if llm.entails(claim=claim, context=contexts):
supported += 1
# 3. Score = supported claims / total claims
return supported / len(claims)
In the real RAGAS library these two LLM calls sit inside prompt templates with verdict parsing, but the shape is exactly this: decompose, verify, divide. If you ever distrust a score, reproduce these three steps by hand on one example and you will see where the judge disagreed with you.
Metrics at a glance
| Metric | Checks | Needs ground truth | Catches |
|---|---|---|---|
| Faithfulness | Answer claims supported by retrieved context | No | Hallucinations, invented details |
| Answer relevance | Answer addresses the user’s question | No | Off-topic or bloated answers |
| Context precision | Retrieved chunks are relevant | Yes | Noisy retrieval, bad ranking |
| Context recall | All needed info was retrieved | Yes | Missing chunks, bad indexing |
| Answer correctness* | Answer matches the gold answer | Yes | End-to-end wrongness |
*Answer correctness is a companion metric, not one of the core four. RAGAS computes it as a blend of factual correctness (an F1 score over claim-level true and false positives) and semantic similarity to the gold answer. Use it as the headline number, and use the four metrics above to diagnose.
What low scores tell you to fix
The point of separating the metrics is that each one points at a different repair:
- Faithfulness low, retrieval metrics fine: the generator is adding claims. Tighten the prompt: instruct the model to answer only from the provided context and to say it does not know when the context is thin.
- Answer relevance low: the answer drifts. Check the prompt for open-ended instructions, and check whether retrieval is returning distracting chunks that pull the answer off course.
- Context precision low: the retriever fetches junk. Improve ranking, add metadata filters, or re-chunk so each chunk carries one idea.
- Context recall low: the retriever misses what exists. Raise top-k, fix chunk overlap, or check that the documents are actually indexed.
- Everything low: your test set may be the problem. If the questions cannot be answered from the corpus at all, no pipeline change will move the scores.
Honest caveats about LLM-as-a-judge
These metrics replace human reading with an LLM’s judgment, and that trade has real costs. Absolute scores shift when you change the judge model or the prompt, so scores from two different setups are not comparable. RAGAS’s original validation used two annotators with roughly 95 percent agreement on faithfulness, and researchers have noted that sample is small. Treat the numbers as a signal with noise, not a lab measurement.
The practical fix is to keep one fixed judge model and one fixed prompt, run the suite on every pipeline change, and track relative movement. A faithfulness score that climbs from 0.67 to 0.82 after a prompt change is meaningful even if the absolute numbers are approximate.
A minimal evaluation loop
You do not need much to start. Collect ten to twenty representative questions, write or review the gold answers, run your pipeline, and score faithfulness and answer relevance first, since those two need no ground truth. Add context precision and recall once you have gold answers you trust. Re-run on every retriever or prompt change and keep the judge fixed. Ten graded examples that you re-run weekly beat a hundred ungraded chats, because a number that moves is the only thing that tells you whether a change helped.