Skip to content

Commit 17fbeb8

Browse files
Improve filtering & search parameters propagation (facebookresearch#3304)
Summary: Pull Request resolved: facebookresearch#3304 Reviewed By: junjieqi Differential Revision: D55823369 Pulled By: mdouze fbshipit-source-id: c0e9f4b85d979758f02e9953f3706b63a846bf22
1 parent 252ae16 commit 17fbeb8

5 files changed

+289
-116
lines changed

faiss/IVFlib.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,10 @@ void search_with_parameters(
352352
const IndexIVF* index_ivf = dynamic_cast<const IndexIVF*>(index);
353353
FAISS_THROW_IF_NOT(index_ivf);
354354

355-
index_ivf->quantizer->search(n, x, params->nprobe, Dq.data(), Iq.data());
355+
SearchParameters* quantizer_params =
356+
(params) ? params->quantizer_params : nullptr;
357+
index_ivf->quantizer->search(
358+
n, x, params->nprobe, Dq.data(), Iq.data(), quantizer_params);
356359

357360
if (nb_dis_ptr) {
358361
*nb_dis_ptr = count_ndis(index_ivf, n * params->nprobe, Iq.data());

faiss/IndexFastScan.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ void estimators_from_tables_generic(
189189
dt += index.ksub;
190190
}
191191
}
192+
192193
if (C::cmp(heap_dis[0], dis)) {
193194
heap_pop<C>(k, heap_dis, heap_ids);
194195
heap_push<C>(k, heap_dis, heap_ids, dis, j);
@@ -203,17 +204,18 @@ ResultHandlerCompare<C, false>* make_knn_handler(
203204
idx_t k,
204205
size_t ntotal,
205206
float* distances,
206-
idx_t* labels) {
207+
idx_t* labels,
208+
const IDSelector* sel = nullptr) {
207209
using HeapHC = HeapHandler<C, false>;
208210
using ReservoirHC = ReservoirHandler<C, false>;
209211
using SingleResultHC = SingleResultHandler<C, false>;
210212

211213
if (k == 1) {
212-
return new SingleResultHC(n, ntotal, distances, labels);
214+
return new SingleResultHC(n, ntotal, distances, labels, sel);
213215
} else if (impl % 2 == 0) {
214-
return new HeapHC(n, ntotal, k, distances, labels);
216+
return new HeapHC(n, ntotal, k, distances, labels, sel);
215217
} else /* if (impl % 2 == 1) */ {
216-
return new ReservoirHC(n, ntotal, k, 2 * k, distances, labels);
218+
return new ReservoirHC(n, ntotal, k, 2 * k, distances, labels, sel);
217219
}
218220
}
219221

0 commit comments

Comments
 (0)