Repository navigation
fix(vectordb): propagate native search failure instead of reporting count 0 - #5890
Open
akushonkamen wants to merge 1 commit into
Open
akushonkamen wants to merge 1 commit into
akushonkamen wants to merge 1 commit into
Conversation
…ount 0
On the local vector backend, a count whose filter referenced a scalar
value that was never inserted took the engine error path: the filter
bitmap could not be computed, IndexManagerImpl::search returned -1
before the counter ran, and IndexEngine::search discarded that return
code. The empty SearchResult reached Python with no extra_json, where
LocalIndex.aggregate() logged "Aggregation results not available:
extra_json is empty" and returned {}, and
LocalCollection.aggregate_data filled in _total: 0 — rendering a failed
aggregation indistinguishable from a legitimate zero (the agent-evolution
count endpoints showed all-zero distributions per call).
- IndexEngine::search now checks the native return code and throws,
mirroring search_with_filter_token and evaluate_filter.
- FieldBitmapGroupSet::make_field_copy (single key) now returns an empty
bitmap when the field or value was never inserted, so a valid no-match
filter yields an explicit __total_count__=0 — the same semantics the
multi-key variant and path filters already had — instead of a null
bitmap treated as an engine failure.
- LocalIndex.aggregate() no longer launders failures into {}: native
search errors are re-raised, and a served search without an aggregation
payload raises RuntimeError, so callers can distinguish "unavailable"
from zero.
Regression tests: tests/vectordb/test_local_aggregate_missing_value.py.
Known adjacent issues, intentionally unchanged here: parse_dsl_query
silently drops a filter op that fails to parse (the count then proceeds
unfiltered), and a non-object "sorter" value crashes the sorter parser;
both predate this change.
Fixes volcengine#5877
AI assistance: change developed with a GLM coding agent under the
direction of akushonkamen, who reviewed, built, and tested it locally.
Signed-off-by: akushonkamen <akushonkamen@163.com>
11 of 21 tasks
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.
Description
本地向量后端上,当 count/aggregate 的 filter 引用一个从未插入过的标量值时,聚合失败被逐层"洗"成合法的零:agent-evolution 各 count 端点每次调用返回全零分布,并打
Aggregation results not available: extra_json is emptywarning,与"真没数据"不可区分。根因(三层叠加,均在本机源码逐层亲验 @ 4c9a755):
get_bitmap_copy返回 nullptr,src/index/detail/index_manager_impl.cpp:188返回 -1,计数器未运行);而IndexEngine::search(src/index/index_engine.cpp:14-19)丢弃impl_->search的返回码,空SearchResult被当作合法结果继续上抛。同文件姊妹方法search_with_filter_token/evaluate_filter均检查 ret 非 0 即 throw——缺检查是不一致,非设计。SearchResult(无extra_json)到达 Python 后,LocalIndex.aggregate()(openviking/storage/vectordb/index/local_index.py)把聚合异常吞成return {},空extra_json仅 warning 后同样return {}。LocalCollection.aggregate_data对无__total_count__的聚合静默填_total: 0。修法(三处,对应三层):
IndexEngine::search检查 ret 非 0 即throw std::runtime_error("Failed to search the native index")(照抄同文件search_with_filter_token/evaluate_filter先例)——原生失败不再被伪装成空结果;FieldBitmapGroupSet::make_field_copy对从未插入的 field/value 返回空位图而非 nullptr,使合法"无匹配"产出显式__total_count__=0(与同函数多 key 分支及 path 过滤既有语义对齐),不再走引擎错误路径;LocalIndex.aggregate()不再吞错——原生失败 re-raise、成功但无聚合 payload 抛RuntimeError,上层(local_collection → adapter.count)随之以异常区分"不可用"与"真零"。Human Involvement
akushonkamen 全程指导方案分层(Layer 1 机械传播错误 / Layer 2 空 bitmap 语义对齐)、review 每一版 diff、本机构建与测试验收。
Related Issue
Fixes #5877
认领评论:#5877 (comment) (含与 r266-tech trace 的协调切分);跟进评论:#5877 (comment)
Type of Change
Changes Made
src/index/index_engine.cpp:IndexEngine::search检查impl_->search返回码,非 0 即 throw(+5/-1)。src/index/detail/scalar/bitmap_holder/bitmap_field_group.cpp:单 keymake_field_copy对未插入 field/value 返回空位图(+12/-2),合法无匹配 → 显式 0。openviking/storage/vectordb/index/local_index.py:aggregate()三处return {}改为raise/RuntimeError(+13/-7),不再把失败洗成空聚合。tests/vectordb/test_local_aggregate_missing_value.py:新增 7 个回归用例(+187),覆盖红→绿行为与对照路径。Testing
红→绿实证(全部实跑,macOS arm64,重编原生后执行):
红(未修改 HEAD 4c9a755):
timeout 120 .venv/bin/python /tmp/ov5877_repro.py→count(never-inserted value)=_total:0+Aggregation results not available: extra_json is emptywarning(对照组 未过滤=3 / 已索引值=2 / 空交集=0 无警告,全部正常——positive control 成立,证明只有"值从未插入"触发错误路径)。红→绿:
git stash两处 C++ 改动并重编后timeout 300 .venv/bin/python -m pytest tests/vectordb/test_local_aggregate_missing_value.py -q→3 failed, 4 passed;恢复重编后同命令 →7 passed。绿(最终轮):
timeout 300 .venv/bin/python -m pytest tests/vectordb/test_local_aggregate_missing_value.py -q→7 passedtimeout 300 .venv/bin/python -m pytest tests/unit -k "aggregate or count" -q --no-cov→38 passed, 6 skippedtimeout 590 .venv/bin/python -m pytest tests/unit/service -q --no-cov→37 passed, 2 failed(test_core_consistency::test_service_passes_queue_worker_concurrency_to_storage与test_core_encryption_startup::test_build_ragfs_binding_config_works_inside_running_event_loop;经git stash后在干净 HEAD 复跑同样 2 failed,确证为与本修复无关的既有失败)timeout 400 .venv/bin/python -m pytest tests/vectordb/test_engine_filter_packed_native_abi.py tests/vectordb/test_filter_ops.py tests/vectordb/test_engine_filter_routing_abi.py -q --no-cov→37 passed原生生效路径 engine 层直验:非法 JSON DSL →
RuntimeError('Failed to search the native index');count(已索引值) →{__total_count__: 2};count(缺失值) →{__total_count__: 0}(显式零,无 warning)。lint:
ruff check/ruff format --check对改动 py 文件通过;clang-format 检查显示两 C++ 文件在 HEAD 本就大量不合规(111/429 行),本 PR 改动行无新增违规。提交前 sanity 复跑:
timeout 300 .venv/bin/python -m pytest tests/vectordb/test_local_aggregate_missing_value.py -q --no-cov→7 passed(fetch 后 main 未前进 @ 4c9a755,无 rebase)。未跑:
tests/vectordb/test_collection_large_scale.py(50K 压力级,超出本单点名范围)。I have added tests that prove my fix is effective or that my feature works
New and existing unit tests pass locally with my changes(唯一失败为上述 2 个既有失败,stash 复证与本修复无关)
I have tested this on the following platforms:
Checklist
Screenshots (if applicable)
不适用。
Additional Notes
parse_dsl_query静默丢弃 parse 失败的 filter op(count 随后无过滤进行);非对象 sorter 值使原生解析器段错误(在未修改 4c9a755 原生上隔离子进程复现,确证非本修复引入)。Signed-off-by与 AI assistance 说明。