From b59a8fee6987c5a0abe063d8c08f8ec8589ddf88 Mon Sep 17 00:00:00 2001 From: Emy Sun Date: Tue, 13 Aug 2024 13:40:55 -0700 Subject: [PATCH] Add hnsw search params for bounded queue option (#3748) Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/3748 So we can dynamically change it Reviewed By: asadoughi Differential Revision: D61029191 --- faiss/impl/HNSW.cpp | 5 ++++- faiss/impl/HNSW.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/faiss/impl/HNSW.cpp b/faiss/impl/HNSW.cpp index 3ba5f72f68..277e194b3e 100644 --- a/faiss/impl/HNSW.cpp +++ b/faiss/impl/HNSW.cpp @@ -847,6 +847,9 @@ HNSWStats HNSW::search( } int k = extract_k_from_ResultHandler(res); + bool bounded_queue = + params ? params->bounded_queue : this->search_bounded_queue; + if (upper_beam == 1) { // greedy search on upper levels storage_idx_t nearest = entry_point; @@ -857,7 +860,7 @@ HNSWStats HNSW::search( } int ef = std::max(params ? params->efSearch : efSearch, k); - if (search_bounded_queue) { // this is the most common branch + if (bounded_queue) { // this is the most common branch MinimaxHeap candidates(ef); candidates.push(nearest, d_nearest); diff --git a/faiss/impl/HNSW.h b/faiss/impl/HNSW.h index f3aacf8a5b..5916922360 100644 --- a/faiss/impl/HNSW.h +++ b/faiss/impl/HNSW.h @@ -46,6 +46,7 @@ struct ResultHandler; struct SearchParametersHNSW : SearchParameters { int efSearch = 16; bool check_relative_distance = true; + bool bounded_queue = true; ~SearchParametersHNSW() {} };