From dbdd63bce56423d0bc3f55cfe28874848a914f0f Mon Sep 17 00:00:00 2001 From: Mengdi Lin Date: Fri, 13 Sep 2024 10:53:32 -0700 Subject: [PATCH] assign_index should default to null (#3855) Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/3855 Laser clients are calling RCQ search with a query size of 1 and the bulk of the overhead came from IndexFlat add/search. With a small query size, using IndexFlatL2 does lots of unnecessary copies to the IndexFlatL2. By default, we should fall back to https://fburl.com/code/jpt236mz branch unless the client overrides `assign_index` with `assign_index_factory`. Reviewed By: bshethmeta Differential Revision: D62644305 fbshipit-source-id: 2434e2b238968304dc5b346637f8ca956e6bd548 --- faiss/impl/residual_quantizer_encode_steps.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/faiss/impl/residual_quantizer_encode_steps.cpp b/faiss/impl/residual_quantizer_encode_steps.cpp index 8db6f9e5f7..802262969a 100644 --- a/faiss/impl/residual_quantizer_encode_steps.cpp +++ b/faiss/impl/residual_quantizer_encode_steps.cpp @@ -664,8 +664,6 @@ void refine_beam_mp( std::unique_ptr assign_index; if (rq.assign_index_factory) { assign_index.reset((*rq.assign_index_factory)(rq.d)); - } else { - assign_index.reset(new IndexFlatL2(rq.d)); } // main loop @@ -701,7 +699,9 @@ void refine_beam_mp( assign_index.get(), rq.approx_topk_mode); - assign_index->reset(); + if (assign_index != nullptr) { + assign_index->reset(); + } std::swap(codes_ptr, new_codes_ptr); std::swap(residuals_ptr, new_residuals_ptr);