Skip to content

Commit

Permalink
MB-60202 - IDMap2 Selector (#12)
Browse files Browse the repository at this point in the history
* Support Selector for IDMap (facebookresearch#2848)

Summary:
Pull Request resolved: facebookresearch#2848

Add selector support for IDMap wrapped indices.
Caveat: this requires to wrap the IDSelector with another selector. Since the params are const, the const is casted away.

This is a problem if the same params are used from multiple execution threads with different selectors. However, this seems rare enough to take the risk.

Reviewed By: alexanderguzhva

Differential Revision: D45598823

fbshipit-source-id: ec23465c13f1f8273a6a46f9aa869ccae2cdb79c

* added C API helper func

---------

Co-authored-by: Matthijs Douze <matthijs@meta.com>
  • Loading branch information
2 people authored and CascadingRadium committed Aug 16, 2024
1 parent 8e6a8cd commit 828e569
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions c_api/IndexIVF_c_ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "macros_impl.h"

using faiss::IndexIVF;
using faiss::SearchParametersIVF;

int faiss_IndexIVF_set_direct_map(FaissIndexIVF* index, int direct_map_type) {
try {
Expand All @@ -20,3 +21,14 @@ int faiss_IndexIVF_set_direct_map(FaissIndexIVF* index, int direct_map_type) {
}
CATCH_AND_HANDLE
}

int faiss_SearchParametersIVF_new_with_sel(
FaissSearchParametersIVF** p_sp,
FaissIDSelector* sel) {
try {
SearchParametersIVF* sp = new SearchParametersIVF;
sp->sel = reinterpret_cast<faiss::IDSelector*>(sel);
*p_sp = reinterpret_cast<FaissSearchParametersIVF*>(sp);
}
CATCH_AND_HANDLE
}
4 changes: 4 additions & 0 deletions c_api/IndexIVF_c_ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ int faiss_IndexIVF_set_direct_map(
FaissIndexIVF* index,
int direct_map_type);

int faiss_SearchParametersIVF_new_with_sel(
FaissSearchParametersIVF** p_sp,
FaissIDSelector* sel);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 828e569

Please sign in to comment.