Skip to content

Commit

Permalink
Add VectorTransform read from filename to the C API (#3970)
Browse files Browse the repository at this point in the history
Summary:
This adds read_VectorTransform to the C API. This is helpful for independently loading a vector transform rather than as an IndexPreTransform.

Pull Request resolved: #3970

Reviewed By: asadoughi

Differential Revision: D65192203

Pulled By: junjieqi

fbshipit-source-id: 949ae875924b9f3558d7a9f43c4f2aa8ae705f02
  • Loading branch information
makosten authored and facebook-github-bot committed Oct 30, 2024
1 parent 9766d64 commit 2c961cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions c_api/index_io_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

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

int faiss_write_index(const FaissIndex* idx, FILE* f) {
try {
Expand Down Expand Up @@ -83,3 +84,13 @@ int faiss_read_index_binary_fname(
}
CATCH_AND_HANDLE
}

int faiss_read_VectorTransform_fname(
const char* fname,
FaissVectorTransform** p_out) {
try {
auto out = faiss::read_VectorTransform(fname);
*p_out = reinterpret_cast<FaissVectorTransform*>(out);
}
CATCH_AND_HANDLE
}
8 changes: 8 additions & 0 deletions c_api/index_io_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <stdio.h>
#include "IndexBinary_c.h"
#include "Index_c.h"
#include "VectorTransform_c.h"
#include "faiss_c.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -71,6 +72,13 @@ int faiss_read_index_binary_fname(
const char* fname,
int io_flags,
FaissIndexBinary** p_out);

/** Read vector transform from a file.
* This is equivalent to `faiss:read_VectorTransform` when a file path is given.
*/
int faiss_read_VectorTransform_fname(
const char* fname,
FaissVectorTransform** p_out);
#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 2c961cc

Please sign in to comment.