faiss 0.4.2 → 0.5.0

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 (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/ext/faiss/index.cpp +36 -10
  4. data/ext/faiss/index_binary.cpp +19 -6
  5. data/ext/faiss/kmeans.cpp +6 -6
  6. data/ext/faiss/numo.hpp +273 -123
  7. data/lib/faiss/version.rb +1 -1
  8. data/vendor/faiss/faiss/AutoTune.cpp +2 -3
  9. data/vendor/faiss/faiss/AutoTune.h +1 -1
  10. data/vendor/faiss/faiss/Clustering.cpp +2 -2
  11. data/vendor/faiss/faiss/Clustering.h +2 -2
  12. data/vendor/faiss/faiss/IVFlib.cpp +1 -2
  13. data/vendor/faiss/faiss/IVFlib.h +1 -1
  14. data/vendor/faiss/faiss/Index.h +10 -10
  15. data/vendor/faiss/faiss/Index2Layer.cpp +1 -1
  16. data/vendor/faiss/faiss/Index2Layer.h +2 -2
  17. data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +9 -4
  18. data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +5 -1
  19. data/vendor/faiss/faiss/IndexBinary.h +7 -7
  20. data/vendor/faiss/faiss/IndexBinaryFromFloat.h +1 -1
  21. data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +3 -1
  22. data/vendor/faiss/faiss/IndexBinaryHNSW.h +1 -1
  23. data/vendor/faiss/faiss/IndexBinaryHash.cpp +3 -3
  24. data/vendor/faiss/faiss/IndexBinaryHash.h +5 -5
  25. data/vendor/faiss/faiss/IndexBinaryIVF.cpp +7 -6
  26. data/vendor/faiss/faiss/IndexFastScan.cpp +125 -49
  27. data/vendor/faiss/faiss/IndexFastScan.h +107 -7
  28. data/vendor/faiss/faiss/IndexFlat.h +1 -1
  29. data/vendor/faiss/faiss/IndexHNSW.cpp +3 -1
  30. data/vendor/faiss/faiss/IndexHNSW.h +1 -1
  31. data/vendor/faiss/faiss/IndexIDMap.cpp +14 -13
  32. data/vendor/faiss/faiss/IndexIDMap.h +6 -6
  33. data/vendor/faiss/faiss/IndexIVF.cpp +1 -1
  34. data/vendor/faiss/faiss/IndexIVF.h +5 -5
  35. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +1 -1
  36. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +9 -3
  37. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +3 -1
  38. data/vendor/faiss/faiss/IndexIVFFastScan.cpp +176 -90
  39. data/vendor/faiss/faiss/IndexIVFFastScan.h +173 -18
  40. data/vendor/faiss/faiss/IndexIVFFlat.cpp +1 -0
  41. data/vendor/faiss/faiss/IndexIVFFlatPanorama.cpp +366 -0
  42. data/vendor/faiss/faiss/IndexIVFFlatPanorama.h +64 -0
  43. data/vendor/faiss/faiss/IndexIVFPQ.cpp +3 -1
  44. data/vendor/faiss/faiss/IndexIVFPQ.h +1 -1
  45. data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +134 -2
  46. data/vendor/faiss/faiss/IndexIVFPQFastScan.h +7 -1
  47. data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +13 -6
  48. data/vendor/faiss/faiss/IndexIVFRaBitQ.h +1 -0
  49. data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +650 -0
  50. data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +216 -0
  51. data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +1 -1
  52. data/vendor/faiss/faiss/IndexIVFSpectralHash.h +1 -1
  53. data/vendor/faiss/faiss/IndexNNDescent.cpp +1 -1
  54. data/vendor/faiss/faiss/IndexNSG.cpp +1 -1
  55. data/vendor/faiss/faiss/IndexNeuralNetCodec.h +1 -1
  56. data/vendor/faiss/faiss/IndexPQ.h +1 -1
  57. data/vendor/faiss/faiss/IndexPQFastScan.cpp +6 -2
  58. data/vendor/faiss/faiss/IndexPQFastScan.h +5 -1
  59. data/vendor/faiss/faiss/IndexRaBitQ.cpp +13 -10
  60. data/vendor/faiss/faiss/IndexRaBitQ.h +7 -2
  61. data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +586 -0
  62. data/vendor/faiss/faiss/IndexRaBitQFastScan.h +149 -0
  63. data/vendor/faiss/faiss/IndexShards.cpp +1 -1
  64. data/vendor/faiss/faiss/MatrixStats.cpp +3 -3
  65. data/vendor/faiss/faiss/MetricType.h +1 -1
  66. data/vendor/faiss/faiss/VectorTransform.h +2 -2
  67. data/vendor/faiss/faiss/clone_index.cpp +3 -1
  68. data/vendor/faiss/faiss/gpu/GpuCloner.cpp +1 -1
  69. data/vendor/faiss/faiss/gpu/GpuIndex.h +11 -11
  70. data/vendor/faiss/faiss/gpu/GpuIndexBinaryCagra.h +1 -1
  71. data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +1 -1
  72. data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +10 -6
  73. data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +2 -0
  74. data/vendor/faiss/faiss/gpu/test/TestGpuIcmEncoder.cpp +7 -0
  75. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +1 -1
  76. data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +1 -1
  77. data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +1 -1
  78. data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +2 -2
  79. data/vendor/faiss/faiss/impl/AuxIndexStructures.h +1 -1
  80. data/vendor/faiss/faiss/impl/CodePacker.h +2 -2
  81. data/vendor/faiss/faiss/impl/DistanceComputer.h +3 -3
  82. data/vendor/faiss/faiss/impl/FastScanDistancePostProcessing.h +53 -0
  83. data/vendor/faiss/faiss/impl/HNSW.cpp +1 -1
  84. data/vendor/faiss/faiss/impl/HNSW.h +4 -4
  85. data/vendor/faiss/faiss/impl/IDSelector.cpp +2 -2
  86. data/vendor/faiss/faiss/impl/IDSelector.h +1 -1
  87. data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +4 -4
  88. data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +1 -1
  89. data/vendor/faiss/faiss/impl/LookupTableScaler.h +1 -1
  90. data/vendor/faiss/faiss/impl/NNDescent.cpp +1 -1
  91. data/vendor/faiss/faiss/impl/NNDescent.h +2 -2
  92. data/vendor/faiss/faiss/impl/NSG.cpp +1 -1
  93. data/vendor/faiss/faiss/impl/PanoramaStats.cpp +33 -0
  94. data/vendor/faiss/faiss/impl/PanoramaStats.h +38 -0
  95. data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +5 -5
  96. data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +1 -1
  97. data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.h +1 -1
  98. data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +2 -0
  99. data/vendor/faiss/faiss/impl/ProductQuantizer.h +1 -1
  100. data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +246 -0
  101. data/vendor/faiss/faiss/impl/RaBitQUtils.h +153 -0
  102. data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +54 -158
  103. data/vendor/faiss/faiss/impl/RaBitQuantizer.h +2 -1
  104. data/vendor/faiss/faiss/impl/ResidualQuantizer.h +1 -1
  105. data/vendor/faiss/faiss/impl/ResultHandler.h +4 -4
  106. data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +1 -1
  107. data/vendor/faiss/faiss/impl/ScalarQuantizer.h +1 -1
  108. data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +7 -4
  109. data/vendor/faiss/faiss/impl/index_read.cpp +87 -3
  110. data/vendor/faiss/faiss/impl/index_write.cpp +73 -3
  111. data/vendor/faiss/faiss/impl/io.cpp +2 -2
  112. data/vendor/faiss/faiss/impl/io.h +4 -4
  113. data/vendor/faiss/faiss/impl/kmeans1d.cpp +1 -1
  114. data/vendor/faiss/faiss/impl/kmeans1d.h +1 -1
  115. data/vendor/faiss/faiss/impl/lattice_Zn.h +2 -2
  116. data/vendor/faiss/faiss/impl/mapped_io.cpp +2 -2
  117. data/vendor/faiss/faiss/impl/mapped_io.h +4 -3
  118. data/vendor/faiss/faiss/impl/maybe_owned_vector.h +8 -1
  119. data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +30 -4
  120. data/vendor/faiss/faiss/impl/pq4_fast_scan.h +14 -8
  121. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +5 -6
  122. data/vendor/faiss/faiss/impl/simd_result_handlers.h +55 -11
  123. data/vendor/faiss/faiss/impl/zerocopy_io.h +1 -1
  124. data/vendor/faiss/faiss/index_factory.cpp +43 -1
  125. data/vendor/faiss/faiss/index_factory.h +1 -1
  126. data/vendor/faiss/faiss/index_io.h +1 -1
  127. data/vendor/faiss/faiss/invlists/InvertedLists.cpp +205 -0
  128. data/vendor/faiss/faiss/invlists/InvertedLists.h +62 -0
  129. data/vendor/faiss/faiss/utils/AlignedTable.h +1 -1
  130. data/vendor/faiss/faiss/utils/Heap.cpp +2 -2
  131. data/vendor/faiss/faiss/utils/Heap.h +3 -3
  132. data/vendor/faiss/faiss/utils/NeuralNet.cpp +1 -1
  133. data/vendor/faiss/faiss/utils/NeuralNet.h +3 -3
  134. data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +2 -2
  135. data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +2 -2
  136. data/vendor/faiss/faiss/utils/approx_topk/mode.h +1 -1
  137. data/vendor/faiss/faiss/utils/distances.h +2 -2
  138. data/vendor/faiss/faiss/utils/extra_distances-inl.h +3 -1
  139. data/vendor/faiss/faiss/utils/hamming-inl.h +2 -0
  140. data/vendor/faiss/faiss/utils/hamming.cpp +7 -6
  141. data/vendor/faiss/faiss/utils/hamming.h +1 -1
  142. data/vendor/faiss/faiss/utils/hamming_distance/common.h +1 -2
  143. data/vendor/faiss/faiss/utils/partitioning.cpp +5 -5
  144. data/vendor/faiss/faiss/utils/partitioning.h +2 -2
  145. data/vendor/faiss/faiss/utils/rabitq_simd.h +222 -336
  146. data/vendor/faiss/faiss/utils/random.cpp +1 -1
  147. data/vendor/faiss/faiss/utils/simdlib_avx2.h +1 -1
  148. data/vendor/faiss/faiss/utils/simdlib_avx512.h +1 -1
  149. data/vendor/faiss/faiss/utils/simdlib_neon.h +2 -2
  150. data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +1 -1
  151. data/vendor/faiss/faiss/utils/utils.cpp +5 -2
  152. data/vendor/faiss/faiss/utils/utils.h +2 -2
  153. metadata +14 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67b63e8dcaa5dcd8c8d08f823c3e1e063906b4a20ad70b28c2fd396e8cccdf48
4
- data.tar.gz: 7e9fddc693db40a58c71b5a5ca6b89638b5cc1db708b30ea32a897519d48b970
3
+ metadata.gz: f3306dbb81c9168dcd82435c99d3404ab8501ac9b948adb2db7238ab89c01003
4
+ data.tar.gz: b14a120e9cc67baba96816b52cf34388aae79fa690fc511918543921b64380d5
5
5
  SHA512:
6
- metadata.gz: 10b9b0efa35ab53fefd3cea964339c856b67af1f7c773f421952f247d16fbd50d76b29cf59eec9e3b77b1a091e96fccb58c1f24afde7d233f298f06ecc90b3b3
7
- data.tar.gz: 70037e0611a6f6adddf30f95710b0e1f1c17ffadfe561c3010db8e66265692da17b49a07756ee946d70eed6602ddfbd2107248c01be353d58d3544b6bbc2b15e
6
+ metadata.gz: b7af3f6540d283d886301137e5fed5dff32b0c0659e9c46d6c45808439e94a0a91f8c953d5897b480568169ec23cacc4224db523d6ab9b3737d7f0df1ce8190c
7
+ data.tar.gz: fbe44473d9e3c61427aee597fed40264ba83a8184c0fe5280b6bf181d9bcc396583f033a69e8d3ec643ee0d41ef435dfeef4aa4441ade67703cbd8259326cb81
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.5.0 (2025-11-12)
2
+
3
+ - Updated Faiss to 1.13.0
4
+ - Added support for releasing GVL
5
+
6
+ ## 0.4.3 (2025-10-26)
7
+
8
+ - Fixed error with Rice 4.7
9
+
1
10
  ## 0.4.2 (2025-08-13)
2
11
 
3
12
  - Updated Faiss to 1.12.0
data/ext/faiss/index.cpp CHANGED
@@ -29,7 +29,7 @@ namespace Rice::detail {
29
29
  public:
30
30
  From_Ruby() = default;
31
31
 
32
- From_Ruby(Arg* arg) : arg_(arg) {}
32
+ explicit From_Ruby(Arg* arg) : arg_(arg) { }
33
33
 
34
34
  Convertible is_convertible(VALUE value) { return Convertible::Cast; }
35
35
 
@@ -49,7 +49,7 @@ namespace Rice::detail {
49
49
  }
50
50
 
51
51
  private:
52
- Arg* arg_;
52
+ Arg* arg_ = nullptr;
53
53
  };
54
54
 
55
55
  template<>
@@ -60,6 +60,10 @@ namespace Rice::detail {
60
60
  template<>
61
61
  class From_Ruby<faiss::ScalarQuantizer::QuantizerType> {
62
62
  public:
63
+ From_Ruby() = default;
64
+
65
+ explicit From_Ruby(Arg* arg) : arg_(arg) { }
66
+
63
67
  Convertible is_convertible(VALUE value) { return Convertible::Cast; }
64
68
 
65
69
  faiss::ScalarQuantizer::QuantizerType convert(VALUE x) {
@@ -82,6 +86,9 @@ namespace Rice::detail {
82
86
  throw Rice::Exception(rb_eArgError, "Invalid quantizer type: %s", s.c_str());
83
87
  }
84
88
  }
89
+
90
+ private:
91
+ Arg* arg_ = nullptr;
85
92
  };
86
93
  } // namespace Rice::detail
87
94
 
@@ -104,19 +111,28 @@ void init_index(Rice::Module& m) {
104
111
  })
