Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
/tmp/faiss/IndexIVFFlat.h
1 /**
2 * Copyright (c) 2015-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD+Patents license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9 // -*- c++ -*-
10
11 #ifndef FAISS_INDEX_IVF_FLAT_H
12 #define FAISS_INDEX_IVF_FLAT_H
13
14 #include <unordered_map>
15
16 #include "IndexIVF.h"
17
18
19 namespace faiss {
20
21 /** Inverted file with stored vectors. Here the inverted file
22 * pre-selects the vectors to be searched, but they are not otherwise
23 * encoded, the code array just contains the raw float entries.
24 */
25 struct IndexIVFFlat: IndexIVF {
26
27 IndexIVFFlat (
28 Index * quantizer, size_t d, size_t nlist_,
29 MetricType = METRIC_L2);
30
31 /// same as add_with_ids, with precomputed coarse quantizer
32 virtual void add_core (idx_t n, const float * x, const long *xids,
33 const long *precomputed_idx);
34
35 /// implemented for all IndexIVF* classes
36 void add_with_ids(idx_t n, const float* x, const long* xids) override;
37
38 void encode_vectors(idx_t n, const float* x,
39 const idx_t *list_nos,
40 uint8_t * codes) const override;
41
42 /*
43 void search_preassigned (idx_t n, const float *x, idx_t k,
44 const idx_t *assign,
45 const float *centroid_dis,
46 float *distances, idx_t *labels,
47 bool store_pairs,
48 const IVFSearchParameters *params=nullptr
49 ) const override;
50 */
51 InvertedListScanner *get_InvertedListScanner (bool store_pairs)
52 const override;
53
54 void range_search(
55 idx_t n,
56 const float* x,
57 float radius,
58 RangeSearchResult* result) const override;
59
60 /** Update a subset of vectors.
61 *
62 * The index must have a direct_map
63 *
64 * @param nv nb of vectors to update
65 * @param idx vector indices to update, size nv
66 * @param v vectors of new values, size nv*d
67 */
68 virtual void update_vectors (int nv, idx_t *idx, const float *v);
69
70 void reconstruct_from_offset (long list_no, long offset,
71 float* recons) const override;
72
73 IndexIVFFlat () {}
74 };
75
76
77 struct IndexIVFFlatDedup: IndexIVFFlat {
78
79 /** Maps ids stored in the index to the ids of vectors that are
80 * the same. When a vector is unique, it does not appear in the
81 * instances map */
82 std::unordered_multimap <idx_t, idx_t> instances;
83
84 IndexIVFFlatDedup (
85 Index * quantizer, size_t d, size_t nlist_,
86 MetricType = METRIC_L2);
87
88 /// also dedups the training set
89 void train(idx_t n, const float* x) override;
90
91 /// implemented for all IndexIVF* classes
92 void add_with_ids(idx_t n, const float* x, const long* xids) override;
93
94 void search_preassigned (idx_t n, const float *x, idx_t k,
95 const idx_t *assign,
96 const float *centroid_dis,
97 float *distances, idx_t *labels,
98 bool store_pairs,
99 const IVFSearchParameters *params=nullptr
100 ) const override;
101
102 long remove_ids(const IDSelector& sel) override;
103
104 /// not implemented
105 void range_search(
106 idx_t n,
107 const float* x,
108 float radius,
109 RangeSearchResult* result) const override;
110
111 /// not implemented
112 void update_vectors (int nv, idx_t *idx, const float *v) override;
113
114
115 /// not implemented
116 void reconstruct_from_offset (long list_no, long offset,
117 float* recons) const override;
118
119 IndexIVFFlatDedup () {}
120
121
122 };
123
124
125
126 } // namespace faiss
127
128 #endif
faiss::IndexIVF
Definition: IndexIVF.h:91
faiss::IndexIVFFlatDedup::train
void train(idx_t n, const float *x) override
also dedups the training set
Definition: IndexIVFFlat.cpp:288
faiss::IndexIVFFlatDedup::reconstruct_from_offset
void reconstruct_from_offset(long list_no, long offset, float *recons) const override
not implemented
Definition: IndexIVFFlat.cpp:516
faiss::IndexIVFFlat::encode_vectors
void encode_vectors(idx_t n, const float *x, const idx_t *list_nos, uint8_t *codes) const override
Definition: IndexIVFFlat.cpp:83
faiss::Index::assign
void assign(idx_t n, const float *x, idx_t *labels, idx_t k=1)
Definition: Index.cpp:35
faiss::IDSelector
Definition: AuxIndexStructures.h:54
faiss::IndexIVFFlat::range_search
void range_search(idx_t n, const float *x, float radius, RangeSearchResult *result) const override
Definition: IndexIVFFlat.cpp:171
faiss::IndexIVFFlat
Definition: IndexIVFFlat.h:25
faiss::IVFSearchParameters
Definition: IndexIVF.h:61
faiss::Index::d
int d
vector dimension
Definition: Index.h:66
faiss::IndexIVFFlatDedup::add_with_ids
void add_with_ids(idx_t n, const float *x, const long *xids) override
implemented for all IndexIVF* classes
Definition: IndexIVFFlat.cpp:315
faiss::IndexIVFFlatDedup::search_preassigned
void search_preassigned(idx_t n, const float *x, idx_t k, const idx_t *assign, const float *centroid_dis, float *distances, idx_t *labels, bool store_pairs, const IVFSearchParameters *params=nullptr) const override
Definition: IndexIVFFlat.cpp:371
faiss::IndexIVFFlat::add_with_ids
void add_with_ids(idx_t n, const float *x, const long *xids) override
implemented for all IndexIVF* classes
Definition: IndexIVFFlat.cpp:37
faiss::Index::idx_t
long idx_t
all indices are this type
Definition: Index.h:64
faiss::IndexIVFFlat::reconstruct_from_offset
void reconstruct_from_offset(long list_no, long offset, float *recons) const override
Definition: IndexIVFFlat.cpp:259
faiss::IndexIVFFlat::update_vectors
virtual void update_vectors(int nv, idx_t *idx, const float *v)
Definition: IndexIVFFlat.cpp:223
faiss::IndexIVFFlatDedup::range_search
void range_search(idx_t n, const float *x, float radius, RangeSearchResult *result) const override
not implemented
Definition: IndexIVFFlat.cpp:501
faiss::InvertedListScanner
Definition: IndexIVF.h:261
faiss::IndexIVFFlatDedup::update_vectors
void update_vectors(int nv, idx_t *idx, const float *v) override
not implemented
Definition: IndexIVFFlat.cpp:510
faiss::RangeSearchResult
Definition: AuxIndexStructures.h:31
faiss::Index
Definition: Index.h:62
faiss::Level1Quantizer::quantizer
Index * quantizer
quantizer that maps vectors to inverted lists
Definition: IndexIVF.h:33
faiss::IndexIVFFlatDedup::remove_ids
long remove_ids(const IDSelector &sel) override
Dataset manipulation functions.
Definition: IndexIVFFlat.cpp:426
faiss::MetricType
MetricType
Some algorithms support both an inner product version and a L2 search version.
Definition: Index.h:45
faiss::IndexIVFFlatDedup
Definition: IndexIVFFlat.h:77
faiss::IndexIVFFlat::get_InvertedListScanner
InvertedListScanner * get_InvertedListScanner(bool store_pairs) const override
get a scanner for this index (store_pairs means ignore labels)
Definition: IndexIVFFlat.cpp:148
faiss::IndexIVFFlat::add_core
virtual void add_core(idx_t n, const float *x, const long *xids, const long *precomputed_idx)
same as add_with_ids, with precomputed coarse quantizer
Definition: IndexIVFFlat.cpp:42
faiss::IndexIVFFlatDedup::instances
std::unordered_multimap< idx_t, idx_t > instances
Definition: IndexIVFFlat.h:82