fix(evaluators): exclude NaN from aggregate score in FaithfulnessEvaluator and ContextRelevanceEvaluator#11510
Open
Aftabbs wants to merge 1 commit into
Open
Conversation
…uator and ContextRelevanceEvaluator When raise_on_failure=False and one or more LLM calls fail, np_mean/mean over a list containing NaN silently returns NaN for the aggregate score. This means a single failed query poisons the whole batch result with no warning, breaking any downstream code that compares or reports the score. Filter out NaN entries before computing the mean so failed queries are excluded from the aggregate. Log a warning with the count of skipped queries. If all queries fail the aggregate remains NaN (unchanged). Individual scores in individual_scores and results are preserved as NaN for per-query transparency. Fixes deepset-ai#11383
|
@Aftabbs is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Can you please use the template we provide for opening PRs? |
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
When
raise_on_failure=Falseand an LLM call fails,FaithfulnessEvaluatorandContextRelevanceEvaluatoreach mark that query's score asfloat(\"nan\"). Both evaluators then compute the aggregatescoreusingnp_mean/statistics.meanover the full list — including thenanentries. Because NaN propagates through both functions, a single failed query silently poisons the entire batch score with no warning.Fixes #11383
Root Cause
faithfulness.pyline 179 (and the equivalent line incontext_relevance.pyline 185):Changes
haystack/components/evaluators/faithfulness.pynp_mean; log a warning with the count of excluded queries; importmathandlogginghaystack/components/evaluators/context_relevance.pystatistics.mean; importmathandloggingtest/components/evaluators/test_faithfulness_evaluator.pyscore == 1.0(valid only); addtest_run_all_failed_returns_nan_scorefor the all-fail edge casetest/components/evaluators/test_context_relevance_evaluator.pyreleasenotes/notes/fix-evaluator-nan-aggregate-score-*.yamlBehaviour after this fix
scorebeforescoreafternanmean([s1, s3])— correct averagenannan— unchangedindividual_scoresandresults[i]["score"]still preserveNaNfor failed queries so callers can inspect per-query status — this is intentional and compatible with theevaluation_statusesoutput added by PR #11333.Testing
test_run_all_failed_returns_nan_score— verifiesscorestays NaN when all queries failImpact
Users running batch evaluations where some LLM calls fail intermittently no longer get a silent
nanscore that breaks downstream dashboards or comparisons.