Skip to content

fix(vectordb): propagate native search failure instead of reporting count 0 - #5890

Open
akushonkamen wants to merge 1 commit into
volcengine:mainfrom
akushonkamen:fix/5877-native-search-failure
Open

akushonkamen wants to merge 1 commit into
volcengine:mainfrom
akushonkamen:fix/5877-native-search-failure

Conversation

@akushonkamen

Copy link
Copy Markdown
Contributor

Description

本地向量后端上,当 count/aggregate 的 filter 引用一个从未插入过的标量值时,聚合失败被逐层"洗"成合法的零:agent-evolution 各 count 端点每次调用返回全零分布,并打 Aggregation results not available: extra_json is empty warning,与"真没数据"不可区分。

根因(三层叠加,均在本机源码逐层亲验 @ 4c9a755):

  1. C++ 引擎错误路径:filter 位图算不出(引用从未插入的 field/value 时 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——缺检查是不一致,非设计。
  2. Python 聚合层吞错:空 SearchResult(无 extra_json)到达 Python 后,LocalIndex.aggregate()(openviking/storage/vectordb/index/local_index.py)把聚合异常吞成 return {},空 extra_json 仅 warning 后同样 return {}。
  3. 上层填零: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 先例)——原生失败不再被伪装成空结果;
  • 单 key FieldBitmapGroupSet::make_field_copy 对从未插入的 field/value 返回空位图而非 nullptr,使合法"无匹配"产出显式 __total_count__=0(与同函数多 key 分支及 path 过滤既有语义对齐),不再走引擎错误路径;
  • LocalIndex.aggregate() 不再吞错——原生失败 re-raise、成功但无聚合 payload 抛 RuntimeError,上层(local_collection → adapter.count)随之以异常区分"不可用"与"真零"。

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

akushonkamen 全程指导方案分层(Layer 1 机械传播错误 / Layer 2 空 bitmap 语义对齐)、review 每一版 diff、本机构建与测试验收。

Related Issue

Fixes #5877

认领评论:#5877 (comment) (含与 r266-tech trace 的协调切分);跟进评论:#5877 (comment)

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

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:单 key make_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 empty warning(对照组 未过滤=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 passed
    • timeout 300 .venv/bin/python -m pytest tests/unit -k "aggregate or count" -q --no-cov → 38 passed, 6 skipped
    • timeout 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:

    • Linux
    • macOS
    • Windows

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

不适用。

Additional Notes

  • 附带发现并已在 issue 报告(未修,超出本单范围):parse_dsl_query 静默丢弃 parse 失败的 filter op(count 随后无过滤进行);非对象 sorter 值使原生解析器段错误(在未修改 4c9a755 原生上隔离子进程复现,确证非本修复引入)。
  • AI 披露:本修复由 GLM coding agent 在 akushonkamen 指导与复核下开发;commit 已带 Signed-off-by 与 AI assistance 说明。

…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>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel Core server, runtime, storage, retrieval, SDK, and CLI.

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

[Bug]: agent-evolution count endpoints render all-zero and log "Aggregation results not available: extra_json is empty" per call (local backend)

2 participants