Skip to content

feat(contextual-precision): add RetrievedContextData source grouping and fix weighted precision score#2743

Merged
penguine-ip merged 2 commits into
confident-ai:mainfrom
Ruthwik-Data:main
Jun 14, 2026
Merged

feat(contextual-precision): add RetrievedContextData source grouping and fix weighted precision score#2743
penguine-ip merged 2 commits into
confident-ai:mainfrom
Ruthwik-Data:main

Conversation

@Ruthwik-Data

Copy link
Copy Markdown
Contributor

Summary

This PR improves ContextualPrecisionMetric with two changes:

1. RetrievedContextData source grouping

Adds a new _group_retrieval_contexts() method that merges multiple RetrievedContextData chunks sharing the same source into 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:

  • Converts verdicts to binary list (1 for yes, 0 otherwise)
  • Accumulates precision_at_k only for relevant nodes
  • Divides by relevant_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
    • Added _group_retrieval_contexts() method
    • Updated _calculate_score() with correct WCP formula
    • Added import warnings

- Add _group_retrieval_contexts() to merge RetrievedContextData chunks by source
- Update _calculate_score() to use correct weighted cumulative precision formula
- Add import warnings
@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

@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.

@penguine-ip penguine-ip merged commit 583e10f into confident-ai:main Jun 14, 2026
10 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants