2017-02-23 06:26:44 +08:00
|
|
|
/**
|
2019-05-28 22:17:22 +08:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2017-02-23 06:26:44 +08:00
|
|
|
*
|
2019-05-28 22:17:22 +08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
2017-02-23 06:26:44 +08:00
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// -*- c++ -*-
|
2018-07-06 20:12:11 +08:00
|
|
|
|
2017-02-23 06:26:44 +08:00
|
|
|
// I/O code for indexes
|
|
|
|
|
|
|
|
#ifndef FAISS_INDEX_IO_H
|
|
|
|
#define FAISS_INDEX_IO_H
|
|
|
|
|
2018-07-06 20:12:11 +08:00
|
|
|
|
2017-02-23 06:26:44 +08:00
|
|
|
#include <cstdio>
|
|
|
|
|
2019-03-29 23:32:28 +08:00
|
|
|
/** I/O functions can read/write to a filename, a file handle or to an
|
|
|
|
* object that abstracts the medium.
|
|
|
|
*
|
|
|
|
* The read functions return objects that should be deallocated with
|
|
|
|
* delete. All references within these objectes are owned by the
|
|
|
|
* object.
|
|
|
|
*/
|
2017-02-23 06:26:44 +08:00
|
|
|
|
2019-03-29 23:32:28 +08:00
|
|
|
namespace faiss {
|
2018-07-06 20:12:11 +08:00
|
|
|
|
2017-02-23 06:26:44 +08:00
|
|
|
struct Index;
|
2018-07-06 20:12:11 +08:00
|
|
|
struct IndexBinary;
|
2017-02-23 06:26:44 +08:00
|
|
|
struct VectorTransform;
|
|
|
|
struct ProductQuantizer;
|
2018-05-24 16:45:42 +08:00
|
|
|
struct IOReader;
|
|
|
|
struct IOWriter;
|
2018-08-31 01:38:50 +08:00
|
|
|
struct InvertedLists;
|
2017-02-23 06:26:44 +08:00
|
|
|
|
|
|
|
void write_index (const Index *idx, const char *fname);
|
2018-07-06 20:12:11 +08:00
|
|
|
void write_index (const Index *idx, FILE *f);
|
2018-05-24 16:45:42 +08:00
|
|
|
void write_index (const Index *idx, IOWriter *writer);
|
|
|
|
|
2018-07-06 20:12:11 +08:00
|
|
|
void write_index_binary (const IndexBinary *idx, const char *fname);
|
|
|
|
void write_index_binary (const IndexBinary *idx, FILE *f);
|
|
|
|
void write_index_binary (const IndexBinary *idx, IOWriter *writer);
|
|
|
|
|
2019-03-29 23:32:28 +08:00
|
|
|
// The read_index flags are implemented only for a subset of index types.
|
2018-08-31 01:38:50 +08:00
|
|
|
const int IO_FLAG_MMAP = 1; // try to memmap if possible
|
2018-02-23 23:44:31 +08:00
|
|
|
const int IO_FLAG_READ_ONLY = 2;
|
2019-03-29 23:32:28 +08:00
|
|
|
// strip directory component from ondisk filename, and assume it's in
|
|
|
|
// the same directory as the index file
|
|
|
|
const int IO_FLAG_ONDISK_SAME_DIR = 4;
|
2018-02-23 23:44:31 +08:00
|
|
|
|
|
|
|
Index *read_index (const char *fname, int io_flags = 0);
|
2018-07-06 20:12:11 +08:00
|
|
|
Index *read_index (FILE * f, int io_flags = 0);
|
2018-05-24 16:45:42 +08:00
|
|
|
Index *read_index (IOReader *reader, int io_flags = 0);
|
2017-02-23 06:26:44 +08:00
|
|
|
|
2018-07-06 20:12:11 +08:00
|
|
|
IndexBinary *read_index_binary (const char *fname, int io_flags = 0);
|
|
|
|
IndexBinary *read_index_binary (FILE * f, int io_flags = 0);
|
|
|
|
IndexBinary *read_index_binary (IOReader *reader, int io_flags = 0);
|
|
|
|
|
2017-02-23 06:26:44 +08:00
|
|
|
void write_VectorTransform (const VectorTransform *vt, const char *fname);
|
|
|
|
VectorTransform *read_VectorTransform (const char *fname);
|
|
|
|
|
|
|
|
ProductQuantizer * read_ProductQuantizer (const char*fname);
|
2018-12-20 00:48:35 +08:00
|
|
|
ProductQuantizer * read_ProductQuantizer (IOReader *reader);
|
|
|
|
|
2017-02-23 06:26:44 +08:00
|
|
|
void write_ProductQuantizer (const ProductQuantizer*pq, const char *fname);
|
2018-12-20 00:48:35 +08:00
|
|
|
void write_ProductQuantizer (const ProductQuantizer*pq, IOWriter *f);
|
2017-02-23 06:26:44 +08:00
|
|
|
|
2018-08-31 01:38:50 +08:00
|
|
|
void write_InvertedLists (const InvertedLists *ils, IOWriter *f);
|
|
|
|
InvertedLists *read_InvertedLists (IOReader *reader, int io_flags = 0);
|
2017-02-23 06:26:44 +08:00
|
|
|
|
2018-05-24 16:45:42 +08:00
|
|
|
|
2018-07-06 20:12:11 +08:00
|
|
|
} // namespace faiss
|
2018-05-24 16:45:42 +08:00
|
|
|
|
2017-02-23 06:26:44 +08:00
|
|
|
|
|
|
|
#endif
|