feat: add EvaluationResult summary and threshold checks
Problem
Ragas EvaluationResult already computes aggregate metric values internally, but users do not have a clear public method for retrieving aggregate scores. This makes CI evaluation gates and regression checks awkward.
Closes #2760
Changes Made
- Added
EvaluationResult.summary() - Added
EvaluationResult.check_thresholds() - Added
EvaluationResult.assert_thresholds() - Added clear handling for missing metrics, NaN/non-finite scores, non-numeric scores, and invalid threshold configs
- Updated CI docs to use the new public helpers instead of stale
evaluate(..., in_ci=True)guidance
Testing
- Added focused unit tests for summary output, copy behavior, min/max/range thresholds, missing metrics, NaN/non-numeric scores, invalid inputs, assertion behavior, and existing result accessors
- Ran:
.venv/bin/python -m pytest tests/unit/test_evaluation_result.py tests/unit/test_dataset_schema.py.venv/bin/python -m ruff check src/ragas/dataset_schema.py tests/unit/test_evaluation_result.py docs/howtos/applications/add_to_ci.md --config pyproject.tomlgit diff --check
Notes
Repo-wide Pyright currently reports errors in existing untouched areas, so this PR was verified with focused tests and linting for the changed files.
✅ No documentation update needed — New public methods include docstrings (API docs auto-generated) and the PR already updates the relevant how-to guide (add_to_ci.md) to demonstrate the new threshold/summary API.
Note on type checks: focused tests, Ruff, and diff checks pass for this PR. Repo-wide Pyright currently reports existing errors in untouched areas, so I verified this change with focused tests and linting for the modified files.
Added relative_thresholds param (suggested by @ferhimedamine):
report = result.check_thresholds(
relative_thresholds={faithfulness: 0.05},
baseline_scores={faithfulness: 0.85},
)
Also available in assert_thresholds():
result.assert_thresholds(
relative_thresholds={faithfulness: 0.05},
baseline_scores={faithfulness: 0.85},
)
The effective bounds are computed as baseline ± (baseline * relative). Each metric in relative_thresholds must have a corresponding entry in baseline_scores. Relative values must be between 0 and 1.
✅ No documentation update needed — New public methods have complete docstrings (auto-generated API docs) and the PR already updates the relevant how-to guide (add_to_ci.md) to demonstrate the new threshold/summary API. No further documentation needed.