Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Explodinggradients Ragas ContextEntityRecall Metric

From Leeroopedia


Field Value
source Repo
domains Metrics, Evaluation
last_updated 2026-02-10

Overview

ContextEntityRecall measures how well the retrieved contexts cover the entities present in the ground truth reference by computing entity-level recall.

Description

The ContextEntityRecall class evaluates the quality of retrieval by extracting named entities from both the ground truth reference and the retrieved contexts using an LLM, then computing entity-level recall: |CN intersection GN| / |GN| where CN is the set of entities in contexts and GN is the set of entities in the ground truth. A score of 1.0 indicates the retrieved contexts cover all entities present in the ground truth. The metric is particularly useful for domain-specific applications where entity coverage matters (e.g., tourism chatbots). It inherits from MetricWithLLM and SingleTurnMetric.

Key attributes:

  • context_entity_recall_prompt -- The prompt used for extracting entities from text (default ExtractEntitiesPrompt).
  • max_retries -- Maximum number of retries for LLM generation (default 1).

Usage

The metric requires reference and retrieved_contexts columns. An LLM must be configured.

Code Reference

Property Value
Source Location src/ragas/metrics/_context_entities_recall.py L90-162
Class Signature class ContextEntityRecall(MetricWithLLM, SingleTurnMetric)
Import from ragas.metrics import ContextEntityRecall

I/O Contract

Inputs

Parameter Type Required Description
reference str Yes The ground truth reference text
retrieved_contexts List[str] Yes The retrieved context passages

Outputs

Output Type Description
score float Entity recall score (0.0 to 1.0)

Usage Examples

from ragas.metrics import ContextEntityRecall
from ragas.dataset_schema import SingleTurnSample

metric = ContextEntityRecall()
# metric.llm = ...  # Set your LLM

sample = SingleTurnSample(
    reference="Albert Einstein was born on 14 March 1879 in Germany.",
    retrieved_contexts=[
        "Albert Einstein (14 March 1879 - 18 April 1955) was a German-born theoretical physicist."
    ]
)
# score = await metric.single_turn_ascore(sample)

A pre-configured instance is available:

from ragas.metrics._context_entities_recall import context_entity_recall

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment