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