Implementation:Explodinggradients Ragas ContextRecall Metric
| Field | Value |
|---|---|
| source | Repo |
| domains | Metrics, Evaluation |
| last_updated | 2026-02-10 |
Overview
ContextRecall estimates how much of the ground truth reference can be attributed to the retrieved contexts, with multiple variants including LLM-based, non-LLM, and ID-based implementations.
Description
The context recall module provides several classes:
- LLMContextRecall -- Uses an LLM to classify each sentence in the reference as attributable (1) or not attributable (0) to the retrieved contexts, then computes the ratio of attributed statements.
- ContextRecall -- Convenience alias for
LLMContextRecall. - NonLLMContextRecall -- Uses non-LLM string similarity to compare retrieved contexts against reference contexts, applying a threshold for binary decisions.
- IDBasedContextRecall -- Directly compares retrieved context IDs with reference context IDs for recall.
The LLM-based variant uses an ensembler to aggregate multiple classification responses for robustness. The non-LLM variant supports configurable distance measures (Levenshtein, Hamming, Jaro, Jaro-Winkler).
Usage
LLM-based variants require user_input, retrieved_contexts, and reference. Non-LLM requires retrieved_contexts and reference_contexts. ID-based requires retrieved_context_ids and reference_context_ids.
Code Reference
| Property | Value |
|---|---|
| Source Location | src/ragas/metrics/_context_recall.py L88-282
|
| Class Signature | class LLMContextRecall(MetricWithLLM, SingleTurnMetric)
|
| Import | from ragas.metrics import ContextRecall
|
I/O Contract
Inputs (LLMContextRecall / ContextRecall)
| Parameter | Type | Required | Description |
|---|---|---|---|
| user_input | str | Yes | The user query |
| retrieved_contexts | List[str] | Yes | The retrieved context passages |
| reference | str | Yes | The ground truth reference answer |
Outputs
| Output | Type | Description |
|---|---|---|
| score | float | Recall score: ratio of attributed statements (0.0 to 1.0) |
Usage Examples
from ragas.metrics import ContextRecall
from ragas.dataset_schema import SingleTurnSample
metric = ContextRecall()
# metric.llm = ... # Set your LLM
sample = SingleTurnSample(
user_input="What can you tell me about Albert Einstein?",
retrieved_contexts=[
"Albert Einstein (14 March 1879 - 18 April 1955) was a German-born theoretical physicist."
],
reference="Albert Einstein was born on 14 March 1879 and was a German-born theoretical physicist."
)
# score = await metric.single_turn_ascore(sample)
A pre-configured instance is available:
from ragas.metrics._context_recall import context_recall
Related Pages
- Explodinggradients_Ragas_ContextPrecision_Metric -- Complementary precision metric for retrieval
- Explodinggradients_Ragas_ContextEntityRecall_Metric -- Entity-level context recall
- Explodinggradients_Ragas_Faithfulness_Metric -- Statement-level faithfulness against contexts