faiss 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/README.md +23 -21
  4. data/ext/faiss/extconf.rb +11 -0
  5. data/ext/faiss/index.cpp +4 -4
  6. data/ext/faiss/index_binary.cpp +6 -6
  7. data/ext/faiss/product_quantizer.cpp +4 -4
  8. data/lib/faiss/version.rb +1 -1
  9. data/vendor/faiss/faiss/AutoTune.cpp +13 -0
  10. data/vendor/faiss/faiss/IVFlib.cpp +101 -2
  11. data/vendor/faiss/faiss/IVFlib.h +26 -2
  12. data/vendor/faiss/faiss/Index.cpp +36 -3
  13. data/vendor/faiss/faiss/Index.h +43 -6
  14. data/vendor/faiss/faiss/Index2Layer.cpp +6 -2
  15. data/vendor/faiss/faiss/Index2Layer.h +6 -1
  16. data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +219 -16
  17. data/vendor/faiss/faiss/IndexAdditiveQuantizer.h +63 -5
  18. data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +299 -0
  19. data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +199 -0
  20. data/vendor/faiss/faiss/IndexBinary.cpp +20 -4
  21. data/vendor/faiss/faiss/IndexBinary.h +18 -3
  22. data/vendor/faiss/faiss/IndexBinaryFlat.cpp +9 -2
  23. data/vendor/faiss/faiss/IndexBinaryFlat.h +4 -2
  24. data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +4 -1
  25. data/vendor/faiss/faiss/IndexBinaryFromFloat.h +2 -1
  26. data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +5 -1
  27. data/vendor/faiss/faiss/IndexBinaryHNSW.h +2 -1
  28. data/vendor/faiss/faiss/IndexBinaryHash.cpp +17 -4
  29. data/vendor/faiss/faiss/IndexBinaryHash.h +8 -4
  30. data/vendor/faiss/faiss/IndexBinaryIVF.cpp +28 -13
  31. data/vendor/faiss/faiss/IndexBinaryIVF.h +10 -7
  32. data/vendor/faiss/faiss/IndexFastScan.cpp +626 -0
  33. data/vendor/faiss/faiss/IndexFastScan.h +145 -0
  34. data/vendor/faiss/faiss/IndexFlat.cpp +34 -21
  35. data/vendor/faiss/faiss/IndexFlat.h +7 -4
  36. data/vendor/faiss/faiss/IndexFlatCodes.cpp +35 -1
  37. data/vendor/faiss/faiss/IndexFlatCodes.h +12 -0
  38. data/vendor/faiss/faiss/IndexHNSW.cpp +66 -138
  39. data/vendor/faiss/faiss/IndexHNSW.h +4 -2
  40. data/vendor/faiss/faiss/IndexIDMap.cpp +247 -0
  41. data/vendor/faiss/faiss/IndexIDMap.h +107 -0
  42. data/vendor/faiss/faiss/IndexIVF.cpp +121 -33
  43. data/vendor/faiss/faiss/IndexIVF.h +35 -16
  44. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +84 -7
  45. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.h +63 -1
  46. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +590 -0
  47. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +171 -0
  48. data/vendor/faiss/faiss/IndexIVFFastScan.cpp +1290 -0
  49. data/vendor/faiss/faiss/IndexIVFFastScan.h +213 -0
  50. data/vendor/faiss/faiss/IndexIVFFlat.cpp +37 -17
  51. data/vendor/faiss/faiss/IndexIVFFlat.h +4 -2
  52. data/vendor/faiss/faiss/IndexIVFPQ.cpp +234 -50
  53. data/vendor/faiss/faiss/IndexIVFPQ.h +5 -1
  54. data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +23 -852
  55. data/vendor/faiss/faiss/IndexIVFPQFastScan.h +7 -112
  56. data/vendor/faiss/faiss/IndexIVFPQR.cpp +3 -3
  57. data/vendor/faiss/faiss/IndexIVFPQR.h +1 -1
  58. data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +3 -1
  59. data/vendor/faiss/faiss/IndexIVFSpectralHash.h +2 -1
  60. data/vendor/faiss/faiss/IndexLSH.cpp +4 -2
  61. data/vendor/faiss/faiss/IndexLSH.h +2 -1
  62. data/vendor/faiss/faiss/IndexLattice.cpp +7 -1
  63. data/vendor/faiss/faiss/IndexLattice.h +3 -1
  64. data/vendor/faiss/faiss/IndexNNDescent.cpp +4 -3
  65. data/vendor/faiss/faiss/IndexNNDescent.h +2 -1
  66. data/vendor/faiss/faiss/IndexNSG.cpp +37 -3
  67. data/vendor/faiss/faiss/IndexNSG.h +25 -1
  68. data/vendor/faiss/faiss/IndexPQ.cpp +106 -69
  69. data/vendor/faiss/faiss/IndexPQ.h +19 -5
  70. data/vendor/faiss/faiss/IndexPQFastScan.cpp +15 -450
  71. data/vendor/faiss/faiss/IndexPQFastScan.h +15 -78
  72. data/vendor/faiss/faiss/IndexPreTransform.cpp +47 -8
  73. data/vendor/faiss/faiss/IndexPreTransform.h +15 -3
  74. data/vendor/faiss/faiss/IndexRefine.cpp +8 -4
  75. data/vendor/faiss/faiss/IndexRefine.h +4 -2
  76. data/vendor/faiss/faiss/IndexReplicas.cpp +4 -2
  77. data/vendor/faiss/faiss/IndexReplicas.h +2 -1
  78. data/vendor/faiss/faiss/IndexRowwiseMinMax.cpp +438 -0
  79. data/vendor/faiss/faiss/IndexRowwiseMinMax.h +92 -0
  80. data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +26 -15
  81. data/vendor/faiss/faiss/IndexScalarQuantizer.h +6 -7
  82. data/vendor/faiss/faiss/IndexShards.cpp +4 -1
  83. data/vendor/faiss/faiss/IndexShards.h +2 -1
  84. data/vendor/faiss/faiss/MetaIndexes.cpp +5 -178
  85. data/vendor/faiss/faiss/MetaIndexes.h +3 -81
  86. data/vendor/faiss/faiss/VectorTransform.cpp +43 -0
  87. data/vendor/faiss/faiss/VectorTransform.h +22 -4
  88. data/vendor/faiss/faiss/clone_index.cpp +23 -1
  89. data/vendor/faiss/faiss/clone_index.h +3 -0
  90. data/vendor/faiss/faiss/cppcontrib/SaDecodeKernels.h +300 -0
  91. data/vendor/faiss/faiss/cppcontrib/detail/CoarseBitType.h +24 -0
  92. data/vendor/faiss/faiss/cppcontrib/detail/UintReader.h +195 -0
  93. data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +2058 -0
  94. data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +408 -0
  95. data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-neon-inl.h +2147 -0
  96. data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMax-inl.h +460 -0
  97. data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMaxFP16-inl.h +465 -0
  98. data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-avx2-inl.h +1618 -0
  99. data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-inl.h +251 -0
  100. data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-neon-inl.h +1452 -0
  101. data/vendor/faiss/faiss/gpu/GpuAutoTune.cpp +1 -0
  102. data/vendor/faiss/faiss/gpu/GpuCloner.cpp +0 -4
  103. data/vendor/faiss/faiss/gpu/GpuIndex.h +28 -4
  104. data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +2 -1
  105. data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +10 -8
  106. data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +75 -14
  107. data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +19 -32
  108. data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +22 -31
  109. data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +22 -28
  110. data/vendor/faiss/faiss/gpu/GpuResources.cpp +14 -0
  111. data/vendor/faiss/faiss/gpu/GpuResources.h +16 -3
  112. data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +3 -3
  113. data/vendor/faiss/faiss/gpu/impl/IndexUtils.h +32 -0
  114. data/vendor/faiss/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +1 -0
  115. data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +311 -75
  116. data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +10 -0
  117. data/vendor/faiss/faiss/gpu/test/TestUtils.h +3 -0
  118. data/vendor/faiss/faiss/gpu/test/demo_ivfpq_indexing_gpu.cpp +2 -2
  119. data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +5 -4
  120. data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +116 -47
  121. data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +44 -13
  122. data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +0 -54
  123. data/vendor/faiss/faiss/impl/AuxIndexStructures.h +0 -76
  124. data/vendor/faiss/faiss/impl/DistanceComputer.h +64 -0
  125. data/vendor/faiss/faiss/impl/HNSW.cpp +123 -27
  126. data/vendor/faiss/faiss/impl/HNSW.h +19 -16
  127. data/vendor/faiss/faiss/impl/IDSelector.cpp +125 -0
  128. data/vendor/faiss/faiss/impl/IDSelector.h +135 -0
  129. data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +6 -28
  130. data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +6 -1
  131. data/vendor/faiss/faiss/impl/LookupTableScaler.h +77 -0
  132. data/vendor/faiss/faiss/impl/NNDescent.cpp +1 -0
  133. data/vendor/faiss/faiss/impl/NSG.cpp +1 -1
  134. data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +383 -0
  135. data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.h +154 -0
  136. data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +225 -145
  137. data/vendor/faiss/faiss/impl/ProductQuantizer.h +29 -10
  138. data/vendor/faiss/faiss/impl/Quantizer.h +43 -0
  139. data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +192 -36
  140. data/vendor/faiss/faiss/impl/ResidualQuantizer.h +40 -20
  141. data/vendor/faiss/faiss/impl/ResultHandler.h +96 -0
  142. data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +97 -173
  143. data/vendor/faiss/faiss/impl/ScalarQuantizer.h +18 -18
  144. data/vendor/faiss/faiss/impl/index_read.cpp +240 -9
  145. data/vendor/faiss/faiss/impl/index_write.cpp +237 -5
  146. data/vendor/faiss/faiss/impl/kmeans1d.cpp +6 -4
  147. data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +56 -16
  148. data/vendor/faiss/faiss/impl/pq4_fast_scan.h +25 -8
  149. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +66 -25
  150. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +75 -27
  151. data/vendor/faiss/faiss/index_factory.cpp +196 -7
  152. data/vendor/faiss/faiss/index_io.h +5 -0
  153. data/vendor/faiss/faiss/invlists/DirectMap.cpp +1 -0
  154. data/vendor/faiss/faiss/invlists/InvertedLists.cpp +4 -1
  155. data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +2 -1
  156. data/vendor/faiss/faiss/python/python_callbacks.cpp +27 -0
  157. data/vendor/faiss/faiss/python/python_callbacks.h +15 -0
  158. data/vendor/faiss/faiss/utils/Heap.h +31 -15
  159. data/vendor/faiss/faiss/utils/distances.cpp +380 -56
  160. data/vendor/faiss/faiss/utils/distances.h +113 -15
  161. data/vendor/faiss/faiss/utils/distances_simd.cpp +726 -6
  162. data/vendor/faiss/faiss/utils/extra_distances.cpp +12 -7
  163. data/vendor/faiss/faiss/utils/extra_distances.h +3 -1
  164. data/vendor/faiss/faiss/utils/fp16-fp16c.h +21 -0
  165. data/vendor/faiss/faiss/utils/fp16-inl.h +101 -0
  166. data/vendor/faiss/faiss/utils/fp16.h +11 -0
  167. data/vendor/faiss/faiss/utils/hamming-inl.h +54 -0
  168. data/vendor/faiss/faiss/utils/hamming.cpp +0 -48
  169. data/vendor/faiss/faiss/utils/ordered_key_value.h +10 -0
  170. data/vendor/faiss/faiss/utils/quantize_lut.cpp +62 -0
  171. data/vendor/faiss/faiss/utils/quantize_lut.h +20 -0
  172. data/vendor/faiss/faiss/utils/random.cpp +53 -0
  173. data/vendor/faiss/faiss/utils/random.h +5 -0
  174. data/vendor/faiss/faiss/utils/simdlib_avx2.h +4 -0
  175. data/vendor/faiss/faiss/utils/simdlib_emulated.h +6 -1
  176. data/vendor/faiss/faiss/utils/simdlib_neon.h +7 -2
  177. metadata +37 -3
@@ -11,11 +11,13 @@
11
11
  #define FAISS_INDEX_IVF_H
12
12
 
13
13
  #include <stdint.h>
14
+ #include <memory>
14
15
  #include <unordered_map>
15
16
  #include <vector>
16
17
 
17
18
  #include <faiss/Clustering.h>
18
19
  #include <faiss/Index.h>
20
+ #include <faiss/impl/IDSelector.h>
19
21
  #include <faiss/impl/platform_macros.h>
20
22
  #include <faiss/invlists/DirectMap.h>
21
23
  #include <faiss/invlists/InvertedLists.h>
@@ -62,13 +64,18 @@ struct Level1Quantizer {
62
64
  ~Level1Quantizer();
63
65
  };
64
66
 
65
- struct IVFSearchParameters {
67
+ struct SearchParametersIVF : SearchParameters {
66
68
  size_t nprobe; ///< number of probes at query time
67
69
  size_t max_codes; ///< max nb of codes to visit to do a query
68
- IVFSearchParameters() : nprobe(1), max_codes(0) {}
69
- virtual ~IVFSearchParameters() {}
70
+ SearchParameters* quantizer_params = nullptr;
71
+
72
+ SearchParametersIVF() : nprobe(1), max_codes(0) {}
73
+ virtual ~SearchParametersIVF() {}
70
74
  };
71
75
 
76
+ // the new convention puts the index type after SearchParameters
77
+ using IVFSearchParameters = SearchParametersIVF;
78
+
72
79
  struct InvertedListScanner;
73
80
  struct IndexIVFStats;
74
81
 
@@ -218,13 +225,15 @@ struct IndexIVF : Index, Level1Quantizer {
218
225
  const float* x,
219
226
  idx_t k,
220
227
  float* distances,
221
- idx_t* labels) const override;
228
+ idx_t* labels,
229
+ const SearchParameters* params = nullptr) const override;
222
230
 
