Skip to content
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

Add the ability to clone and read binary indexes to the C API. #3318

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions c_api/clone_index_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "macros_impl.h"

using faiss::Index;
using faiss::IndexBinary;

int faiss_clone_index(const FaissIndex* idx, FaissIndex** p_out) {
try {
Expand All @@ -22,3 +23,14 @@ int faiss_clone_index(const FaissIndex* idx, FaissIndex** p_out) {
}
CATCH_AND_HANDLE
}

int faiss_clone_index_binary(
const FaissIndexBinary* idx,
FaissIndexBinary** p_out) {
try {
auto out = faiss::clone_binary_index(
reinterpret_cast<const IndexBinary*>(idx));
*p_out = reinterpret_cast<FaissIndexBinary*>(out);
}
CATCH_AND_HANDLE
}
4 changes: 4 additions & 0 deletions c_api/clone_index_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define FAISS_CLONE_INDEX_C_H

#include <stdio.h>
#include "IndexBinary_c.h"
#include "Index_c.h"
#include "faiss_c.h"

Expand All @@ -25,6 +26,9 @@ extern "C" {
/** Clone an index. This is equivalent to `faiss::clone_index` */
int faiss_clone_index(const FaissIndex*, FaissIndex** p_out);

/** Clone a binary index. This is equivalent to `faiss::clone_index_binary` */
int faiss_clone_index_binary(const FaissIndexBinary*, FaissIndexBinary** p_out);

#ifdef __cplusplus
}
#endif
Expand Down
16 changes: 15 additions & 1 deletion c_api/index_factory_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

using faiss::Index;

/** Build and index with the sequence of processing steps described in
/** Build an index with the sequence of processing steps described in
* the string.
*/
int faiss_index_factory(
Expand All @@ -29,3 +29,17 @@ int faiss_index_factory(
}
CATCH_AND_HANDLE
}

/** Build an index with the sequence of processing steps described in
* the string.
*/
int faiss_index_binary_factory(
FaissIndexBinary** p_index,
int d,
const char* description) {
try {
*p_index = reinterpret_cast<FaissIndexBinary*>(
faiss::index_binary_factory(d, description));
}
CATCH_AND_HANDLE
}
11 changes: 10 additions & 1 deletion c_api/index_factory_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
#ifndef FAISS_INDEX_FACTORY_C_H
#define FAISS_INDEX_FACTORY_C_H

#include "IndexBinary_c.h"
#include "Index_c.h"
#include "faiss_c.h"

#ifdef __cplusplus
extern "C" {
#endif

/** Build and index with the sequence of processing steps described in
/** Build an index with the sequence of processing steps described in
* the string.
*/
int faiss_index_factory(
Expand All @@ -27,6 +28,14 @@ int faiss_index_factory(
const char* description,
FaissMetricType metric);

/** Build a binary index with the sequence of processing steps described in
* the string.
*/
int faiss_index_binary_factory(
FaissIndexBinary** p_index,
int d,
const char* description);

#ifdef __cplusplus
}
#endif
Expand Down