feat(contextual-precision): add RetrievedContextData source grouping and fix weighted precision score#2743
Merged
Merged
Conversation
- Add _group_retrieval_contexts() to merge RetrievedContextData chunks by source - Update _calculate_score() to use correct weighted cumulative precision formula - Add import warnings
|
@Ruthwik-Data is attempting to deploy a commit to the Confident AI Team on Vercel. A member of the Team first needs to authorize it. |
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.
Summary
This PR improves
ContextualPrecisionMetricwith two changes:1.
RetrievedContextDatasource groupingAdds a new
_group_retrieval_contexts()method that merges multipleRetrievedContextDatachunks sharing the samesourceinto a single context string. This prevents redundant per-chunk LLM calls and gives the judge model better context by presenting all chunks from the same document together.Before: Each chunk is evaluated independently, even if from the same source.
After: Chunks from the same source are combined under a
Source: <name>header, separated by---.2. Weighted cumulative precision formula fix
Updates
_calculate_score()to correctly implement the WCP formula:1foryes,0otherwise)precision_at_konly for relevant nodesrelevant_nodes_count(not total verdicts)This aligns the implementation with the documented formula in the DeepEval docs.
Changes
deepeval/metrics/contextual_precision/contextual_precision.py_group_retrieval_contexts()method_calculate_score()with correct WCP formulaimport warnings