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 FactualCorrectness Metric

From Leeroopedia


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

Overview

FactualCorrectness evaluates the factual accuracy of responses by decomposing text into atomic claims and verifying them against a reference using Natural Language Inference (NLI).

Description

The FactualCorrectness class decomposes a response into atomic claims using a claim decomposition prompt, then verifies each claim against the reference text using an NLI prompt. It supports three evaluation modes: precision (how many response claims are supported by the reference), recall (how many reference claims appear in the response), and F1 (harmonic mean of both). The decomposition granularity is controlled by atomicity and coverage parameters. It inherits from MetricWithLLM and SingleTurnMetric.

Key attributes:

  • mode -- Evaluation mode: "precision", "recall", or "f1" (default "f1").
  • beta -- Beta value for F-beta score calculation (default 1.0).
  • atomicity -- Level of claim decomposition: "low" or "high" (default "low").
  • coverage -- Level of claim coverage: "low" or "high" (default "low").
  • claim_decomposition_prompt -- Prompt for breaking text into claims.
  • nli_prompt -- Prompt for NLI verification of claims.

Usage

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

Code Reference

Property Value
Source Location src/ragas/metrics/_factual_correctness.py L165-307
Class Signature class FactualCorrectness(MetricWithLLM, SingleTurnMetric)
Import from ragas.metrics import FactualCorrectness

I/O Contract

Inputs

Parameter Type Required Description
response str Yes The generated response to evaluate
reference str Yes The ground truth reference text

Outputs

Output Type Description
score float Factual correctness score (0.0 to 1.0), computed based on the selected mode

Usage Examples

from ragas.metrics import FactualCorrectness
from ragas.dataset_schema import SingleTurnSample

metric = FactualCorrectness(mode="f1", atomicity="low", coverage="low")
# metric.llm = ...  # Set your LLM

sample = SingleTurnSample(
    response="Albert Einstein was a German theoretical physicist who developed the theory of relativity.",
    reference="Albert Einstein was a German-born theoretical physicist. He developed the theory of relativity and contributed to quantum mechanics."
)
# score = await metric.single_turn_ascore(sample)

Related Pages

Page Connections

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