Skip to content

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

Merged
wxyucs merged 2 commits intoantgroup:0.16from
wxyucs:wxyucs/cherry-pick-1742-to-0.16
Mar 31, 2026
Merged

fix: add INVALID_ENTRY_POINT guard to iterative KnnSearch and RangeSearch#1772
wxyucs merged 2 commits intoantgroup:0.16from
wxyucs:wxyucs/cherry-pick-1742-to-0.16

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:21
Copilot AI review requested due to automatic review settings March 30, 2026 07:21
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 helper function make_empty_dataset_with_stats to ensure that empty search results include search statistics. This helper is integrated into KnnSearch, RangeSearch, and SearchWithRequest. Feedback suggests updating an additional early exit condition in KnnSearch to use this new helper for better consistency.

Comment on lines 357 to 359
if (cur_count == 0) {
auto dataset_result = DatasetImpl::MakeEmptyDataset();
return dataset_result;
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

While this change correctly returns an empty dataset with statistics when cur_count is 0, there's an earlier check in this function (around line 322): if (GetNumElements() == 0). This check returns an empty dataset without statistics, which makes the behavior for an empty index inconsistent. To ensure the fix is complete, that initial check should also be updated to use make_empty_dataset_with_stats().

…arch

Signed-off-by: Xiangyu Wang <wxy407827@antgroup.com>
@wxyucs wxyucs force-pushed the wxyucs/cherry-pick-1742-to-0.16 branch from ca68170 to a5391fd 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

This PR backports a fix to prevent iterative KnnSearch and RangeSearch from crashing when the HGraph entry point is invalid (notably on empty indexes), and introduces a shared helper intended to return an empty dataset while preserving search statistics.

Changes:

  • Add make_empty_dataset_with_stats() helper for empty-result returns.
  • Guard iterative KnnSearch against INVALID_ENTRY_POINT.
  • Guard RangeSearch against INVALID_ENTRY_POINT.

Comment on lines +45 to +48
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() currently won't compile on this branch: SearchStatistics is not defined anywhere in the repository, and vsag::Dataset/DatasetImpl has no Statistics(...) member (see include/vsag/dataset.h). Either backport the missing statistics types/APIs along with this change, or remove the statistics plumbing and just return DatasetImpl::MakeEmptyDataset() 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 550 to +557
InnerSearchParam search_param;
search_param.ep = this->entry_point_id_;
search_param.topk = 1;
search_param.ef = 1;

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.

HGraph::RangeSearch still doesn't take global_mutex_ as a shared lock, unlike KnnSearch/SearchWithRequest. Since RangeSearch reads entry_point_id_ and iterates route_graphs_ (which are mutated under global_mutex_ during add/resize), this is a data race under the advertised concurrent add/search features; the new INVALID_ENTRY_POINT guard doesn’t address that. Consider adding a std::shared_lock on global_mutex_ before reading entry_point_id_ / traversing graphs.

Copilot uses AI. Check for mistakes.
Signed-off-by: Xiangyu Wang <wxy407827@antgroup.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 25.00000% with 6 lines in your changes missing coverage. Please review.

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

@@            Coverage Diff             @@
##             0.16    #1772      +/-   ##
==========================================
- Coverage   92.24%   92.07%   -0.17%     
==========================================
  Files         295      295              
  Lines       15714    15718       +4     
==========================================
- Hits        14496    14473      -23     
- Misses       1218     1245      +27     
Flag Coverage Δ
cpp 92.07% <25.00%> (-0.17%) ⬇️

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

Components Coverage Δ
common 92.66% <ø> (ø)
datacell 91.97% <ø> (-0.05%) ⬇️
index 91.18% <25.00%> (-0.29%) ⬇️
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 681e944...f582aa0. 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.16 kind/bug Something isn't working labels Mar 31, 2026
@wxyucs wxyucs self-assigned this Mar 31, 2026
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

Copy link
Copy Markdown
Collaborator

@LHT129 LHT129 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 f9030e8 into antgroup:0.16 Mar 31, 2026
29 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.16

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants