org.llm4s.rag.evaluation.metrics.Faithfulness
See theFaithfulness companion object
class Faithfulness(llmClient: LLMClient, batchSize: Int) extends RAGASMetric
Faithfulness metric: measures factual accuracy of the answer relative to the retrieved contexts.
Algorithm:
- Extract factual claims from the generated answer using LLM
- For each claim, verify if it can be inferred from the contexts
- Score = Number of supported claims / Total number of claims
A score of 1.0 means all claims in the answer can be verified from the retrieved context. Lower scores indicate hallucination.
Value parameters
- batchSize
-
Number of claims to verify per LLM call (default: 5)
- llmClient
-
The LLM client for claim extraction and verification
Attributes
- Example
-
val faithfulness = Faithfulness(llmClient) val sample = EvalSample( question = "What is the capital of France?", answer = "Paris is the capital of France and has a population of 2.1 million.", contexts = Seq("Paris is the capital and largest city of France.") ) val result = faithfulness.evaluate(sample) // Result: score ~0.5 (capital claim supported, population claim not supported) - Companion
- object
- Graph
-
- Supertypes
Members list
In this article