| 1 |
/* |
| 2 |
* Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 |
* |
| 4 |
* This source code is licensed under the MIT license found in the |
| 5 |
* LICENSE file in the root directory of this source tree. |
| 6 |
*/ |
| 7 |
|
| 8 |
// -*- c++ -*- |
| 9 |
// I/O code for indexes |
| 10 |
|
| 11 |
#ifndef FAISS_INDEX_IO_C_H |
| 12 |
#define FAISS_INDEX_IO_C_H |
| 13 |
|
| 14 |
#include <stdio.h> |
| 15 |
#include "IndexBinary_c.h" |
| 16 |
#include "Index_c.h" |
| 17 |
#include "VectorTransform_c.h" |
| 18 |
#include "faiss_c.h" |
| 19 |
#include "impl/io_c.h" |
| 20 |
|
| 21 |
#ifdef __cplusplus |
| 22 |
extern "C" { |
| 23 |
#endif |
| 24 |
|
| 25 |
/** Write index to a file. |
| 26 |
* This is equivalent to `faiss::write_index` when a file descriptor is |
| 27 |
* provided. |
| 28 |
*/ |
| 29 |
int faiss_write_index(const FaissIndex* idx, FILE* f); |
| 30 |
|
| 31 |
/** Write index to a file. |
| 32 |
* This is equivalent to `faiss::write_index` when a file path is provided. |
| 33 |
*/ |
| 34 |
int faiss_write_index_fname(const FaissIndex* idx, const char* fname); |
| 35 |
|
| 36 |
/** Write index to a custom writer. |
| 37 |
*/ |
| 38 |
int faiss_write_index_custom( |
| 39 |
const FaissIndex* idx, |
| 40 |
FaissIOWriter* io_writer, |
| 41 |
int io_flags); |
| 42 |
|
| 43 |
#define FAISS_IO_FLAG_MMAP 1 |
| 44 |
#define FAISS_IO_FLAG_READ_ONLY 2 |
| 45 |
|
| 46 |
/** Read index from a file. |
| 47 |
* This is equivalent to `faiss:read_index` when a file descriptor is given. |
| 48 |
*/ |
| 49 |
int faiss_read_index(FILE* f, int io_flags, FaissIndex** p_out); |
| 50 |
|
| 51 |
/** Read index from a file. |
| 52 |
* This is equivalent to `faiss:read_index` when a file path is given. |
| 53 |
*/ |
| 54 |
int faiss_read_index_fname(const char* fname, int io_flags, FaissIndex** p_out); |
| 55 |
|
| 56 |
/** Read index from a custom reader. |
| 57 |
*/ |
| 58 |
int faiss_read_index_custom( |
| 59 |
FaissIOReader* io_reader, |
| 60 |
int io_flags, |
| 61 |
FaissIndex** p_out); |
| 62 |
|
| 63 |
/** Write index to a file. |
| 64 |
* This is equivalent to `faiss::write_index_binary` when a file descriptor is |
| 65 |
* provided. |
| 66 |
*/ |
| 67 |
int faiss_write_index_binary(const FaissIndexBinary* idx, FILE* f); |
| 68 |
|
| 69 |
/** Write index to a file. |
| 70 |
* This is equivalent to `faiss::write_index_binary` when a file path is |
| 71 |
* provided. |
| 72 |
*/ |
| 73 |
int faiss_write_index_binary_fname( |
| 74 |
const FaissIndexBinary* idx, |
| 75 |
const char* fname); |
| 76 |
|
| 77 |
/** Write binary index to a custom writer. |
| 78 |
*/ |
| 79 |
int faiss_write_index_binary_custom( |
| 80 |
const FaissIndexBinary* idx, |
| 81 |
FaissIOWriter* io_writer); |
| 82 |
|
| 83 |
/** Read index from a file. |
| 84 |
* This is equivalent to `faiss:read_index_binary` when a file descriptor is |
| 85 |
* given. |
| 86 |
*/ |
| 87 |
int faiss_read_index_binary(FILE* f, int io_flags, FaissIndexBinary** p_out); |
| 88 |
|
| 89 |
/** Read index from a file. |
| 90 |
* This is equivalent to `faiss:read_index_binary` when a file path is given. |
| 91 |
*/ |
| 92 |
int faiss_read_index_binary_fname( |
| 93 |
const char* fname, |
| 94 |
int io_flags, |
| 95 |
FaissIndexBinary** p_out); |
| 96 |
|
| 97 |
/** Read binary index from a custom reader. |
| 98 |
*/ |
| 99 |
int faiss_read_index_binary_custom( |
| 100 |
FaissIOReader* io_reader, |
| 101 |
int io_flags, |
| 102 |
FaissIndexBinary** p_out); |
| 103 |
|
| 104 |
/** Read vector transform from a file. |
| 105 |
* This is equivalent to `faiss:read_VectorTransform` when a file path is given. |
| 106 |
*/ |
| 107 |
int faiss_read_VectorTransform_fname( |
| 108 |
const char* fname, |
| 109 |
FaissVectorTransform** p_out); |
| 110 |
#ifdef __cplusplus |
| 111 |
} |
| 112 |
#endif |
| 113 |
#endif |