Repository navigation
fix: coerce None filter_rate in Label/Int Filter charts #851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jamesgao-jpg
merged 2 commits into
zilliztech:main
from
daviddallakyan2005:filter-rate-none-crash
Sep 10, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import pytest | ||
|
|
||
| from vectordb_bench.backend.cases import CaseType, PerformanceCustomDataset | ||
| from vectordb_bench.backend.filter import LabelFilter | ||
| from vectordb_bench.models import CaseConfig | ||
|
|
||
|
|
||
| def _custom_case_kwargs(**overrides): | ||
| kwargs = { | ||
| "name": "custom-ds", | ||
| "description": "", | ||
| "load_timeout": 1.0, | ||
| "optimize_timeout": 1.0, | ||
| "dataset_config": { | ||
| "name": "custom-ds", | ||
| "dir": "/tmp/custom-ds", | ||
| "size": 1000, | ||
| "dim": 128, | ||
| "metric_type": "L2", | ||
| "file_count": 1, | ||
| }, | ||
| } | ||
| kwargs.update(overrides) | ||
| return kwargs | ||
|
|
||
|
|
||
| def test_custom_dataset_filter_sets_filter_rate_from_label_percentage(): | ||
| case = PerformanceCustomDataset(**_custom_case_kwargs(use_filter=True, label_percentage=0.01)) | ||
| assert case.filter_rate == pytest.approx(0.99) | ||
| assert isinstance(case.filters, LabelFilter) | ||
| assert case.filters.filter_rate == pytest.approx(0.99) | ||
|
|
||
|
|
||
| def test_custom_dataset_filter_matches_label_filter_formula(): | ||
| case = PerformanceCustomDataset(**_custom_case_kwargs(use_filter=True, label_percentage=0.2)) | ||
| assert case.filter_rate == pytest.approx(LabelFilter(label_percentage=0.2).filter_rate) | ||
|
|
||
|
|
||
| def test_custom_dataset_without_filter_leaves_filter_rate_unset(): | ||
| case = PerformanceCustomDataset(**_custom_case_kwargs(use_filter=False)) | ||
| assert case.filter_rate is None | ||
|
|
||
|
|
||
| def test_case_config_builds_custom_dataset_with_filter_rate(): | ||
| case = CaseConfig( | ||
| case_id=CaseType.PerformanceCustomDataset, | ||
| custom_case=_custom_case_kwargs(use_filter=True, label_percentage=0.5), | ||
| ).case | ||
| assert case.filter_rate == pytest.approx(0.5) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| from vectordb_bench.frontend.components.int_filter import charts as int_charts | ||
| from vectordb_bench.frontend.components.label_filter import charts as label_charts | ||
|
|
||
| NONE_FILTER_DATA = [ | ||
| { | ||
| "filter_rate": None, | ||
| "qps": 10.0, | ||
| "recall": 0.9, | ||
| "db_name": "A", | ||
| "dataset_name": "custom", | ||
| }, | ||
| { | ||
| "filter_rate": 0.99, | ||
| "qps": 20.0, | ||
| "recall": 0.8, | ||
| "db_name": "B", | ||
| "dataset_name": "custom", | ||
| }, | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("charts", [label_charts, int_charts]) | ||
| def test_get_range_coerces_none_filter_rate(charts): | ||
| data = [{"filter_rate": None}, {"filter_rate": 0.5}] | ||
| xrange = charts.getRange("filter_rate", data, [0.05, 0.1]) | ||
| assert xrange[0] <= 0 | ||
| assert xrange[1] >= 0.5 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("charts", [label_charts, int_charts]) | ||
| def test_draw_chart_does_not_crash_when_filter_rate_is_none(charts): | ||
| st = MagicMock() | ||
| with patch.object(charts, "px") as px: | ||
| px.line.return_value = MagicMock() | ||
| charts.drawChart(st, list(NONE_FILTER_DATA), "qps") | ||
| px.line.assert_called_once() | ||
| st.plotly_chart.assert_called_once() |
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two small notes on this coercion (identical in int_filter/charts.py):
A one-line rationale comment would help —
d.get(metric) or 0is easy to "simplify" back tod.get(metric, 0), which reintroduces the crash for present-but-None values.For the legacy
filter_rate=Nonerows this is meant to keep rendering: plotly converts None x to NaN, so the point is dropped from the line (not drawn at 0), while the axis still extends to 0. The run is invisible rather than misplaced. Once the producers are fixed (see comment on cases.py:442) this path is mostly unreachable; consider dropping unknown rows before the axis computation instead of padding the range with 0.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment that dict.get(metric, 0) still returns None when the key is present. I left the coerce in place so leftover result files with filter_rate=None still do not TypeError on min or sort. Dropping those rows would change the axis for mixed leftover files, which I left out of this follow-up.