From 720b41def96cda787134e9e76e3ef164c073b280 Mon Sep 17 00:00:00 2001 From: WeiLiuu <103909074+WeiLiuu@users.noreply.github.com> Date: Fri, 27 Nov 2026 23:45:43 +0800 Subject: [PATCH] fix(eval): pass cases that meet the pass@k threshold Count subsets containing a pass before dividing so pass@1 meets the threshold when one of five runs passes. --- .../_multi_run_aggregation_methods.py | 3 ++- ...t_eval_case_result_multi_run_aggregator.py | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/google/adk/evaluation/_multi_run_aggregation_methods.py b/src/google/adk/evaluation/_multi_run_aggregation_methods.py index 52f3ee1c317..29467cfe22b 100644 --- a/src/google/adk/evaluation/_multi_run_aggregation_methods.py +++ b/src/google/adk/evaluation/_multi_run_aggregation_methods.py @@ -239,7 +239,8 @@ def pass_at_k(runs: Sequence[RunResult], k: int) -> float | None: decided, passed = _count_decided_and_passed(runs) if decided < k: return None - return 1.0 - math.comb(decided - passed, k) / math.comb(decided, k) + total = math.comb(decided, k) + return (total - math.comb(decided - passed, k)) / total def pass_hat_k(runs: Sequence[RunResult], k: int) -> float | None: diff --git a/tests/unittests/evaluation/test_eval_case_result_multi_run_aggregator.py b/tests/unittests/evaluation/test_eval_case_result_multi_run_aggregator.py index aa2fdc3275e..1875065a051 100644 --- a/tests/unittests/evaluation/test_eval_case_result_multi_run_aggregator.py +++ b/tests/unittests/evaluation/test_eval_case_result_multi_run_aggregator.py @@ -1804,6 +1804,30 @@ def test_pass_k_criteria_without_threshold_only_report(): assert aggregated.final_eval_status == EvalStatus.PASSED +def test_pass_at_one_meets_one_in_five_threshold() -> None: + runs = [ + _judged_run(i, a=score) + for i, score in enumerate([1.0, 0.0, 0.0, 0.0, 0.0]) + ] + multi_run_config = MultiRunConfig( + cross_run_scoring=MultiRunCriterion(method="pass_rate", threshold=0.2), + cross_run_criteria=[ + PassKMultiRunCriterion(method="pass_at_k", k=1, threshold=0.2) + ], + ) + + (aggregated,) = aggregate_eval_case_results( + runs, multi_run_config=multi_run_config + ) + + (result,) = aggregated.cross_run_results + assert (result.value, result.status, aggregated.final_eval_status) == ( + 0.2, + EvalStatus.PASSED, + EvalStatus.PASSED, + ) + + def test_pass_hat_k_with_threshold_fails_the_case_below_it(): """A pass^k criterion with a threshold judges the case like pass_rate.""" multi_run_config = MultiRunConfig(