Skip to content

fix: add INVALID_ENTRY_POINT guard to iterative KnnSearch and RangeSearch#1771

Merged
wxyucs merged 1 commit intoantgroup:0.15from
wxyucs:wxyucs/cherry-pick-1742-to-0.15
Mar 31, 2026
Merged

fix: add INVALID_ENTRY_POINT guard to iterative KnnSearch and RangeSearch#1771
wxyucs merged 1 commit intoantgroup:0.15from
wxyucs:wxyucs/cherry-pick-1742-to-0.15

Conversation

@wxyucs
Copy link
Copy Markdown
Collaborator

@wxyucs wxyucs commented Mar 30, 2026

Summary

Related

@wxyucs wxyucs requested a review from inabao as a code owner March 30, 2026 07:20
Copilot AI review requested due to automatic review settings March 30, 2026 07:20
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a static helper function make_empty_dataset_with_stats to standardize the creation of empty datasets with search statistics in HGraph. This helper is used to replace redundant code in KnnSearch and RangeSearch, and a new early exit check for an invalid entry point was added to KnnSearch. A review comment suggests checking the entry point ID directly from the class member instead of the search_param struct to improve code clarity.

Comment on lines +466 to +468
if (search_param.ep == INVALID_ENTRY_POINT) {
return make_empty_dataset_with_stats();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved clarity, it's better to check this->entry_point_id_ directly rather than initializing search_param and then immediately checking one of its members. This makes the dependency on entry_point_id_ explicit and avoids using a newly assigned struct member for the condition.

        if (this->entry_point_id_ == INVALID_ENTRY_POINT) {
            return make_empty_dataset_with_stats();
        }

@wxyucs wxyucs force-pushed the wxyucs/cherry-pick-1742-to-0.15 branch from 3894ff2 to ddebcad Compare March 30, 2026 07:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Backport fix to prevent crashes in HGraph iterative KnnSearch / RangeSearch when the index is empty and the entry point is invalid.

Changes:

  • Add a shared helper to return an “empty dataset” for early-exit cases.
  • Add INVALID_ENTRY_POINT guards to iterative KnnSearch and to RangeSearch/non-iterative KnnSearch early-exit paths.
  • Replace some DatasetImpl::MakeEmptyDataset() returns with the shared helper.

Comment on lines +44 to +47
SearchStatistics stats;
auto dataset_result = DatasetImpl::MakeEmptyDataset();
dataset_result->Statistics(stats.Dump());
return dataset_result;
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make_empty_dataset_with_stats() introduces two compile-time issues in the current codebase: SearchStatistics is not declared anywhere in the repository, and Dataset/DatasetImpl do not define a Statistics(...) setter, so dataset_result->Statistics(...) cannot compile (the static type is DatasetPtr). Either remove this stats-setting logic, or add the missing statistics type + a Statistics API to include/vsag/dataset.h and implement it in DatasetImpl (and include the proper header here).

Suggested change
SearchStatistics stats;
auto dataset_result = DatasetImpl::MakeEmptyDataset();
dataset_result->Statistics(stats.Dump());
return dataset_result;
return DatasetImpl::MakeEmptyDataset();

Copilot uses AI. Check for mistakes.
Comment on lines +466 to +468
if (search_param.ep == INVALID_ENTRY_POINT) {
return make_empty_dataset_with_stats();
}
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new iterative-KnnSearch guard returns early when entry_point_id_ is invalid, but there’s no regression test covering the iterative-filtering path on an empty/invalid-entry-point HGraph (this PR fixes a reported SIGSEGV). Please add a test that calls the iterator-based KnnSearch(..., IteratorContext*&, ...) against an empty index and asserts it returns an empty dataset without crashing (and that the iterator context handling is correct).

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.

❌ Your patch status has failed because the patch coverage (57.14%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

@@           Coverage Diff           @@
##             0.15    #1771   +/-   ##
=======================================
  Coverage   90.12%   90.13%           
=======================================
  Files         218      218           
  Lines       13537    13538    +1     
=======================================
+ Hits        12200    12202    +2     
+ Misses       1337     1336    -1     
Flag Coverage Δ
cpp 90.13% <57.14%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
common 93.36% <ø> (ø)
datacell 91.30% <ø> (+0.20%) ⬆️
index 88.46% <57.14%> (-0.14%) ⬇️
simd 100.00% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d876ca...4b8b95b. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wxyucs wxyucs added version/0.15 kind/bug Something isn't working labels Mar 31, 2026
@wxyucs wxyucs force-pushed the wxyucs/cherry-pick-1742-to-0.15 branch from 18a4dcf to 39920b8 Compare March 31, 2026 06:28
…arch

Signed-off-by: Xiangyu Wang <wxy407827@antgroup.com>
Copy link
Copy Markdown
Collaborator

@inabao inabao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wxyucs wxyucs merged commit b29a3e0 into antgroup:0.15 Mar 31, 2026
20 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/S version/0.15

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants