faiss 0.2.6 → 0.2.7

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 (189) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/ext/faiss/extconf.rb +1 -1
  4. data/lib/faiss/version.rb +1 -1
  5. data/lib/faiss.rb +2 -2
  6. data/vendor/faiss/faiss/AutoTune.cpp +15 -4
  7. data/vendor/faiss/faiss/AutoTune.h +0 -1
  8. data/vendor/faiss/faiss/Clustering.cpp +1 -5
  9. data/vendor/faiss/faiss/Clustering.h +0 -2
  10. data/vendor/faiss/faiss/IVFlib.h +0 -2
  11. data/vendor/faiss/faiss/Index.h +1 -2
  12. data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +17 -3
  13. data/vendor/faiss/faiss/IndexAdditiveQuantizer.h +10 -1
  14. data/vendor/faiss/faiss/IndexBinary.h +0 -1
  15. data/vendor/faiss/faiss/IndexBinaryFlat.cpp +2 -1
  16. data/vendor/faiss/faiss/IndexBinaryFlat.h +4 -0
  17. data/vendor/faiss/faiss/IndexBinaryHash.cpp +1 -3
  18. data/vendor/faiss/faiss/IndexBinaryIVF.cpp +273 -48
  19. data/vendor/faiss/faiss/IndexBinaryIVF.h +18 -11
  20. data/vendor/faiss/faiss/IndexFastScan.cpp +13 -10
  21. data/vendor/faiss/faiss/IndexFastScan.h +5 -1
  22. data/vendor/faiss/faiss/IndexFlat.cpp +16 -3
  23. data/vendor/faiss/faiss/IndexFlat.h +1 -1
  24. data/vendor/faiss/faiss/IndexFlatCodes.cpp +5 -0
  25. data/vendor/faiss/faiss/IndexFlatCodes.h +7 -2
  26. data/vendor/faiss/faiss/IndexHNSW.cpp +3 -6
  27. data/vendor/faiss/faiss/IndexHNSW.h +0 -1
  28. data/vendor/faiss/faiss/IndexIDMap.cpp +4 -4
  29. data/vendor/faiss/faiss/IndexIDMap.h +0 -2
  30. data/vendor/faiss/faiss/IndexIVF.cpp +155 -129
  31. data/vendor/faiss/faiss/IndexIVF.h +121 -61
  32. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +2 -2
  33. data/vendor/faiss/faiss/IndexIVFFastScan.cpp +12 -11
  34. data/vendor/faiss/faiss/IndexIVFFastScan.h +6 -1
  35. data/vendor/faiss/faiss/IndexIVFPQ.cpp +221 -165
  36. data/vendor/faiss/faiss/IndexIVFPQ.h +1 -0
  37. data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +6 -1
  38. data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +0 -2
  39. data/vendor/faiss/faiss/IndexNNDescent.cpp +1 -2
  40. data/vendor/faiss/faiss/IndexNNDescent.h +0 -1
  41. data/vendor/faiss/faiss/IndexNSG.cpp +1 -2
  42. data/vendor/faiss/faiss/IndexPQ.cpp +7 -9
  43. data/vendor/faiss/faiss/IndexRefine.cpp +1 -1
  44. data/vendor/faiss/faiss/IndexReplicas.cpp +3 -4
  45. data/vendor/faiss/faiss/IndexReplicas.h +0 -1
  46. data/vendor/faiss/faiss/IndexRowwiseMinMax.cpp +8 -1
  47. data/vendor/faiss/faiss/IndexRowwiseMinMax.h +7 -0
  48. data/vendor/faiss/faiss/IndexShards.cpp +26 -109
  49. data/vendor/faiss/faiss/IndexShards.h +2 -3
  50. data/vendor/faiss/faiss/IndexShardsIVF.cpp +246 -0
  51. data/vendor/faiss/faiss/IndexShardsIVF.h +42 -0
  52. data/vendor/faiss/faiss/MetaIndexes.cpp +86 -0
  53. data/vendor/faiss/faiss/MetaIndexes.h +29 -0
  54. data/vendor/faiss/faiss/MetricType.h +14 -0
  55. data/vendor/faiss/faiss/VectorTransform.cpp +8 -10
  56. data/vendor/faiss/faiss/VectorTransform.h +1 -3
  57. data/vendor/faiss/faiss/clone_index.cpp +232 -18
  58. data/vendor/faiss/faiss/cppcontrib/SaDecodeKernels.h +25 -3
  59. data/vendor/faiss/faiss/cppcontrib/detail/CoarseBitType.h +7 -0
  60. data/vendor/faiss/faiss/cppcontrib/detail/UintReader.h +78 -0
  61. data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +20 -6
  62. data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +7 -1
  63. data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-neon-inl.h +21 -7
  64. data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMax-inl.h +7 -0
  65. data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMaxFP16-inl.h +7 -0
  66. data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-avx2-inl.h +10 -3
  67. data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-inl.h +7 -1
  68. data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-neon-inl.h +11 -3
  69. data/vendor/faiss/faiss/gpu/GpuAutoTune.cpp +25 -2
  70. data/vendor/faiss/faiss/gpu/GpuCloner.cpp +76 -29
  71. data/vendor/faiss/faiss/gpu/GpuCloner.h +2 -2
  72. data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +14 -13
  73. data/vendor/faiss/faiss/gpu/GpuDistance.h +18 -6
  74. data/vendor/faiss/faiss/gpu/GpuIndex.h +23 -21
  75. data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +10 -10
  76. data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +11 -12
  77. data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +29 -50
  78. data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +3 -3
  79. data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +8 -8
  80. data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +4 -4
  81. data/vendor/faiss/faiss/gpu/impl/IndexUtils.h +2 -5
  82. data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +9 -7
  83. data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +4 -4
  84. data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +2 -2
  85. data/vendor/faiss/faiss/gpu/perf/IndexWrapper.h +1 -1
  86. data/vendor/faiss/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +55 -6
  87. data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +20 -6
  88. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +95 -25
  89. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +67 -16
  90. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +4 -4
  91. data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +7 -7
  92. data/vendor/faiss/faiss/gpu/test/TestUtils.h +4 -4
  93. data/vendor/faiss/faiss/gpu/test/demo_ivfpq_indexing_gpu.cpp +1 -1
  94. data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +6 -0
  95. data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +0 -7
  96. data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +9 -9
  97. data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +1 -1
  98. data/vendor/faiss/faiss/impl/AuxIndexStructures.h +2 -7
  99. data/vendor/faiss/faiss/impl/CodePacker.cpp +67 -0
  100. data/vendor/faiss/faiss/impl/CodePacker.h +71 -0
  101. data/vendor/faiss/faiss/impl/DistanceComputer.h +0 -2
  102. data/vendor/faiss/faiss/impl/HNSW.cpp +3 -7
  103. data/vendor/faiss/faiss/impl/HNSW.h +6 -9
  104. data/vendor/faiss/faiss/impl/IDSelector.cpp +1 -1
  105. data/vendor/faiss/faiss/impl/IDSelector.h +39 -1
  106. data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +62 -51
  107. data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +11 -12
  108. data/vendor/faiss/faiss/impl/NNDescent.cpp +3 -9
  109. data/vendor/faiss/faiss/impl/NNDescent.h +10 -10
  110. data/vendor/faiss/faiss/impl/NSG.cpp +1 -6
  111. data/vendor/faiss/faiss/impl/NSG.h +4 -7
  112. data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +1 -15
  113. data/vendor/faiss/faiss/impl/PolysemousTraining.h +11 -10
  114. data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +0 -7
  115. data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +25 -12
  116. data/vendor/faiss/faiss/impl/ProductQuantizer.h +2 -4
  117. data/vendor/faiss/faiss/impl/Quantizer.h +6 -3
  118. data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +796 -174
  119. data/vendor/faiss/faiss/impl/ResidualQuantizer.h +16 -8
  120. data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +3 -5
  121. data/vendor/faiss/faiss/impl/ScalarQuantizer.h +4 -4
  122. data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +3 -3
  123. data/vendor/faiss/faiss/impl/ThreadedIndex.h +4 -4
  124. data/vendor/faiss/faiss/impl/code_distance/code_distance-avx2.h +291 -0
  125. data/vendor/faiss/faiss/impl/code_distance/code_distance-generic.h +74 -0
  126. data/vendor/faiss/faiss/impl/code_distance/code_distance.h +123 -0
  127. data/vendor/faiss/faiss/impl/code_distance/code_distance_avx512.h +102 -0
  128. data/vendor/faiss/faiss/impl/index_read.cpp +13 -10
  129. data/vendor/faiss/faiss/impl/index_write.cpp +3 -4
  130. data/vendor/faiss/faiss/impl/kmeans1d.cpp +0 -1
  131. data/vendor/faiss/faiss/impl/kmeans1d.h +3 -3
  132. data/vendor/faiss/faiss/impl/lattice_Zn.cpp +1 -1
  133. data/vendor/faiss/faiss/impl/platform_macros.h +61 -0
  134. data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +48 -4
  135. data/vendor/faiss/faiss/impl/pq4_fast_scan.h +18 -4
  136. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +2 -2
  137. data/vendor/faiss/faiss/index_factory.cpp +8 -10
  138. data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +29 -12
  139. data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +8 -2
  140. data/vendor/faiss/faiss/invlists/DirectMap.cpp +1 -1
  141. data/vendor/faiss/faiss/invlists/DirectMap.h +2 -4
  142. data/vendor/faiss/faiss/invlists/InvertedLists.cpp +118 -18
  143. data/vendor/faiss/faiss/invlists/InvertedLists.h +44 -4
  144. data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +3 -3
  145. data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +1 -1
  146. data/vendor/faiss/faiss/python/python_callbacks.cpp +1 -1
  147. data/vendor/faiss/faiss/python/python_callbacks.h +1 -1
  148. data/vendor/faiss/faiss/utils/AlignedTable.h +3 -1
  149. data/vendor/faiss/faiss/utils/Heap.cpp +139 -3
  150. data/vendor/faiss/faiss/utils/Heap.h +35 -1
  151. data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +84 -0
  152. data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +196 -0
  153. data/vendor/faiss/faiss/utils/approx_topk/generic.h +138 -0
  154. data/vendor/faiss/faiss/utils/approx_topk/mode.h +34 -0
  155. data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +367 -0
  156. data/vendor/faiss/faiss/utils/distances.cpp +61 -7
  157. data/vendor/faiss/faiss/utils/distances.h +11 -0
  158. data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +346 -0
  159. data/vendor/faiss/faiss/utils/distances_fused/avx512.h +36 -0
  160. data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +42 -0
  161. data/vendor/faiss/faiss/utils/distances_fused/distances_fused.h +40 -0
  162. data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +352 -0
  163. data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.h +32 -0
  164. data/vendor/faiss/faiss/utils/distances_simd.cpp +515 -327
  165. data/vendor/faiss/faiss/utils/extra_distances-inl.h +17 -1
  166. data/vendor/faiss/faiss/utils/extra_distances.cpp +37 -8
  167. data/vendor/faiss/faiss/utils/extra_distances.h +2 -1
  168. data/vendor/faiss/faiss/utils/fp16-fp16c.h +7 -0
  169. data/vendor/faiss/faiss/utils/fp16-inl.h +7 -0
  170. data/vendor/faiss/faiss/utils/fp16.h +7 -0
  171. data/vendor/faiss/faiss/utils/hamming-inl.h +0 -456
  172. data/vendor/faiss/faiss/utils/hamming.cpp +104 -120
  173. data/vendor/faiss/faiss/utils/hamming.h +21 -10
  174. data/vendor/faiss/faiss/utils/hamming_distance/avx2-inl.h +535 -0
  175. data/vendor/faiss/faiss/utils/hamming_distance/common.h +48 -0
  176. data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +519 -0
  177. data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +26 -0
  178. data/vendor/faiss/faiss/utils/hamming_distance/neon-inl.h +614 -0
  179. data/vendor/faiss/faiss/utils/partitioning.cpp +21 -25
  180. data/vendor/faiss/faiss/utils/simdlib_avx2.h +344 -3
  181. data/vendor/faiss/faiss/utils/simdlib_emulated.h +390 -0
  182. data/vendor/faiss/faiss/utils/simdlib_neon.h +655 -130
  183. data/vendor/faiss/faiss/utils/sorting.cpp +692 -0
  184. data/vendor/faiss/faiss/utils/sorting.h +71 -0
  185. data/vendor/faiss/faiss/utils/transpose/transpose-avx2-inl.h +165 -0
  186. data/vendor/faiss/faiss/utils/utils.cpp +4 -176
  187. data/vendor/faiss/faiss/utils/utils.h +2 -9
  188. metadata +29 -3
  189. data/vendor/faiss/faiss/gpu/GpuClonerOptions.cpp +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a12656e91180940d60fdd412b6f179cd0faa8a6b473aaadfa0bc4a371131464
