Skip to content
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

wip: [do not review] improve hnsw iterator #528

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions thirdparty/hnswlib/hnswlib/hnswalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,13 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
for (int i = 0; i < retset.size(); i++) {
workspace->dists.emplace_back(retset[i].id, retset[i].distance);
}
// unvisited invalid nodes should be added to to_visit to ensure conectivity
while (retset.has_next()) {
auto n = retset.pop();
if (n.status == Neighbor::kInvalid) {
workspace->to_visit.push(n);
}
}
workspace->initial_search_done = true;
return;
}
Expand Down
4 changes: 3 additions & 1 deletion thirdparty/hnswlib/hnswlib/neighbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ class NeighborSetDoublePopList {
if (hasCandNext != hasResNext) {
return hasCandNext ? invalid_ns_->pop() : valid_ns_->pop();
}
return {0, 0, Neighbor::kValid};
// caller must always check has_next() before calling pop(), reaching
// here means a bug in the implementation.
throw std::runtime_error("No more elements to pop");
}

std::unique_ptr<NeighborSetPopList<true>> valid_ns_ = nullptr;
Expand Down
Loading