feat: add ContextualFaithfulnessEvaluator#64
Open
stefanoamorelli wants to merge 9 commits intostrands-agents:mainfrom
Open
feat: add ContextualFaithfulnessEvaluator#64stefanoamorelli wants to merge 9 commits intostrands-agents:mainfrom
ContextualFaithfulnessEvaluator#64stefanoamorelli wants to merge 9 commits intostrands-agents:mainfrom
Conversation
This field stores documents from vector stores or retrieval systems, enabling RAG evaluation workflows where responses need validation against source context. [1] [1]: https://docs.aws.amazon.com/bedrock/latest/userguide/knowledge-base-evaluate.html
Mirrors the EvaluationData field so users can provide retrieved documents when defining test cases.
Pass retrieval_context from Case through to EvaluationData in both sync and async paths so evaluators can access it.
Defines a 4-tier rating scale from Not Faithful to Fully Faithful, with guidance on evaluating factual claims against retrieval context. Based on faithfulness metrics from RAG evaluation literature. [1] [1]: https://arxiv.org/abs/2309.01431
Validates whether response claims are grounded in retrieval context, designed specifically for RAG systems. Uses structured output with faithfulness tiers mapped to scores [0.0, 0.33, 0.67, 1.0]. This differs from FaithfulnessEvaluator which checks conversation history rather than retrieved documents. [1] [1]: https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/faithfulness/
Tests the new field in Case and updates experiment serialization assertions to include retrieval_context.
Covers initialization, score mapping across all faithfulness tiers, input validation, prompt formatting behavior, async evaluation, and serialization.
Shows RAG evaluation with retrieval_context and updates the available evaluators list to include ContextualFaithfulnessEvaluator and HarmfulnessEvaluator.
ContextualFaithfulnessEvaluator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
ContextualFaithfulnessEvaluatorfor RAG systems to detect hallucinations by validating whether response claims are grounded in retrieval context. This differs from the existingFaithfulnessEvaluatorwhich checks against conversation history rather than retrieved documents.The evaluator uses a 4-tier scoring system mapped to numeric values:
Also an optional
retrieval_contextfield toCaseandEvaluationDatafor passing retrieved data through the evaluation pipeline.Related Issues
#65
Documentation PR
Type of Change
New feature
Testing
New unit tests introduced
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.