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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/ext/faiss/index.cpp +36 -10
- data/ext/faiss/index_binary.cpp +19 -6
- data/ext/faiss/kmeans.cpp +6 -6
- data/ext/faiss/numo.hpp +273 -123
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +2 -3
- data/vendor/faiss/faiss/AutoTune.h +1 -1
- data/vendor/faiss/faiss/Clustering.cpp +2 -2
- data/vendor/faiss/faiss/Clustering.h +2 -2
- data/vendor/faiss/faiss/IVFlib.cpp +1 -2
- data/vendor/faiss/faiss/IVFlib.h +1 -1
- data/vendor/faiss/faiss/Index.h +10 -10
- data/vendor/faiss/faiss/Index2Layer.cpp +1 -1
- data/vendor/faiss/faiss/Index2Layer.h +2 -2
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +9 -4
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +5 -1
- data/vendor/faiss/faiss/IndexBinary.h +7 -7
- data/vendor/faiss/faiss/IndexBinaryFromFloat.h +1 -1
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +3 -1
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +1 -1
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +3 -3
- data/vendor/faiss/faiss/IndexBinaryHash.h +5 -5
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +7 -6
- data/vendor/faiss/faiss/IndexFastScan.cpp +125 -49
- data/vendor/faiss/faiss/IndexFastScan.h +107 -7
- data/vendor/faiss/faiss/IndexFlat.h +1 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +3 -1
- data/vendor/faiss/faiss/IndexHNSW.h +1 -1
- data/vendor/faiss/faiss/IndexIDMap.cpp +14 -13
- data/vendor/faiss/faiss/IndexIDMap.h +6 -6
- data/vendor/faiss/faiss/IndexIVF.cpp +1 -1
- data/vendor/faiss/faiss/IndexIVF.h +5 -5
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +9 -3
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +3 -1
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +176 -90
- data/vendor/faiss/faiss/IndexIVFFastScan.h +173 -18
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +1 -0
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.cpp +366 -0
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.h +64 -0
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +3 -1
- data/vendor/faiss/faiss/IndexIVFPQ.h +1 -1
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +134 -2
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +7 -1
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +13 -6
- data/vendor/faiss/faiss/IndexIVFRaBitQ.h +1 -0
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +650 -0
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +216 -0
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +1 -1
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +1 -1
- data/vendor/faiss/faiss/IndexNNDescent.cpp +1 -1
- data/vendor/faiss/faiss/IndexNSG.cpp +1 -1
- data/vendor/faiss/faiss/IndexNeuralNetCodec.h +1 -1
- data/vendor/faiss/faiss/IndexPQ.h +1 -1
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +6 -2
- data/vendor/faiss/faiss/IndexPQFastScan.h +5 -1
- data/vendor/faiss/faiss/IndexRaBitQ.cpp +13 -10
- data/vendor/faiss/faiss/IndexRaBitQ.h +7 -2
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +586 -0
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +149 -0
- data/vendor/faiss/faiss/IndexShards.cpp +1 -1
- data/vendor/faiss/faiss/MatrixStats.cpp +3 -3
- data/vendor/faiss/faiss/MetricType.h +1 -1
- data/vendor/faiss/faiss/VectorTransform.h +2 -2
- data/vendor/faiss/faiss/clone_index.cpp +3 -1
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +1 -1
- data/vendor/faiss/faiss/gpu/GpuIndex.h +11 -11
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryCagra.h +1 -1
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +1 -1
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +10 -6
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +2 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIcmEncoder.cpp +7 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +1 -1
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +2 -2
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +1 -1
- data/vendor/faiss/faiss/impl/CodePacker.h +2 -2
- data/vendor/faiss/faiss/impl/DistanceComputer.h +3 -3
- data/vendor/faiss/faiss/impl/FastScanDistancePostProcessing.h +53 -0
- data/vendor/faiss/faiss/impl/HNSW.cpp +1 -1
- data/vendor/faiss/faiss/impl/HNSW.h +4 -4
- data/vendor/faiss/faiss/impl/IDSelector.cpp +2 -2
- data/vendor/faiss/faiss/impl/IDSelector.h +1 -1
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +4 -4
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/LookupTableScaler.h +1 -1
- data/vendor/faiss/faiss/impl/NNDescent.cpp +1 -1
- data/vendor/faiss/faiss/impl/NNDescent.h +2 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +1 -1
- data/vendor/faiss/faiss/impl/PanoramaStats.cpp +33 -0
- data/vendor/faiss/faiss/impl/PanoramaStats.h +38 -0
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +5 -5
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +2 -0
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +246 -0
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +153 -0
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +54 -158
- data/vendor/faiss/faiss/impl/RaBitQuantizer.h +2 -1
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ResultHandler.h +4 -4
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +7 -4
- data/vendor/faiss/faiss/impl/index_read.cpp +87 -3
- data/vendor/faiss/faiss/impl/index_write.cpp +73 -3
- data/vendor/faiss/faiss/impl/io.cpp +2 -2
- data/vendor/faiss/faiss/impl/io.h +4 -4
- data/vendor/faiss/faiss/impl/kmeans1d.cpp +1 -1
- data/vendor/faiss/faiss/impl/kmeans1d.h +1 -1
- data/vendor/faiss/faiss/impl/lattice_Zn.h +2 -2
- data/vendor/faiss/faiss/impl/mapped_io.cpp +2 -2
- data/vendor/faiss/faiss/impl/mapped_io.h +4 -3
- data/vendor/faiss/faiss/impl/maybe_owned_vector.h +8 -1
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +30 -4
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +14 -8
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +5 -6
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +55 -11
- data/vendor/faiss/faiss/impl/zerocopy_io.h +1 -1
- data/vendor/faiss/faiss/index_factory.cpp +43 -1
- data/vendor/faiss/faiss/index_factory.h +1 -1
- data/vendor/faiss/faiss/index_io.h +1 -1
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +205 -0
- data/vendor/faiss/faiss/invlists/InvertedLists.h +62 -0
- data/vendor/faiss/faiss/utils/AlignedTable.h +1 -1
- data/vendor/faiss/faiss/utils/Heap.cpp +2 -2
- data/vendor/faiss/faiss/utils/Heap.h +3 -3
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +1 -1
- data/vendor/faiss/faiss/utils/NeuralNet.h +3 -3
- data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/mode.h +1 -1
- data/vendor/faiss/faiss/utils/distances.h +2 -2
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +3 -1
- data/vendor/faiss/faiss/utils/hamming-inl.h +2 -0
- data/vendor/faiss/faiss/utils/hamming.cpp +7 -6
- data/vendor/faiss/faiss/utils/hamming.h +1 -1
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +1 -2
- data/vendor/faiss/faiss/utils/partitioning.cpp +5 -5
- data/vendor/faiss/faiss/utils/partitioning.h +2 -2
- data/vendor/faiss/faiss/utils/rabitq_simd.h +222 -336
- data/vendor/faiss/faiss/utils/random.cpp +1 -1
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +1 -1
- data/vendor/faiss/faiss/utils/simdlib_avx512.h +1 -1
- data/vendor/faiss/faiss/utils/simdlib_neon.h +2 -2
- data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +1 -1
- data/vendor/faiss/faiss/utils/utils.cpp +5 -2
- data/vendor/faiss/faiss/utils/utils.h +2 -2
- metadata +14 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f3306dbb81c9168dcd82435c99d3404ab8501ac9b948adb2db7238ab89c01003
|
|
4
|
+
data.tar.gz: b14a120e9cc67baba96816b52cf34388aae79fa690fc511918543921b64380d5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b7af3f6540d283d886301137e5fed5dff32b0c0659e9c46d6c45808439e94a0a91f8c953d5897b480568169ec23cacc4224db523d6ab9b3737d7f0df1ce8190c
|
|
7
|
+
data.tar.gz: fbe44473d9e3c61427aee597fed40264ba83a8184c0fe5280b6bf181d9bcc396583f033a69e8d3ec643ee0d41ef435dfeef4aa4441ade67703cbd8259326cb81
|
data/CHANGELOG.md
CHANGED
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
|
-
[](
|
|
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
|
-
[](
|
|
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
|
-
[](
|
|
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
|
-
[](
|
|
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
|
-
|
|
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
|
-
[](
|
|
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(
|
data/ext/faiss/index_binary.cpp
CHANGED
|
@@ -27,29 +27,42 @@ void init_index_binary(Rice::Module& m) {
|
|
|
27
27
|
})
|
|
28
28
|
.define_method(
|
|
29
29
|
"train",
|
|
30
|
-
[](
|
|
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
|
-
[](
|
|
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
|
-
[](
|
|
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
|
-
|
|
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
|
|
36
|
-
auto
|
|
37
|
-
auto n = check_shape(objects,
|
|
38
|
-
auto index = faiss::IndexFlatL2(
|
|
39
|
-
|
|
40
|
-
|
|
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
|
}
|