Skip to content
Open
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
12 changes: 12 additions & 0 deletions include/svs/index/vamana/dynamic_search_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ template <typename Idx, typename Cmp = std::less<>> class MutableBuffer {
best_unvisited_ = 0;
}

/// Keep only the ids now in the buffer in the visited set, so dropped ids can be
/// re-inserted.
void reset_visited_to_contents() {
if (!visited_set_enabled()) {
return;
}
visited_->reset();
for (const auto& neighbor : candidates_) {
visited_->emplace(neighbor.id());
}
}

size_t capacity() const { return candidates_.capacity(); }

/// @brief Return the number of valid elements currently contained in the buffer.
Expand Down
2 changes: 2 additions & 0 deletions include/svs/index/vamana/iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ template <std::integral I> struct RestartInitializer {
return;
}

// Let ids dropped from the buffer be inserted again in the larger window.
buffer.reset_visited_to_contents();
// Otherwise, sort the buffer to prepare for the next search.
buffer.sort();
}
Expand Down
12 changes: 12 additions & 0 deletions include/svs/index/vamana/search_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,18 @@ template <typename Idx, typename Cmp = std::less<>> class SearchBuffer {
best_unvisited_ = 0;
}

/// Keep only the ids now in the buffer in the visited set, so dropped ids can be
/// re-inserted.
void reset_visited_to_contents() {
if (!visited_set_enabled()) {
return;
}
visited_->reset();
for (size_t i = 0; i < size_; ++i) {
visited_->emplace(candidates_[i].id());
}
}

/// @brief Return the current number of valid elements in the buffer.
size_t size() const { return size_; }

Expand Down
Loading