ContextRecall

org.llm4s.rag.evaluation.metrics.ContextRecall
See theContextRecall companion object
class ContextRecall(llmClient: LLMClient) extends RAGASMetric

Context Recall metric: measures if all relevant information was retrieved.

Algorithm:

  1. Extract key facts/sentences from the ground truth answer
  2. For each fact, check if it can be attributed to the retrieved contexts
  3. Score = Number of facts covered by contexts / Total facts in ground truth

The intuition: if all facts needed to answer the question correctly are present in the retrieved contexts, recall is 1.0. Missing facts lower the score.

Value parameters

llmClient

The LLM client for fact extraction and attribution

Attributes

Example
{
val metric = ContextRecall(llmClient)
val sample = EvalSample(
 question = "What are the symptoms of diabetes?",
 answer = "...",  // answer not used for this metric
 contexts = Seq(
   "Diabetes symptoms include excessive thirst and frequent urination.",
   "Type 2 diabetes may cause fatigue and blurred vision."
 ),
 groundTruth = Some("Symptoms of diabetes include increased thirst, frequent urination, fatigue, and blurred vision.")
)
val result = metric.evaluate(sample)
// Score = facts covered / total facts from ground truth

}

Companion
object
Graph
Supertypes
trait RAGASMetric
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def evaluate(sample: EvalSample): Result[MetricResult]

Evaluate a single sample.

Evaluate a single sample.

Value parameters

sample

The evaluation sample containing question, answer, contexts

Attributes

Returns

Score between 0.0 and 1.0, with optional details

Definition Classes

Inherited methods

def canEvaluate(sample: EvalSample): Boolean

Check if this metric can be evaluated for a given sample.

Check if this metric can be evaluated for a given sample.

Attributes

Inherited from:
RAGASMetric
def evaluateBatch(samples: Seq[EvalSample]): Result[Seq[MetricResult]]

Evaluate multiple samples.

Evaluate multiple samples.

Default implementation evaluates sequentially. Override for batch optimizations (e.g., batched LLM calls).

Value parameters

samples

The evaluation samples

Attributes

Returns

Results for each sample in order

Inherited from:
RAGASMetric

Concrete fields

override val description: String

Human-readable description of what this metric measures.

Human-readable description of what this metric measures.

Attributes

override val name: String

Unique name of this metric (e.g., "faithfulness", "answer_relevancy"). Used as an identifier in results and configuration.

Unique name of this metric (e.g., "faithfulness", "answer_relevancy"). Used as an identifier in results and configuration.

Attributes

override val requiredInputs: Set[RequiredInput]

Which inputs this metric requires from an EvalSample. Used to skip metrics when required inputs are missing.

Which inputs this metric requires from an EvalSample. Used to skip metrics when required inputs are missing.

Attributes