Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
/data/users/hoss/faiss/index_io.h
1 /**
2 * Copyright (c) Facebook, Inc. and its 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
10 // I/O code for indexes
11
12 #ifndef FAISS_INDEX_IO_H
13 #define FAISS_INDEX_IO_H
14
15
16 #include <cstdio>
17
18 /** I/O functions can read/write to a filename, a file handle or to an
19 * object that abstracts the medium.
20 *
21 * The read functions return objects that should be deallocated with
22 * delete. All references within these objectes are owned by the
23 * object.
24 */
25
26 namespace faiss {
27
28 struct Index;
29 struct IndexBinary;
30 struct VectorTransform;
31 struct IndexIVF;
32 struct ProductQuantizer;
33 struct IOReader;
34 struct IOWriter;
35 struct InvertedLists;
36
37 void write_index (const Index *idx, const char *fname);
38 void write_index (const Index *idx, FILE *f);
39 void write_index (const Index *idx, IOWriter *writer);
40
41 void write_index_binary (const IndexBinary *idx, const char *fname);
42 void write_index_binary (const IndexBinary *idx, FILE *f);
43 void write_index_binary (const IndexBinary *idx, IOWriter *writer);
44
45 // The read_index flags are implemented only for a subset of index types.
46 const int IO_FLAG_MMAP = 1; // try to memmap if possible
47 const int IO_FLAG_READ_ONLY = 2;
48 // strip directory component from ondisk filename, and assume it's in
49 // the same directory as the index file
50 const int IO_FLAG_ONDISK_SAME_DIR = 4;
51
52 Index *read_index (const char *fname, int io_flags = 0);
53 Index *read_index (FILE * f, int io_flags = 0);
54 Index *read_index (IOReader *reader, int io_flags = 0);
55
56 IndexBinary *read_index_binary (const char *fname, int io_flags = 0);
57 IndexBinary *read_index_binary (FILE * f, int io_flags = 0);
58 IndexBinary *read_index_binary (IOReader *reader, int io_flags = 0);
59
60 void write_VectorTransform (const VectorTransform *vt, const char *fname);
61 VectorTransform *read_VectorTransform (const char *fname);
62
63 ProductQuantizer * read_ProductQuantizer (const char*fname);
64 ProductQuantizer * read_ProductQuantizer (IOReader *reader);
65
66 void write_ProductQuantizer (const ProductQuantizer*pq, const char *fname);
67 void write_ProductQuantizer (const ProductQuantizer*pq, IOWriter *f);
68
69 void write_InvertedLists (const InvertedLists *ils, IOWriter *f);
70 InvertedLists *read_InvertedLists (IOReader *reader, int io_flags = 0);
71
72 /* cloning functions */
73 Index *clone_index (const Index *);
74
75 /** Cloner class, useful to override classes with other cloning
76 * functions. The cloning function above just calls
77 * Cloner::clone_Index. */
78 struct Cloner {
79 virtual VectorTransform *clone_VectorTransform (const VectorTransform *);
80 virtual Index *clone_Index (const Index *);
81 virtual IndexIVF *clone_IndexIVF (const IndexIVF *);
82 virtual ~Cloner() {}
83 };
84
85
86
87 } // namespace faiss
88
89
90 #endif
faiss::IndexIVF
Definition: IndexIVF.h:90
faiss::Cloner
Definition: index_io.h:78
faiss::VectorTransform
Definition: VectorTransform.h:26
faiss::Index
Definition: Index.h:61