223
231
  void range_search(
224
232
  idx_t n,
225
233
  const float* x,
226
234
  float radius,
227
- RangeSearchResult* result) const override;
235
+ RangeSearchResult* result,
236
+ const SearchParameters* params = nullptr) const override;
228
237
 
229
238
  void range_search_preassigned(
230
239
  idx_t nx,
@@ -242,7 +251,8 @@ struct IndexIVF : Index, Level1Quantizer {
242
251
  * The default search implementation uses this to compute the distances
243
252
  */
244
253
  virtual InvertedListScanner* get_InvertedListScanner(
245
- bool store_pairs = false) const;
254
+ bool store_pairs = false,
255
+ const IDSelector* sel = nullptr) const;
246
256
 
247
257
  /** reconstruct a vector. Works only if maintain_direct_map is set to 1 or 2
248
258
  */
@@ -284,7 +294,8 @@ struct IndexIVF : Index, Level1Quantizer {
284
294
  idx_t k,
285
295
  float* distances,
286
296
  idx_t* labels,
287
- float* recons) const override;
297
+ float* recons,
298
+ const SearchParameters* params = nullptr) const override;
288
299
 
289
300
  /** Reconstruct a vector given the location in terms of (inv list index +
290
301
  * inv list offset) instead of the id.
@@ -302,15 +313,9 @@ struct IndexIVF : Index, Level1Quantizer {
302
313
 
303
314
  size_t remove_ids(const IDSelector& sel) override;
304
315
 
305
- /** check that the two indexes are compatible (ie, they are
306
- * trained in the same way and have the same
307
- * parameters). Otherwise throw. */
308
- void check_compatible_for_merge(const IndexIVF& other) const;
316
+ void check_compatible_for_merge(const Index& otherIndex) const override;
309
317
 
