Ragas metrics
A metric is a quantitative measure of how an application, or one of its components, performs on a test set. It is the compass for an experiment: a positive delta is a successful change, and a drop is a regression.
Three levels of score User, part, business
Start with the outcome the user sees. Drop to a component when that outcome is weak. Business numbers arrive later.
End to end
The system as a black box. Answer correctness and citation accuracy are the outcomes a RAG user cares about.
Component
One part in isolation, such as retrieval accuracy. A 50% retrieval score is actionable, and it still may not move the end-to-end score.
Business
A lagging organizational outcome, such as ticket deflection after an assistant has been in production for weeks.
Metrics also decide which LLM, retriever, or agent configuration to keep, which stage is failing, and whether performance drifts after deployment.
How a score is produced LLM or code, one turn or many
LLM metrics subclass MetricWithLLM and need an LLM set before scoring. Non-LLM metrics subclass Metric and stay deterministic.
| LLM-based | Non-LLM | |
|---|---|---|
| Mechanism | One or more LLM calls, with prompts you can edit | String similarity, BLEU, exact match, and similar checks |
| Behavior | Closer to human judgment, and not always identical on a rerun | Deterministic, with a weaker correlation to human ratings |
| Base class | MetricWithLLM | Metric |
from ragas.metrics import FactualCorrectness
scorer = FactualCorrectness(llm=evaluation_llm)
await scorer.single_turn_ascore(sample)Single-turn metrics subclass SingleTurnMetric and score withsingle_turn_ascore on a single-turn sample. Multi-turn metrics subclassMultiTurnMetric and score a MultiTurnSample withmulti_turn_ascore.
from ragas.metrics import AgentGoalAccuracy
from ragas import MultiTurnSample
scorer = AgentGoalAccuracy()
await scorer.multi_turn_ascore(sample)Output types Discrete, numeric, ranking
The decorator fixes the shape of the score so results can be compared and, for numbers, aggregated.
@discrete_metric(name="response_quality", allowed_values=["pass", "fail"])
def my_metric(predicted: str, expected: str) -> str:
return "pass" if predicted.lower() == expected.lower() else "fail"Classes such as pass/fail or good/okay/bad have no implicit order. Discrete metrics accept a custom prompt, which makes them the short path to a one-off judge. Built-in collection metrics such as Faithfulness keep their own prompts; those are edited separately.
@numeric_metric(name="response_accuracy", allowed_values=(0, 1))
def my_metric(predicted: float, expected: float) -> float:
return abs(predicted - expected) / max(expected, 1e-5)@ranking_metric(name="response_ranking", allowed_values=[0, 1])
def my_metric(responses: list) -> list:
lengths = [len(response) for response in responses]
return sorted(range(len(lengths)), key=lambda i: lengths[i])Design and selection Few strong signals
Ragas designs each metric around one aspect, a readable score, a prompt flow close to how a person would grade, enough few-shot examples, and a shared range such as 0 to 1.
- End to end first. For a RAG assistant, answer accuracy and citation accuracy carry more user value than a pile of secondary scores.
- Interpretable. Execution accuracy in text-to-SQL means the generated query returns the same rows as the expert query.
- Objective. If independent raters agree on at least 80% of labels, the criterion is solid enough to automate.
- One strong proxy. Goal accuracy on a conversational agent says more than a bundle of weak scores such as coherence and helpfulness.
Available metrics By task
Each built-in metric targets one aspect. LLM-based ones may take several calls. Any of them can be replaced with a metric you write.
| Task | Metrics |
|---|---|
| RAG | Context precision, context recall, context entities recall, noise sensitivity, response relevancy, faithfulness, multimodal faithfulness, multimodal relevance |
| Nvidia | Answer accuracy, context relevance, response groundedness |
| Agents and tools | Topic adherence, tool call accuracy, tool call F1, agent goal accuracy |
| Natural language | Factual correctness, semantic similarity, non-LLM string similarity, BLEU, CHRF, ROUGE, string presence, exact match |
| SQL | Execution-based Datacompy score, SQL query equivalence |
| General | Aspect critic, simple criteria scoring, rubrics scoring, instance-specific rubrics, summarization |
Key takeaways
- Pick the end-to-end outcome first, then a component metric when you need to know which stage failed.
- Use an LLM metric when the rubric needs judgment. Use a non-LLM metric when the answer is checkable.
- Keep scores on a shared range and on a single aspect so two experiments can be compared.