4
- data.tar.gz: 1076b01164ff1702abc8a9184410e0f8417199056698628ff2b0e5bf641cf168
3
+ metadata.gz: 8d0e67c5b23ef30f3632f8f878bba1ed8be7cbf8212c21a799daca8a65c23fcb
4
+ data.tar.gz: d3bcbf4453ece0531cb3cfa017bf60327fffa47401a27451ccb501c11431911e
5
5
  SHA512:
6
- metadata.gz: 1298e0ed4b4455c478ee94384dbd02b4a029ea96409d66cf0b0e4292e51acde782d6bd875470c093a07198b99e222a366878d7019b6dc499221ee8b126a95cd7
7
- data.tar.gz: 4b61b0fa059d240b568e176abdffff5b56a06e16598c185795e4d437bb0581a1cafb36794dd799168512b010ba71858837a30f3197be9b781510e50d3d4a268b
6
+ metadata.gz: 50f4c6ef3b637b708e0860f524eabb64b708868ce8210153f0868ff846a67ec24c4f229cf9146ab1dea0113b033e2287866ced15e750297ae79822cf9f131fe2
7
+ data.tar.gz: a3b0df6f2377c7381fdaab54f56e97a80ebaf5e752b92ba04b5d7a256c493a2bcbb14d60e4eeeb26a0d044f3159b4e416699ab6ecf774eb92f6e6014958d20b7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.2.7 (2023-04-20)
2
+
3
+ - Updated Faiss to 1.7.4
4
+
1
5
  ## 0.2.6 (2023-04-11)