105
112
  .define_method(
106
113
  "train",
107
- [](faiss::Index &self, numo::SFloat objects) {
114
+ [](Rice::Object rb_self, numo::SFloat objects) {
115
+ rb_check_frozen(rb_self.value());
116
+
117
+ auto &self = *Rice::Data_Object<faiss::Index>{rb_self};
108
118
  auto n = check_shape(objects, self.d);
109
119
  self.train(n, objects.read_ptr());
110
120
  })
111
121
  .define_method(
112
122
  "add",
113
- [](faiss::Index &self, numo::SFloat objects) {
123
+ [](Rice::Object rb_self, numo::SFloat objects) {
124
+ rb_check_frozen(rb_self.value());
125
+
126
+ auto &self = *Rice::Data_Object<faiss::Index>{rb_self};
114
127
  auto n = check_shape(objects, self.d);
115
128
  self.add(n, objects.read_ptr());
116
129
  })
117
130
  .define_method(
118
131
  "add_with_ids",
119
- [](faiss::Index &self, numo::SFloat objects, numo::Int64 ids) {
132
+ [](Rice::Object rb_self, numo::SFloat objects, numo::Int64 ids) {
133
+ rb_check_frozen(rb_self.value());
134
+
135
+ auto &self = *Rice::Data_Object<faiss::Index>{rb_self};
120
136
  auto n = check_shape(objects, self.d);
121
137
  if (ids.ndim() != 1 || ids.shape()[0] != n) {
122
138
  throw Rice::Exception(rb_eArgError, "expected ids to be 1d array with size %d", n);
@@ -125,22 +141,32 @@ void init_index(Rice::Module& m) {
125
141
  })
126
142
  .define_method(
127
143
  "search",
128
- [](faiss::Index &self, numo::SFloat objects, size_t k) {
144
+ [](Rice::Object rb_self, numo::SFloat objects, size_t k) {
145
+ auto &self = *Rice::Data_Object<faiss::Index>{rb_self};
129
146
  auto n = check_shape(objects, self.d);
130
147
 
131
148
  auto distances = numo::SFloat({n, k});
132
149
  auto labels = numo::Int64({n, k});
133
150
 
134
- self.search(n, objects.read_ptr(), k, distances.write_ptr(), labels.write_ptr());
151
+ if (rb_self.is_frozen()) {
152
+ Rice::detail::no_gvl([&] {
153
+ self.search(n, objects.read_ptr(), k, distances.write_ptr(), labels.write_ptr());
154
+ });
155
+ } else {
156
+ self.search(n, objects.read_ptr(), k, distances.write_ptr(), labels.write_ptr());
157
+ }
135
158
 
136
159
  Rice::Array ret;
137
- ret.push(distances);
138
- ret.push(labels);
160
+ ret.push(std::move(distances), false);
161
+ ret.push(std::move(labels), false);
139
162
  return ret;
140
163
  })
141
164
  .define_method(
142
165
  "nprobe=",
143
- [](faiss::Index &self, double val) {
166
+ [](Rice::Object rb_self, double val) {
167
+ rb_check_frozen(rb_self.value());
168
+
169
+ auto &self = *Rice::Data_Object<faiss::Index>{rb_self};
144
170
  faiss::ParameterSpace().set_index_parameter(&self, "nprobe", val);
145
171
  })
146
172
  .define_method(
@@ -27,29 +27,42 @@ void init_index_binary(Rice::Module& m) {
27
27
  })
28
28
  .define_method(
29
29
  "train",
30
- [](faiss::IndexBinary &self, numo::UInt8 objects) {
30
+ [](Rice::Object rb_self, numo::UInt8 objects) {
31
+ rb_check_frozen(rb_self.value());
32
+
33
+ auto &self = *Rice::Data_Object<faiss::IndexBinary>{rb_self};
31
34
  auto n = check_shape(objects, self.d / 8);
32
35
  self.train(n, objects.read_ptr());
33
36
  })
34
37
  .define_method(
35
38
  "add",
36
- [](faiss::IndexBinary &self, numo::UInt8 objects) {
39
+ [](Rice::Object rb_self, numo::UInt8 objects) {
40
+ rb_check_frozen(rb_self.value());
41
+
42
+ auto &self = *Rice::Data_Object<faiss::IndexBinary>{rb_self};
37
43
  auto n = check_shape(objects, self.d / 8);
38
44
  self.add(n, objects.read_ptr());
39
45
  })
40
46
  .define_method(
41
47
  "search",
42
- [](faiss::IndexBinary &self, numo::UInt8 objects, size_t k) {
48
+ [](Rice::Object rb_self, numo::UInt8 objects, size_t k) {
49
+ auto &self = *Rice::Data_Object<faiss::IndexBinary>{rb_self};
43
50
  auto n = check_shape(objects, self.d / 8);
44
51
 
45
52
  auto distances = numo::Int32({n, k});
46
53
  auto labels = numo::Int64({n, k});
47
54
 
48
- self.search(n, objects.read_ptr(), k, distances.write_ptr(), labels.write_ptr());
55
+ if (rb_self.is_frozen()) {
56
+ Rice::detail::no_gvl([&] {
57
+ self.search(n, objects.read_ptr(), k, distances.write_ptr(), labels.write_ptr());
58
+ });
59
+ } else {
60
+ self.search(n, objects.read_ptr(), k, distances.write_ptr(), labels.write_ptr());
61
+ }
49
62
 
50
63
  Rice::Array ret;
51
- ret.push(distances);
52
- ret.push(labels);
64
+ ret.push(std::move(distances), false);
65
+ ret.push(std::move(labels), false);
53
66
  return ret;
54
67
  })
55
68
  .define_method(
data/ext/faiss/kmeans.cpp CHANGED
@@ -32,11 +32,11 @@ void init_kmeans(Rice::Module& m) {
32
32
  })
33
33
  .define_method(
34
34
  "train",
35
- [](Rice::Object self, numo::SFloat objects) {
36
- auto self_ptr = Rice::detail::From_Ruby<faiss::Clustering*>().convert(self.value());
37
- auto n = check_shape(objects, self_ptr->d);
38
- auto index = faiss::IndexFlatL2(self_ptr->d);
39
- self.iv_set("@index", Rice::Object(Rice::detail::To_Ruby<faiss::IndexFlatL2>().convert(index)));
40
- self_ptr->train(n, objects.read_ptr(), index);
35
+ [](Rice::Object rb_self, numo::SFloat objects) {
36
+ auto &self = *Rice::Data_Object<faiss::Clustering>{rb_self};
37
+ auto n = check_shape(objects, self.d);
38
+ auto index = faiss::IndexFlatL2(self.d);
39
+ rb_self.iv_set("@index", index);
40
+ self.train(n, objects.read_ptr(), index);
41
41
  });
42
42
  }