-
Notifications
You must be signed in to change notification settings - Fork 6
MB-62985 - Adding BQ vector-related utils. #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: bleve
Are you sure you want to change the base?
Changes from all commits
df5d4b3
19774ba
98cd6bc
bcb976b
455b607
eb53082
b572d66
017a044
6d3885a
4f9cb89
f7af429
7731f20
c0da9c0
808a143
ac15b52
3a0544f
40db079
719bea6
bb2b615
84867c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #include "IndexBinaryIVF_c.h" | ||
| #include <faiss/IndexBinaryIVF.h> | ||
| #include "macros_impl.h" | ||
|
|
||
| using faiss::IndexBinaryIVF; | ||
|
|
||
| DEFINE_GETTER_PERMISSIVE(IndexBinaryIVF, FaissIndexBinaryPtr, quantizer) | ||
|
|
||
| extern "C" { | ||
|
|
||
| int faiss_IndexBinaryIVF_set_direct_map( | ||
| FaissIndexBinaryIVF* index, | ||
| int direct_map_type) { | ||
| try { | ||
| reinterpret_cast<IndexBinaryIVF*>(index)->set_direct_map_type( | ||
| static_cast<faiss::DirectMap::Type>(direct_map_type)); | ||
| return 0; | ||
| } | ||
| CATCH_AND_HANDLE | ||
| } | ||
|
|
||
| int faiss_get_lists_for_keys_binary( | ||
| FaissIndexBinaryIVF* index, | ||
| idx_t* keys, | ||
| size_t n_keys, | ||
| idx_t* lists) { | ||
| try { | ||
| reinterpret_cast<IndexBinaryIVF*>(index)->get_lists_for_keys( | ||
| keys, n_keys, lists); | ||
| return 0; | ||
| } | ||
| CATCH_AND_HANDLE | ||
| } | ||
|
|
||
| int faiss_Search_closest_eligible_centroids_binary( | ||
| FaissIndexBinaryIVF* index, | ||
| idx_t n, | ||
| const uint8_t* query, | ||
| idx_t k, | ||
| int32_t* centroid_distances, | ||
| idx_t* centroid_ids, | ||
| const FaissSearchParameters* params) { | ||
| try { | ||
| auto idx = reinterpret_cast<IndexBinaryIVF*>(index); | ||
| idx->quantizer->search( | ||
| n, | ||
| query, | ||
| k, | ||
| centroid_distances, | ||
| centroid_ids, | ||
| reinterpret_cast<const faiss::SearchParameters*>(params)); | ||
|
|
||
| return 0; | ||
| } | ||
| CATCH_AND_HANDLE | ||
| } | ||
|
|
||
| int faiss_IndexBinaryIVF_set_is_trained(FaissIndexBinaryIVF* index, int is_trained) { | ||
| try { | ||
| reinterpret_cast<faiss::IndexBinaryIVF*>(index)->is_trained = static_cast<bool>(is_trained); | ||
| } | ||
| CATCH_AND_HANDLE | ||
| } | ||
|
|
||
| int faiss_IndexBinaryIVF_search_preassigned_with_params( | ||
| const FaissIndexBinaryIVF* index, | ||
| idx_t n, | ||
| const uint8_t* x, | ||
| idx_t k, | ||
| const idx_t* assign, | ||
| const int32_t* centroid_dis, | ||
| int32_t* distances, | ||
| idx_t* labels, | ||
| int store_pairs, | ||
| const FaissSearchParametersIVF* params) { | ||
| try { | ||
| auto idx = reinterpret_cast<const IndexBinaryIVF*>(index); | ||
| idx->search_preassigned( | ||
| n, x, k, assign, centroid_dis, distances, labels, | ||
| static_cast<bool>(store_pairs), | ||
| reinterpret_cast<const faiss::IVFSearchParameters*>(params)); | ||
| return 0; | ||
| } | ||
| CATCH_AND_HANDLE | ||
| } | ||
|
|
||
| } // extern "C" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #ifndef FAISS_INDEX_BINARY_IVF_C_H | ||
| #define FAISS_INDEX_BINARY_IVF_C_H | ||
|
|
||
| #include "Index_c.h" | ||
| #include "IndexBinary_c.h" | ||
| #include "IndexIVF_c.h" | ||
| #include "faiss_c.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| FAISS_DECLARE_GETTER_SETTER(IndexBinaryIVF, size_t, nlist) | ||
|
|
||
| FAISS_DECLARE_GETTER_SETTER(IndexBinaryIVF, size_t, nprobe) | ||
|
|
||
| int faiss_IndexBinaryIVF_set_direct_map( | ||
| FaissIndexBinaryIVF* index, | ||
| int direct_map_type); | ||
|
|
||
| int faiss_get_lists_for_keys_binary( | ||
| FaissIndexBinaryIVF* index, | ||
| idx_t* keys, | ||
| size_t n_keys, | ||
| idx_t* lists); | ||
|
|
||
| int faiss_Search_closest_eligible_centroids_binary( | ||
| FaissIndexBinaryIVF* index, | ||
| idx_t n, | ||
| const uint8_t* query, | ||
| idx_t k, | ||
| int32_t* centroid_distances, | ||
| idx_t* centroid_ids, | ||
| const FaissSearchParameters* params); | ||
|
|
||
| int faiss_IndexBinaryIVF_set_is_trained(FaissIndexBinaryIVF* index, int is_trained); | ||
|
|
||
| int faiss_IndexBinaryIVF_search_preassigned_with_params( | ||
| const FaissIndexBinaryIVF* index, | ||
| idx_t n, | ||
| const uint8_t* x, | ||
| idx_t k, | ||
| const idx_t* assign, | ||
| const int32_t* centroid_dis, | ||
| int32_t* distances, | ||
| idx_t* labels, | ||
| int store_pairs, | ||
| const FaissSearchParametersIVF* params); | ||
|
|
||
| typedef FaissIndexBinary* FaissIndexBinaryPtr; | ||
| FaissIndexBinaryPtr faiss_IndexBinaryIVF_quantizer(const FaissIndexBinaryIVF* index); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,9 @@ | |
|
|
||
| #include "IndexBinary_c.h" | ||
| #include <faiss/IndexBinary.h> | ||
| #include <faiss/IndexBinaryIVF.h> | ||
| #include <faiss/IndexIVF.h> | ||
| #include "IndexIVF_c_ex.h" | ||
| #include "macros_impl.h" | ||
|
|
||
| extern "C" { | ||
|
|
@@ -18,6 +21,7 @@ DEFINE_DESTRUCTOR(IndexBinary) | |
| DEFINE_GETTER(IndexBinary, int, d) | ||
|
|
||
| DEFINE_GETTER(IndexBinary, int, is_trained) | ||
| DEFINE_SETTER(IndexBinary, int, is_trained) | ||
|
|
||
| DEFINE_GETTER(IndexBinary, idx_t, ntotal) | ||
|
|
||
|
|
@@ -26,6 +30,14 @@ DEFINE_GETTER(IndexBinary, FaissMetricType, metric_type) | |
| DEFINE_GETTER(IndexBinary, int, verbose); | ||
| DEFINE_SETTER(IndexBinary, int, verbose); | ||
|
|
||
| DEFINE_GETTER(IndexBinaryIVF, size_t, nprobe); | ||
| DEFINE_SETTER(IndexBinaryIVF, size_t, nprobe); | ||
|
|
||
| DEFINE_GETTER(IndexBinaryIVF, size_t, nlist); | ||
| DEFINE_SETTER(IndexBinaryIVF, size_t, nlist); | ||
|
Comment on lines
+36
to
+37
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nlist getter and setter not required |
||
|
|
||
| DEFINE_INDEXBINARY_DOWNCAST(IndexBinaryIVF) | ||
|
|
||
| int faiss_IndexBinary_train( | ||
| FaissIndexBinary* index, | ||
| idx_t n, | ||
|
|
@@ -68,6 +80,26 @@ int faiss_IndexBinary_search( | |
| CATCH_AND_HANDLE | ||
| } | ||
|
|
||
| int faiss_IndexBinary_search_with_params( | ||
| const FaissIndexBinary* index, | ||
| idx_t n, | ||
| const uint8_t* x, | ||
| idx_t k, | ||
| const FaissSearchParameters* params, | ||
| int32_t* distances, | ||
| idx_t* labels) { | ||
| try { | ||
| reinterpret_cast<const faiss::IndexBinary*>(index)->search( | ||
| n, | ||
| x, | ||
| k, | ||
| distances, | ||
| labels, | ||
| reinterpret_cast<const faiss::SearchParameters*>(params)); | ||
| } | ||
| CATCH_AND_HANDLE | ||
| } | ||
|
|
||
| int faiss_IndexBinary_range_search( | ||
| const FaissIndexBinary* index, | ||
| idx_t n, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,11 +28,17 @@ typedef struct FaissIDSelector_H FaissIDSelector; | |
| FAISS_DECLARE_CLASS(IndexBinary) | ||
| FAISS_DECLARE_DESTRUCTOR(IndexBinary) | ||
|
|
||
| FAISS_DECLARE_CLASS_INHERITED(IndexBinaryIVF, IndexBinary) | ||
|
|
||
| /// Cast function for IndexBinaryIVF | ||
| FaissIndexBinaryIVF* faiss_IndexBinaryIVF_cast(FaissIndexBinary* index); | ||
|
|
||
| /// Getter for d | ||
| FAISS_DECLARE_GETTER(IndexBinary, int, d) | ||
|
|
||
| /// Getter for is_trained | ||
| FAISS_DECLARE_GETTER(IndexBinary, int, is_trained) | ||
|
|
||
| FAISS_DECLARE_GETTER_SETTER(IndexBinary, int, is_trained) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please point out why a setter method is required for |
||
|
|
||
| /// Getter for ntotal | ||
| FAISS_DECLARE_GETTER(IndexBinary, idx_t, ntotal) | ||
|
|
@@ -92,6 +98,27 @@ int faiss_IndexBinary_search( | |
| int32_t* distances, | ||
| idx_t* labels); | ||
|
|
||
| /** query n vectors of dimension d to the index. | ||
| * | ||
| * return at most k vectors. If there are not enough results for a | ||
| * query, the result array is padded with -1s. | ||
| * | ||
| * @param index opaque pointer to index object | ||
| * @param x input vectors to search, size n * d | ||
| * @param k number of results to return | ||
| * @param params search parameters | ||
| * @param distances output distances, size n*k | ||
| * @param labels output labels of the NNs, size n*k | ||
| */ | ||
| int faiss_IndexBinary_search_with_params( | ||
| const FaissIndexBinary* index, | ||
| idx_t n, | ||
| const uint8_t* x, | ||
| idx_t k, | ||
| const FaissSearchParameters* params, | ||
| int32_t* distances, | ||
| idx_t* labels); | ||
|
|
||
| /** query n vectors of dimension d to the index. | ||
| * | ||
| * return all vectors with distance < radius. Note that many | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usused setter ?