From 2c961cc308ade8a85b3aa10a550728ce3387f625 Mon Sep 17 00:00:00 2001 From: Michael Kosten Date: Wed, 30 Oct 2024 12:01:15 -0700 Subject: [PATCH] Add VectorTransform read from filename to the C API (#3970) 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: https://github.com/facebookresearch/faiss/pull/3970 Reviewed By: asadoughi Differential Revision: D65192203 Pulled By: junjieqi fbshipit-source-id: 949ae875924b9f3558d7a9f43c4f2aa8ae705f02 --- c_api/index_io_c.cpp | 11 +++++++++++ c_api/index_io_c.h | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/c_api/index_io_c.cpp b/c_api/index_io_c.cpp index 9be2f9e414..ea3068e968 100644 --- a/c_api/index_io_c.cpp +++ b/c_api/index_io_c.cpp @@ -14,6 +14,7 @@ using faiss::Index; using faiss::IndexBinary; +using faiss::VectorTransform; int faiss_write_index(const FaissIndex* idx, FILE* f) { try { @@ -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(out); + } + CATCH_AND_HANDLE +} diff --git a/c_api/index_io_c.h b/c_api/index_io_c.h index c9026c7e9c..fd4da615e5 100644 --- a/c_api/index_io_c.h +++ b/c_api/index_io_c.h @@ -14,6 +14,7 @@ #include #include "IndexBinary_c.h" #include "Index_c.h" +#include "VectorTransform_c.h" #include "faiss_c.h" #ifdef __cplusplus @@ -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