310
- /** moves the entries from another dataset to self. On output,
311
- * other is empty. add_id is added to all moved ids (for
312
- * sequential ids, this would be this->ntotal */
313
- virtual void merge_from(IndexIVF& other, idx_t add_id);
318
+ virtual void merge_from(Index& otherIndex, idx_t add_id) override;
314
319
 
315
320
  /** copy a subset of the entries index to the other index
316
321
  *
@@ -331,6 +336,9 @@ struct IndexIVF : Index, Level1Quantizer {
331
336
  return invlists->list_size(list_no);
332
337
  }
333
338
 
339
+ /// are the ids sorted?
340
+ bool check_ids_sorted() const;
341
+
334
342
  /** intialize a direct map
335
343
  *
336
344
  * @param new_maintain_direct_map if true, create a direct map,
@@ -363,7 +371,15 @@ struct InvertedListScanner {
363
371
  idx_t list_no = -1; ///< remember current list
364
372
  bool keep_max = false; ///< keep maximum instead of minimum
365
373
  /// store positions in invlists rather than labels
366
- bool store_pairs = false;
374
+ bool store_pairs;
375
+
376
+ /// search in this subset of ids
377
+ const IDSelector* sel;
378
+
379
+ InvertedListScanner(
380
+ bool store_pairs = false,
381
+ const IDSelector* sel = nullptr)
382
+ : store_pairs(store_pairs), sel(sel) {}
367
383
 
368
384
  /// used in default implementation of scan_codes
369
385
  size_t code_size = 0;
@@ -411,6 +427,9 @@ struct InvertedListScanner {
411
427
  virtual ~InvertedListScanner() {}
412
428
  };
413
429
 
430
+ // whether to check that coarse quantizers are the same
431
+ FAISS_API extern bool check_compatible_for_merge_expensive_check;
432
+
414
433
  struct IndexIVFStats {
415
434
  size_t nq; // nb of queries run
416
435
  size_t nlist; // nb of inverted lists scanned
@@ -5,9 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- // quiet the noise
9
- // XXclang-format off
10
-
11
8
  #include <faiss/IndexIVFAdditiveQuantizer.h>
12
9
 
13
10
  #include <algorithm>
@@ -44,10 +41,14 @@ void IndexIVFAdditiveQuantizer::train_residual(idx_t n, const float* x) {
44
41
  const float* x_in = x;
45
42
 
46
43
  size_t max_train_points = 1024 * ((size_t)1 << aq->nbits[0]);
44
+ // we need more data to train LSQ
45
+ if (dynamic_cast<LocalSearchQuantizer*>(aq)) {
46
+ max_train_points = 1024 * aq->M * ((size_t)1 << aq->nbits[0]);
47
+ }
47
48
 
48
49
  x = fvecs_maybe_subsample(
49
50
  d, (size_t*)&n, max_train_points, x, verbose, 1234);
50
- ScopeDeleter1<float> del_x(x_in == x ? nullptr : x);
51
+ ScopeDeleter<float> del_x(x_in == x ? nullptr : x);
51
52
 
52
53
  if (by_residual) {
53
54
  std::vector<Index::idx_t> idx(n);
@@ -76,7 +77,7 @@ void IndexIVFAdditiveQuantizer::encode_vectors(
76
77
  // subtract centroids
77
78
  std::vector<float> residuals(n * d);
78
79
 
79
- #pragma omp parallel if (n > 10000)
80
+ #pragma omp parallel for if (n > 10000)
80
81
  for (idx_t i = 0; i < n; i++) {
81
82
  quantizer->compute_residual(
82
83
  x + i * d,
@@ -99,6 +100,32 @@ void IndexIVFAdditiveQuantizer::encode_vectors(
99
100
  }
100
101
  }
101
102
 
103
+ void IndexIVFAdditiveQuantizer::sa_decode(
104
+ idx_t n,
105
+ const uint8_t* codes,
106
+ float* x) const {
107
+ const size_t coarse_size = coarse_code_size();
108
+
109
+ #pragma omp parallel if (n > 1000)
110
+ {
111
+ std::vector<float> residual(d);
112
+
113
+ #pragma omp for
114
+ for (idx_t i = 0; i < n; i++) {
115
+ const uint8_t* code = codes + i * (code_size + coarse_size);
116
+ int64_t list_no = decode_listno(code);
117
+ float* xi = x + i * d;
118
+ aq->decode(code + coarse_size, xi, 1);
119
+ if (by_residual) {
120
+ quantizer->reconstruct(list_no, residual.data());
121
+ for (size_t j = 0; j < d; j++) {
122
+ xi[j] += residual[j];
123
+ }
124
+ }
125
+ }
126
+ }
127
+ }
128
+
102
129
  IndexIVFAdditiveQuantizer::~IndexIVFAdditiveQuantizer() {}
103
130
 
104
131
  /*********************************************
@@ -220,7 +247,9 @@ struct AQInvertedListScannerLUT : AQInvertedListScanner {
220
247
  } // anonymous namespace
221
248
 
222
249
  InvertedListScanner* IndexIVFAdditiveQuantizer::get_InvertedListScanner(
223
- bool store_pairs) const {
250
+ bool store_pairs,
251
+ const IDSelector* sel) const {
252
+ FAISS_THROW_IF_NOT(!sel);
224
253
  if (metric_type == METRIC_INNER_PRODUCT) {
225
254
  if (aq->search_type == AdditiveQuantizer::ST_decompress) {
226
255
  return new AQInvertedListScannerDecompress<true>(
@@ -244,8 +273,10 @@ InvertedListScanner* IndexIVFAdditiveQuantizer::get_InvertedListScanner(
244
273
  A(ST_norm_float)
245
274
  A(ST_norm_qint8)
246
275
  A(ST_norm_qint4)
247
- A(ST_norm_cqint8)
248
276
  A(ST_norm_cqint4)
277
+ case AdditiveQuantizer::ST_norm_lsq2x4:
278
+ case AdditiveQuantizer::ST_norm_rq2x4:
279
+ A(ST_norm_cqint8)
249
280
  #undef A
250
281
  default:
251
282
  FAISS_THROW_FMT(
@@ -313,4 +344,50 @@ IndexIVFLocalSearchQuantizer::IndexIVFLocalSearchQuantizer()
313
344
 
314
345
  IndexIVFLocalSearchQuantizer::~IndexIVFLocalSearchQuantizer() {}
315
346
 
347
+ /**************************************************************************************
348
+ * IndexIVFProductResidualQuantizer
349
+ **************************************************************************************/
350
+
351
+ IndexIVFProductResidualQuantizer::IndexIVFProductResidualQuantizer(
352
+ Index* quantizer,
353
+ size_t d,
354
+ size_t nlist,
355
+ size_t nsplits,
356
+ size_t Msub,
357
+ size_t nbits,
358
+ MetricType metric,
359
+ Search_type_t search_type)
360
+ : IndexIVFAdditiveQuantizer(&prq, quantizer, d, nlist, metric),
361
+ prq(d, nsplits, Msub, nbits, search_type) {
362
+ code_size = invlists->code_size = prq.code_size;
363
+ }
364
+
365
+ IndexIVFProductResidualQuantizer::IndexIVFProductResidualQuantizer()
366
+ : IndexIVFAdditiveQuantizer(&prq) {}
367
+
368
+ IndexIVFProductResidualQuantizer::~IndexIVFProductResidualQuantizer() {}
369
+
370
+ /**************************************************************************************
371
+ * IndexIVFProductLocalSearchQuantizer
372
+ **************************************************************************************/
373
+
374
+ IndexIVFProductLocalSearchQuantizer::IndexIVFProductLocalSearchQuantizer(
375
+ Index* quantizer,
376
+ size_t d,
377
+ size_t nlist,
378
+ size_t nsplits,
379
+ size_t Msub,
380
+ size_t nbits,
381
+ MetricType metric,
382
+ Search_type_t search_type)
383
+ : IndexIVFAdditiveQuantizer(&plsq, quantizer, d, nlist, metric),
384
+ plsq(d, nsplits, Msub, nbits, search_type) {
385
+ code_size = invlists->code_size = plsq.code_size;
386
+ }
387
+
388
+ IndexIVFProductLocalSearchQuantizer::IndexIVFProductLocalSearchQuantizer()
389
+ : IndexIVFAdditiveQuantizer(&plsq) {}
390
+
391
+ IndexIVFProductLocalSearchQuantizer::~IndexIVFProductLocalSearchQuantizer() {}
392
+
316
393
  } // namespace faiss
