Repository navigation
fix(evaluations): account for score duplication in evaluator stats and fix max_items deduplication - #2103
fix(evaluations): account for score duplication in evaluator stats and fix max_items deduplication#2103viliamgonda wants to merge 1 commit into
Conversation
|
|
||
| while True: | ||
| if max_items is not None and total_items_fetched >= max_items: | ||
| if max_items is not None and total_items_processed >= max_items: |
There was a problem hiding this comment.
max_items now counts only successful items. If the mapper raises or score creation fails, total_items_failed increases but the runner keeps fetching replacements. With max_items=1 and a mapper that fails for every item, the runner attempts the entire matching dataset instead of stopping after one item. This can greatly extend runtime and work done by the mapper or evaluators.
Count successful and failed unique items toward the limit, while excluding skipped duplicates.
Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/batch_evaluation.py
Line: 945
Comment:
**Failed items bypass the limit**
`max_items` now counts only successful items. If the mapper raises or score creation fails, `total_items_failed` increases but the runner keeps fetching replacements. With `max_items=1` and a mapper that fails for every item, the runner attempts the entire matching dataset instead of stopping after one item. This can greatly extend runtime and work done by the mapper or evaluators.
Count successful and failed unique items toward the limit, while excluding skipped duplicates.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| result = await run(runner, max_items=3, fetch_batch_size=2) | ||
|
|
||
| assert result.total_items_processed == 3 | ||
| assert set(result.item_evaluations.keys()) == {"obs-1", "obs-2", "obs-3"} |
There was a problem hiding this comment.
Test never reaches the duplicate
The fake API sorts these rows as obs-3, obs-2, obs-1, duplicate, obs-0. With max_items=3, the runner fetches two rows and then one row, so it stops before fetching the duplicate. Both the old and new code pass, leaving the pagination fix unguarded.
Use max_items=4 and assert all four unique items are processed, or move the duplicate into a page fetched before the limit.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/unit/test_batch_evaluation.py
Line: 435-438
Comment:
**Test never reaches the duplicate**
The fake API sorts these rows as `obs-3`, `obs-2`, `obs-1`, duplicate, `obs-0`. With `max_items=3`, the runner fetches two rows and then one row, so it stops before fetching the duplicate. Both the old and new code pass, leaving the pagination fix unguarded.
Use `max_items=4` and assert all four unique items are processed, or move the duplicate into a page fetched before the limit.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
…d fix max_items deduplication
842213f to
2155ee3
Compare
Fixes langfuse/langfuse#19610.
Summary
This fixes two interrelated accounting and pagination boundary issues in
BatchEvaluationRunner.run_async:EvaluatorStats Score Count Accounting:
When
_add_observation_scores_to_trace=True,_create_scorecreates two distinct score records in Langfuse (one on the observation and one duplicated onto the parent trace), andresult.total_scores_createdincrements by 2 per evaluation. However,stats.total_scores_createdwas incremented bylen(eval_results)(1 per evaluation), causing per-evaluator score counts to report half of the actual scores created.len(eval_results)by2 if _add_observation_scores_to_trace else 1when updatingstats.total_scores_created, ensuring per-evaluator stats align withresult.total_scores_created.max_itemsPremature Halting on Deduplicated Pages:In
run_async, page clamping and loop termination were checked againsttotal_items_fetched >= max_itemsrather than processed items. When ClickHouse page boundary duplicates or resumed items were skipped via_deduplicate_page,total_items_fetchedreachedmax_itemsearly, terminating the loop beforetotal_items_processedreachedmax_items.total_items_processed >= max_items, calculates page limit asmin(limit, max_items - total_items_processed), and clampsitems_to_processto remaining needed items.Verification
uv run pytest tests/unit/test_batch_evaluation.py: 18/18 passed.max_items.uv run ruff check langfuse/batch_evaluation.py tests/unit/test_batch_evaluation.py: All checks passed.uv run ruff format --check langfuse/batch_evaluation.py tests/unit/test_batch_evaluation.py: Clean.uv run mypy langfuse/batch_evaluation.py: Success, no issues found.Fix the failed-item limit before merging so bounded runs cannot attempt the entire dataset.
Summary
This PR counts trace-level score copies in evaluator statistics and lets pagination continue past skipped duplicates.
Reviews (1) · Last reviewed commit: "fix(evaluations): account for score dupl..." · Reviewed by Greptile