forked from facebookresearch/faiss
-
Notifications
You must be signed in to change notification settings - Fork 11
/
index_io.h
103 lines (78 loc) · 3.29 KB
/
index_io.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// -*- c++ -*-
// I/O code for indexes
#ifndef FAISS_INDEX_IO_H
#define FAISS_INDEX_IO_H
#include <cstdio>
#include <fstream>
/** 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.
*/
namespace faiss {
struct Index;
struct IndexBinary;
struct VectorTransform;
struct IndexIVF;
struct ProductQuantizer;
struct IOReader;
struct IOWriter;
struct InvertedLists;
void write_index (const Index *idx, const char *fname);
void write_index (const Index *idx, FILE *f);
void write_index (const Index *idx, IOWriter *writer);
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);
// For IVF, export the cluster id for each database vetor
// for finding ground truth minimum termination condition.
void write_cluster_id (const Index *idx, const char *path);
// Load ground truth nearest neighbor database index
// for finding ground truth minimum termination condition.
void load_gt (Index *idx, long label);
// Load the thresholds about when to make predictions.
// This is related to the choice of intermediate search result features.
void load_thresh (Index *idx, long thresh);
// Load the prediction model.
void load_model (Index *idx, char *path);
// The read_index flags are implemented only for a subset of index types.
const int IO_FLAG_MMAP = 1; // try to memmap if possible
const int IO_FLAG_READ_ONLY = 2;
// 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;
Index *read_index (const char *fname, int io_flags = 0);
Index *read_index (FILE * f, int io_flags = 0);
Index *read_index (IOReader *reader, int io_flags = 0);
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);
void write_VectorTransform (const VectorTransform *vt, const char *fname);
VectorTransform *read_VectorTransform (const char *fname);
ProductQuantizer * read_ProductQuantizer (const char*fname);
ProductQuantizer * read_ProductQuantizer (IOReader *reader);
void write_ProductQuantizer (const ProductQuantizer*pq, const char *fname);
void write_ProductQuantizer (const ProductQuantizer*pq, IOWriter *f);
void write_InvertedLists (const InvertedLists *ils, IOWriter *f);
InvertedLists *read_InvertedLists (IOReader *reader, int io_flags = 0);
/* cloning functions */
Index *clone_index (const Index *);
/** Cloner class, useful to override classes with other cloning
* functions. The cloning function above just calls
* Cloner::clone_Index. */
struct Cloner {
virtual VectorTransform *clone_VectorTransform (const VectorTransform *);
virtual Index *clone_Index (const Index *);
virtual IndexIVF *clone_IndexIVF (const IndexIVF *);
virtual ~Cloner() {}
};
} // namespace faiss
#endif