2
6
 
3
7
  - Added `add_with_ids` method
data/ext/faiss/extconf.rb CHANGED
@@ -26,7 +26,7 @@ $CXXFLAGS << " -std=c++17 $(optflags) -DFINTEGER=int " << with_config("optflags"
26
26
  ext = File.expand_path(".", __dir__)
27
27
  vendor = File.expand_path("../../vendor/faiss", __dir__)
28
28
 
29
- $srcs = Dir["{#{ext},#{vendor}/faiss,#{vendor}/faiss/{impl,invlists,utils}}/*.{cpp}"]
29
+ $srcs = Dir["{#{ext},#{vendor}/faiss,#{vendor}/faiss/{impl,invlists,utils}/**}/*.{cpp}"]
30
30
  $objs = $srcs.map { |v| v.sub(/cpp\z/, "o") }
31
31
  abort "Faiss not found" unless find_header("faiss/Index.h", vendor)
32
32
  $VPATH << vendor
data/lib/faiss/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Faiss
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
data/lib/faiss.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  require "numo/narray"
3
3
 
4
4
  # ext
5
- require "faiss/ext"
5
+ require_relative "faiss/ext"
6
6
 
7
7
  # modules
8
- require "faiss/version"
8
+ require_relative "faiss/version"
@@ -32,6 +32,7 @@
32
32
  #include <faiss/IndexPreTransform.h>
33
33
  #include <faiss/IndexRefine.h>
34
34
  #include <faiss/IndexScalarQuantizer.h>
35
+ #include <faiss/IndexShardsIVF.h>
35
36
  #include <faiss/MetaIndexes.h>
36
37
  #include <faiss/VectorTransform.h>
37
38
 
@@ -354,7 +355,7 @@ void ParameterSpace::initialize(const Index* index) {
354
355
  index = ix->index;
355
356
  }
356
357
 
357
- if (DC(IndexIVF)) {
358
+ if (DC(IndexIVFInterface)) {
358
359
  {
359
360
  ParameterRange& pr = add_range("nprobe");
360
361
  for (int i = 0; i < 13; i++) {
@@ -461,6 +462,16 @@ void ParameterSpace::set_index_parameter(
461
462
  set_index_parameter(ix->index, name, val);
462
463
  return;
463
464
  }
465
+ if (DC(IndexShardsIVF)) {
466
+ // special handling because the nprobe is set at the sub-class level
467
+ // but other params are set on the class itself
468
+ if (name.find("quantizer_") == 0 && name != "nprobe" &&
469
+ name != "quantizer_nprobe") {
470
+ std::string sub_name = name.substr(strlen("quantizer_"));
471
+ set_index_parameter(ix->quantizer, sub_name, val);
472
+ return;
473
+ }
474
+ }
464
475
  if (DC(ThreadedIndex<Index>)) {
465
476
  // call on all sub-indexes
466
477
  auto fn = [this, name, val](int /* no */, Index* subIndex) {
@@ -608,7 +619,7 @@ void ParameterSpace::explore(
608
619
  if (n_experiments == 0) {
609
620
  for (size_t cno = 0; cno < n_comb; cno++) {
610
621
  set_index_parameters(index, cno);
611
- std::vector<Index::idx_t> I(nq * crit.nnn);
622
+ std::vector<idx_t> I(nq * crit.nnn);
612
623
  std::vector<float> D(nq * crit.nnn);
613
624
 
614
625
  double t0 = getmillisecs();
@@ -677,7 +688,7 @@ void ParameterSpace::explore(
677
688
  }
678
689
 
679
690
  set_index_parameters(index, cno);
680
- std::vector<Index::idx_t> I(nq * crit.nnn);
691
+ std::vector<idx_t> I(nq * crit.nnn);
681
692
  std::vector<float> D(nq * crit.nnn);
682
693
 
683
694
  double t0 = getmillisecs();
@@ -688,7 +699,7 @@ void ParameterSpace::explore(
688
699
  do {
689
700
  if (thread_over_batches) {
690
701
  #pragma omp parallel for
691
- for (Index::idx_t q0 = 0; q0 < nq; q0 += batchsize) {
702
+ for (idx_t q0 = 0; q0 < nq; q0 += batchsize) {
692
703
  size_t q1 = q0 + batchsize;
693
704
  if (q1 > nq)
694
705
  q1 = nq;
@@ -24,7 +24,6 @@ namespace faiss {
24
24
  * higher is better.
25
25
  */
26
26
  struct AutoTuneCriterion {
27
- typedef Index::idx_t idx_t;
28
27
  idx_t nq; ///< nb of queries this criterion is evaluated on
29
28
  idx_t nnn; ///< nb of NNs that the query should request
30
29
  idx_t gt_nnn; ///< nb of GT NNs required to evaluate criterion
@@ -88,8 +88,6 @@ void Clustering::train(
88
88
 
89
89
  namespace {
90
90
 
91
- using idx_t = Clustering::idx_t;
92
-
93
91
  idx_t subsample_training_set(
94
92
  const Clustering& clus,
95
93
  idx_t nx,
@@ -374,7 +372,7 @@ void Clustering::train_encoded(
374
372
  std::unique_ptr<float[]> dis(new float[nx]);
375
373
 
376
374
  // remember best iteration for redo
377
- bool lower_is_better = index.metric_type != METRIC_INNER_PRODUCT;
375
+ bool lower_is_better = !is_similarity_metric(index.metric_type);
378
376
  float best_obj = lower_is_better ? HUGE_VALF : -HUGE_VALF;
379
377
  std::vector<ClusteringIterationStats> best_iteration_stats;
380
378
  std::vector<float> best_centroids;
@@ -624,8 +622,6 @@ ProgressiveDimClustering::ProgressiveDimClustering(
624
622
 
625
623
  namespace {
626
624
 
627
- using idx_t = Index::idx_t;
628
-
629
625
  void copy_columns(idx_t n, idx_t d1, const float* src, idx_t d2, float* dest) {
630
626
  idx_t d = std::min(d1, d2);
631
627
  for (idx_t i = 0; i < n; i++) {
@@ -61,7 +61,6 @@ struct ClusteringIterationStats {
61
61
  *
62
62
  */
63
63
  struct Clustering : ClusteringParameters {
64
- typedef Index::idx_t idx_t;
65
64
  size_t d; ///< dimension of the vectors
66
65
  size_t k; ///< nb of centroids
67
66
 
@@ -154,7 +153,6 @@ struct ProgressiveDimIndexFactory {
154
153
  * https://arxiv.org/abs/1509.05195
155
154
  */
156
155
  struct ProgressiveDimClustering : ProgressiveDimClusteringParameters {
157
- using idx_t = Index::idx_t;
158
156
  size_t d; ///< dimension of the vectors
159
157
  size_t k; ///< nb of centroids
160
158
 
@@ -48,8 +48,6 @@ IndexIVF* try_extract_index_ivf(Index* index);
48
48
  */
49
49
  void merge_into(Index* index0, Index* index1, bool shift_ids);
50
50
 
51
- typedef Index::idx_t idx_t;
52
-
53
51
  /* Returns the cluster the embeddings belong to.
54
52
  *
55
53
  * @param index Index, which should be an IVF index
@@ -18,7 +18,7 @@
18
18
 
19
19
  #define FAISS_VERSION_MAJOR 1
20
20
  #define FAISS_VERSION_MINOR 7
21
- #define FAISS_VERSION_PATCH 3
21
+ #define FAISS_VERSION_PATCH 4
22
22
 
23
23
  /**
24
24
  * @namespace faiss
@@ -62,7 +62,6 @@ struct SearchParameters {
62
62
  * although the internal representation may vary.
63
63
  */
64
64
  struct Index {
65
- using idx_t = int64_t; ///< all indices are this type
66
65
  using component_t = float;
67
66
  using distance_t = float;
68
67
 
@@ -484,7 +484,7 @@ ResidualCoarseQuantizer::ResidualCoarseQuantizer(
484
484
  int d, ///< dimensionality of the input vectors
485
485
  const std::vector<size_t>& nbits,
486
486
  MetricType metric)
487
- : AdditiveCoarseQuantizer(d, &rq, metric), rq(d, nbits), beam_factor(4.0) {
487
+ : AdditiveCoarseQuantizer(d, &rq, metric), rq(d, nbits) {
488
488
  FAISS_THROW_IF_NOT(rq.tot_bits <= 63);
489
489
  is_trained = false;
490
490
  }
@@ -520,10 +520,15 @@ void ResidualCoarseQuantizer::search(
520
520
  idx_t k,
521
521
  float* distances,
522
522
  idx_t* labels,
523
- const SearchParameters * params
523
+ const SearchParameters * params_in
524
524
  ) const {
525
525
 
526
- FAISS_THROW_IF_NOT_MSG(!params, "search params not supported for this index");
526
+ float beam_factor = this->beam_factor;
527
+ if (params_in) {
528
+ auto params = dynamic_cast<const SearchParametersResidualCoarseQuantizer*>(params_in);
529
+ FAISS_THROW_IF_NOT_MSG(params, "need SearchParametersResidualCoarseQuantizer parameters");
530
+ beam_factor = params->beam_factor;
531
+ }
527
532
 
528
533
  if (beam_factor < 0) {
529
534
  AdditiveCoarseQuantizer::search(n, x, k, distances, labels);
@@ -585,6 +590,15 @@ void ResidualCoarseQuantizer::search(
585
590
  }
586
591
  }
587
592
 
593
+ void ResidualCoarseQuantizer::initialize_from(const ResidualCoarseQuantizer &other) {
594
+ FAISS_THROW_IF_NOT(rq.M <= other.rq.M);
595
+ rq.initialize_from(other.rq);
596
+ set_beam_factor(other.beam_factor);
597
+ is_trained = other.is_trained;
598
+ ntotal = (idx_t)1 << aq->tot_bits;
599
+ }
600
+
601
+
588
602
  /**************************************************************************************
589
603
  * LocalSearchCoarseQuantizer
590
604
  **************************************************************************************/
@@ -187,6 +187,11 @@ struct AdditiveCoarseQuantizer : Index {
187
187
  void reset() override;
188
188
  };
189
189
 
190
+ struct SearchParametersResidualCoarseQuantizer : SearchParameters {
191
+ float beam_factor = 4.0f;
192
+ ~SearchParametersResidualCoarseQuantizer() {}
193
+ };
194
+
190
195
  /** The ResidualCoarseQuantizer is a bit specialized compared to the
191
196
  * default AdditiveCoarseQuantizer because it can use a beam search
192
197
  * at search time (slow but may be useful for very large vocabularies) */
@@ -196,7 +201,7 @@ struct ResidualCoarseQuantizer : AdditiveCoarseQuantizer {
196
201
 
197
202
  /// factor between the beam size and the search k
198
203
  /// if negative, use exact search-to-centroid
199
- float beam_factor;
204
+ float beam_factor = 4.0f;
200
205
 
201
206
  /// computes centroid norms if required
202
207
  void set_beam_factor(float new_beam_factor);
@@ -226,6 +231,10 @@ struct ResidualCoarseQuantizer : AdditiveCoarseQuantizer {
226
231
  idx_t* labels,
227
232
  const SearchParameters* params = nullptr) const override;
228
233
 
234
+ /** Copy the M first codebook levels from other. Useful to crop a
235
+ * ResidualQuantizer to its first M quantizers. */
236
+ void initialize_from(const ResidualCoarseQuantizer& other);
237
+
229
238
  ResidualCoarseQuantizer();
230
239
  };
231
240
 
@@ -32,7 +32,6 @@ struct RangeSearchResult;
32
32
  * vectors.
33
33
  */
34
34
  struct IndexBinary {
35
- using idx_t = Index::idx_t; ///< all indices are this type
36
35
  using component_t = uint8_t;
37
36
  using distance_t = int32_t;
38
37
 
@@ -60,7 +60,8 @@ void IndexBinaryFlat::search(
60
60
  xb.data(),
61
61
  ntotal,
62
62
  code_size,
63
- /* ordered = */ true);
63
+ /* ordered = */ true,
64
+ approx_topk_mode);
64
65
  } else {
65
66
  hammings_knn_mc(
66
67
  x + s * code_size,
@@ -14,6 +14,8 @@
14
14
 
15
15
  #include <faiss/IndexBinary.h>
16
16
 
17
+ #include <faiss/utils/approx_topk/mode.h>
18
+
17
19
  namespace faiss {
18
20
 
19
21
  /** Index that stores the full vectors and performs exhaustive search. */
@@ -28,6 +30,8 @@ struct IndexBinaryFlat : IndexBinary {
28
30
 
29
31
  size_t query_batch_size = 32;
30
32
 
33
+ ApproxTopK_mode_t approx_topk_mode = ApproxTopK_mode_t::EXACT_TOPK;
34
+
31
35
  explicit IndexBinaryFlat(idx_t d);
32
36
 
33
37
  void add(idx_t n, const uint8_t* x) override;
@@ -108,8 +108,6 @@ struct FlipEnumerator {
108
108
  }
109
109
  };
110
110
 
111
- using idx_t = Index::idx_t;
112
-
113
111
  struct RangeSearchResults {
114
112
  int radius;
115
113
  RangeQueryResult& qres;
@@ -353,7 +351,7 @@ template <class HammingComputer, class SearchResults>
353
351
  static void verify_shortlist(
354
352
  const IndexBinaryFlat& index,
355
353
  const uint8_t* q,
356
- const std::unordered_set<Index::idx_t>& shortlist,
354
+ const std::unordered_set<idx_t>& shortlist,
357
355
  SearchResults& res) {
358
356
  size_t code_size = index.code_size;
359
357
  size_t nlist = 0, ndis = 0, n0 = 0;