fix: IVF nprobe selected list scanning (#544)

This commit is contained in:
egolearner
2026-07-03 17:17:37 +08:00
committed by GitHub
parent 59e04ae4cc
commit 54340bb705
4 changed files with 114 additions and 71 deletions
+1 -1
View File
@@ -226,7 +226,7 @@ int IVFSearcher::search_impl(const void *query, const IndexQueryMeta &qmeta,
auto &context_stats = ctx->mutable_stats(q);
auto &heap = ctx->mutable_result_heap();
heap.clear();
uint32_t total_scan_count = 0;
size_t total_scan_count = 0;
for (size_t i = 0;
i < centroids.size() && total_scan_count < ctx->max_scan_count();
++i) {
@@ -82,15 +82,10 @@ class IVFSearcherContext : public IndexSearcher::Context {
centroid_searcher_ctx_->set_topk(topk_val);
// When nprobe is explicitly set, scale max_scan_count proportionally
// to ensure all probed clusters can be fully scanned.
// When nprobe is explicitly set, lift max_scan_count to the total vector
// count to ensure all selected clusters can be fully scanned.
if (nprobe > 0 && entity_->inverted_list_count() > 0) {
uint32_t list_count =
static_cast<uint32_t>(entity_->inverted_list_count());
max_scan_count_ = static_cast<uint32_t>(
(static_cast<uint64_t>(entity_->vector_count()) * nprobe +
list_count - 1) /
list_count);
max_scan_count_ = static_cast<uint32_t>(entity_->vector_count());
} else {
max_scan_count_ = static_cast<uint32_t>(
std::ceil(entity_->vector_count() * scan_ratio_));
+1 -1
View File
@@ -226,7 +226,7 @@ int IVFStreamer::search_impl(const void *query, const IndexQueryMeta &qmeta,
auto &context_stats = ctx->mutable_stats(q);
auto &heap = ctx->mutable_result_heap();
heap.clear();
uint32_t total_scan_count = 0;
size_t total_scan_count = 0;
for (size_t i = 0;
i < centroids.size() && total_scan_count < ctx->max_scan_count();
++i) {