fix(ragas): score 0 when Faithfulness gets no statements - #225
Open
fei (feiiiiii5) wants to merge 1 commit into
Open
fei (feiiiiii5) wants to merge 1 commit into
fei (feiiiiii5) wants to merge 1 commit into
Conversation
An LLM judge that returns no statements (or no verdicts for them) left `faithfulness` empty, and the scorer divided by `len(faithfulness)`, so the whole eval run died with a ZeroDivisionError instead of reporting an unfaithful answer. The TypeScript scorer already returns 0 in this case. Guard both the async and sync paths the same way js/ragas.ts does, and cover them with a regression test.
This branch has not been deployed
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.
When the LLM judge returns no statements — or no verdicts for the statements it did return —
Faithfulnessdivided bylen(faithfulness)with an empty list, so a single unfaithful-looking answer killed the whole eval run instead of scoring it:The TypeScript scorer already handles this case, in
js/ragas.ts:This applies the same guard to the Python async and sync paths, so an empty verdict list scores
0and the run continues.Test:
pytest py/autoevals/test_ragas.py -k no_statements— the new test fails on9546b28withZeroDivisionError: division by zeroatpy/autoevals/ragas.py:998(both the sync and async parametrization) and passes on this branch. The rest oftest_ragas.pyis unchanged: 9 of its tests fail identically before and after this branch because they call a real OpenAI model and this environment has no API key.Also ran the repo's configured lint on the two changed files:
black --check(clean),ruff check(clean),codespell(clean).Details
AnswerRelevancyhas the same unguarded division atpy/autoevals/ragas.py:1152(/ len(questions)), but the TypeScript twin is unguarded in the same place, so there is no prior art to point at. I left it alone rather than fold a second, differently-evidenced change into this one.py/autoevals/ragas.py:402(ContextRelevancy,/ len(context)) is likewise unguarded in both languages; that one divides by user input rather than a judge result, so it is a different shape again.