@@ -15,6 +15,7 @@
15
15
 
16
16
  #include <faiss/IndexIVF.h>
17
17
  #include <faiss/impl/LocalSearchQuantizer.h>
18
+ #include <faiss/impl/ProductAdditiveQuantizer.h>
18
19
  #include <faiss/impl/ResidualQuantizer.h>
19
20
  #include <faiss/impl/platform_macros.h>
20
21
 
@@ -49,7 +50,10 @@ struct IndexIVFAdditiveQuantizer : IndexIVF {
49
50
  bool include_listnos = false) const override;
50
51
 
51
52
  InvertedListScanner* get_InvertedListScanner(
52
- bool store_pairs) const override;
53
+ bool store_pairs,
54
+ const IDSelector* sel) const override;
55
+
56
+ void sa_decode(idx_t n, const uint8_t* codes, float* x) const override;
53
57
 
54
58
  ~IndexIVFAdditiveQuantizer() override;
55
59
  };
@@ -116,6 +120,64 @@ struct IndexIVFLocalSearchQuantizer : IndexIVFAdditiveQuantizer {
116
120
  virtual ~IndexIVFLocalSearchQuantizer();
117
121
  };
118
122
 
123
+ /** IndexIVF based on a product residual quantizer. Stored vectors are
124
+ * approximated by product residual quantization codes.
125
+ */
126
+ struct IndexIVFProductResidualQuantizer : IndexIVFAdditiveQuantizer {
127
+ /// The product residual quantizer used to encode the vectors
128
+ ProductResidualQuantizer prq;
129
+
130
+ /** Constructor.
131
+ *
132
+ * @param d dimensionality of the input vectors
133
+ * @param nsplits number of residual quantizers
134
+ * @param Msub number of subquantizers per RQ
135
+ * @param nbits number of bit per subvector index
136
+ */
137
+ IndexIVFProductResidualQuantizer(
138
+ Index* quantizer,
139
+ size_t d,
140
+ size_t nlist,
141
+ size_t nsplits,
142
+ size_t Msub,
143
+ size_t nbits,
144
+ MetricType metric = METRIC_L2,
145
+ Search_type_t search_type = AdditiveQuantizer::ST_decompress);
146
+
147
+ IndexIVFProductResidualQuantizer();
148
+
149
+ virtual ~IndexIVFProductResidualQuantizer();
150
+ };
151
+
152
+ /** IndexIVF based on a product local search quantizer. Stored vectors are
153
+ * approximated by product local search quantization codes.
154
+ */
155
+ struct IndexIVFProductLocalSearchQuantizer : IndexIVFAdditiveQuantizer {
156
+ /// The product local search quantizer used to encode the vectors
157
+ ProductLocalSearchQuantizer plsq;
158
+
159
+ /** Constructor.
160
+ *
161
+ * @param d dimensionality of the input vectors
162
+ * @param nsplits number of local search quantizers
163
+ * @param Msub number of subquantizers per LSQ
164
+ * @param nbits number of bit per subvector index
165
+ */
166
+ IndexIVFProductLocalSearchQuantizer(
167
+ Index* quantizer,
168
+ size_t d,
169
+ size_t nlist,
170
+ size_t nsplits,
171
+ size_t Msub,
172
+ size_t nbits,
173
+ MetricType metric = METRIC_L2,
174
+ Search_type_t search_type = AdditiveQuantizer::ST_decompress);
175
+
176
+ IndexIVFProductLocalSearchQuantizer();
177
+
178
+ virtual ~IndexIVFProductLocalSearchQuantizer();
179
+ };
180
+
119
181
  } // namespace faiss
120
182
 
121
183
  #endif