mirror of
https://github.com/facebookresearch/faiss.git
synced 2026-10-12 02:13:36 +00:00
Search params c_api implementation (#2732)
Summary: https://github.com/facebookresearch/faiss/issues/2727 Implements search_with_params function on c_api for index. Implemented c_api equivalents of SearchParameters and SearchParametersIVF. My C/C++ is pretty rusty so I imagine my arguments to the new functions for each search parameters could be refined. Happy to take suggestions :) Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2732 Reviewed By: alexanderguzhva Differential Revision: D43917264 Pulled By: mdouze fbshipit-source-id: c9eaf0d96ec0fad4862528aac9b5946294f5e444
This commit is contained in:
committed by
Facebook GitHub Bot
parent
52dee5c307
commit
24758fb27d
@@ -17,6 +17,7 @@
|
||||
#include "Index_c.h"
|
||||
#include "clone_index_c.h"
|
||||
#include "error_c.h"
|
||||
#include "impl/AuxIndexStructures_c.h"
|
||||
#include "index_factory_c.h"
|
||||
#include "index_io_c.h"
|
||||
|
||||
@@ -92,6 +93,27 @@ int main() {
|
||||
free(I);
|
||||
free(D);
|
||||
}
|
||||
{ // search xb first 5 but search parameters of id range [50, 100]
|
||||
idx_t* I = malloc(k * nq * sizeof(idx_t));
|
||||
float* D = malloc(k * nq * sizeof(float));
|
||||
FaissIDSelectorRange* sel = NULL;
|
||||
FAISS_TRY(faiss_IDSelectorRange_new(&sel, 50, 100));
|
||||
FaissSearchParameters* params = NULL;
|
||||
FAISS_TRY(faiss_SearchParameters_new(¶ms, sel));
|
||||
FAISS_TRY(
|
||||
faiss_Index_search_with_params(index, nq, xq, k, params, D, I));
|
||||
printf("Searching w/ IDSelectorRange [50,100]\n");
|
||||
printf("I=\n");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int j = 0; j < k; j++)
|
||||
printf("%5lld (d=%2.3f) ", I[i * k + j], D[i * k + j]);
|
||||
printf("\n");
|
||||
}
|
||||
free(I);
|
||||
free(D);
|
||||
faiss_SearchParameters_free(params);
|
||||
faiss_IDSelectorRange_free(sel);
|
||||
}
|
||||
|
||||
printf("Saving index to disk...\n");
|
||||
FAISS_TRY(faiss_write_index_fname(index, "example.index"));
|
||||
|
||||
Reference in New Issue
Block a user