faiss 0.6.5 → 0.6.6
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 +5 -0
- data/ext/faiss/extconf.rb +1 -0
- data/ext/faiss/index.cpp +42 -0
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/IVFlib.cpp +48 -51
- data/vendor/faiss/faiss/IVFlib.h +6 -2
- data/vendor/faiss/faiss/Index.cpp +2 -2
- data/vendor/faiss/faiss/Index.h +3 -3
- data/vendor/faiss/faiss/IndexBinary.cpp +2 -2
- data/vendor/faiss/faiss/IndexBinary.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +1 -0
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +6 -3
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +6 -11
- data/vendor/faiss/faiss/IndexFastScan.cpp +1 -1
- data/vendor/faiss/faiss/IndexFlat.cpp +1 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +12 -10
- data/vendor/faiss/faiss/IndexHNSW.h +2 -5
- data/vendor/faiss/faiss/IndexIDMap.cpp +17 -4
- data/vendor/faiss/faiss/IndexIDMap.h +10 -5
- data/vendor/faiss/faiss/IndexIVF.cpp +68 -37
- data/vendor/faiss/faiss/IndexIVF.h +37 -1
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +5 -15
- data/vendor/faiss/faiss/IndexIVFFlat.h +6 -6
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +1 -1
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +28 -44
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +2 -11
- data/vendor/faiss/faiss/IndexIVFRaBitQSSD.cpp +1694 -0
- data/vendor/faiss/faiss/IndexIVFRaBitQSSD.h +288 -0
- data/vendor/faiss/faiss/IndexIVFSQFastScan.cpp +7 -2
- data/vendor/faiss/faiss/IndexNNDescent.cpp +21 -0
- data/vendor/faiss/faiss/IndexRaBitQ.cpp +189 -41
- data/vendor/faiss/faiss/IndexRaBitQ.h +5 -0
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +1 -1
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +2 -2
- data/vendor/faiss/faiss/SuperKMeans.cpp +2 -2
- data/vendor/faiss/faiss/VectorTransform.cpp +156 -9
- data/vendor/faiss/faiss/VectorTransform.h +24 -1
- data/vendor/faiss/faiss/factory_tools.cpp +19 -1
- data/vendor/faiss/faiss/gpu/Dataset.h +66 -14
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryCagra.h +8 -2
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +8 -2
- data/vendor/faiss/faiss/gpu/impl/optimal_kmeans/GpuOptimalKMeans.h +184 -0
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +12 -4
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +6 -5
- data/vendor/faiss/faiss/gpu_metal/GpuIndexFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalDistance.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalFlatKernels.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexBinaryFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFPQ.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalPythonBridge.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalResources.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/StandardMetalResources.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFPQ.h +1 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +1 -1
- data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +31 -50
- data/vendor/faiss/faiss/impl/ClusteringInitialization.h +0 -15
- data/vendor/faiss/faiss/impl/CodePacker.cpp +2 -2
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +2 -2
- data/vendor/faiss/faiss/impl/DeterministicNNDescent.cpp +2167 -0
- data/vendor/faiss/faiss/impl/DeterministicNNDescent.h +301 -0
- data/vendor/faiss/faiss/impl/HNSW.cpp +2 -2
- data/vendor/faiss/faiss/impl/HNSW.h +2 -2
- data/vendor/faiss/faiss/impl/IDSelector.h +5 -4
- data/vendor/faiss/faiss/impl/NNDescent.h +4 -0
- data/vendor/faiss/faiss/impl/PiPNN.cpp +4 -2
- data/vendor/faiss/faiss/impl/PiPNN.h +1 -1
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +1 -1
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +0 -2
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +29 -0
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +14 -13
- data/vendor/faiss/faiss/impl/ResultHandler.h +116 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryIVF_impl.h +1 -3
- data/vendor/faiss/faiss/impl/expanded_scanners.h +29 -24
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.cpp +68 -6
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.h +43 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +15 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +115 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +13 -0
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd256.h +84 -0
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd512.h +0 -4
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_result_handler.h +0 -1
- data/vendor/faiss/faiss/impl/fast_scan/simd_result_handlers.h +64 -55
- data/vendor/faiss/faiss/impl/hnsw/LockVector.h +1 -2
- data/vendor/faiss/faiss/impl/index_read.cpp +146 -9
- data/vendor/faiss/faiss/impl/index_write.cpp +29 -5
- data/vendor/faiss/faiss/impl/io.cpp +1 -0
- data/vendor/faiss/faiss/impl/io_macros.h +2 -2
- data/vendor/faiss/faiss/impl/mapped_io.cpp +3 -1
- data/vendor/faiss/faiss/impl/maybe_owned_vector.h +78 -41
- data/vendor/faiss/faiss/impl/nndescent/gram-avx2.cpp +121 -0
- data/vendor/faiss/faiss/impl/nndescent/gram-avx512.cpp +124 -0
- data/vendor/faiss/faiss/impl/nndescent/gram-neon.cpp +114 -0
- data/vendor/faiss/faiss/impl/nndescent/gram.h +66 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-avx512.cpp +431 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-inl.h +1157 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.cpp +282 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.h +226 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.cpp +1567 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.h +281 -0
- data/vendor/faiss/faiss/impl/pipnn/HashPrune.cpp +1 -1
- data/vendor/faiss/faiss/impl/platform_macros.h +47 -28
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +6 -1
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.cpp +17 -17
- data/vendor/faiss/faiss/impl/result_handler/ResultHandler.cpp +68 -1
- data/vendor/faiss/faiss/impl/result_handler/avx2.cpp +70 -2
- data/vendor/faiss/faiss/impl/result_handler/avx512.cpp +2 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +26 -26
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +48 -45
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-impl.h +34 -32
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-spr.cpp +8 -6
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +4 -3
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +34 -33
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx512.h +20 -20
- data/vendor/faiss/faiss/impl/simdlib/simdlib_neon.h +4 -4
- data/vendor/faiss/faiss/impl/zerocopy_io.cpp +2 -1
- data/vendor/faiss/faiss/index_factory.cpp +30 -6
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +1 -1
- data/vendor/faiss/faiss/invlists/DiskIOBackend.cpp +121 -0
- data/vendor/faiss/faiss/invlists/DiskIOBackend.h +71 -0
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +12 -9
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +26 -0
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +5 -0
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +9 -24
- data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.cpp +751 -0
- data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.h +224 -0
- data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +2 -7
- data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSIVF.cpp +2 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +4 -4
- data/vendor/faiss/faiss/utils/WorkerThread.h +0 -1
- data/vendor/faiss/faiss/utils/distances.cpp +246 -34
- data/vendor/faiss/faiss/utils/distances.h +145 -2
- data/vendor/faiss/faiss/utils/extra_distances.h +2 -1
- data/vendor/faiss/faiss/utils/hamming-inl.h +3 -0
- data/vendor/faiss/faiss/utils/partitioning.cpp +2 -2
- data/vendor/faiss/faiss/utils/rabitq_simd.h +120 -6
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +47 -7
- data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +7 -3
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +47 -7
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +50 -10
- data/vendor/faiss/faiss/utils/simd_impl/distances_simdlib256.h +3 -3
- data/vendor/faiss/faiss/utils/simd_impl/exhaustive_L2sqr_blas_cmax.h +13 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_simdlib256.h +16 -15
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp +131 -36
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +156 -45
- data/vendor/faiss/faiss/utils/simd_levels.cpp +3 -3
- data/vendor/faiss/faiss/utils/sorting.cpp +6 -5
- data/vendor/faiss/faiss/utils/utils.cpp +4 -0
- metadata +20 -1
|
@@ -22,7 +22,9 @@ TEST(TestCodePacking, NonInterleavedCodes_UnpackPack) {
|
|
|
22
22
|
// deterministic
|
|
23
23
|
auto seed = std::random_device()();
|
|
24
24
|
std::mt19937 gen(seed);
|
|
25
|
-
|
|
25
|
+
// uint8_t is not a conforming uniform_int_distribution type (N4950
|
|
26
|
+
// [rand.req.genl]/1.5); MSVC's STL rejects it. Use int over [0,255].
|
|
27
|
+
std::uniform_int_distribution<int> dist{0, 255};
|
|
26
28
|
|
|
27
29
|
std::cout << "seed " << seed << "\n";
|
|
28
30
|
|
|
@@ -74,7 +76,9 @@ TEST(TestCodePacking, NonInterleavedCodes_PackUnpack) {
|
|
|
74
76
|
// deterministic
|
|
75
77
|
std::random_device rd;
|
|
76
78
|
std::mt19937 gen(rd());
|
|
77
|
-
|
|
79
|
+
// uint8_t is not a conforming uniform_int_distribution type (N4950
|
|
80
|
+
// [rand.req.genl]/1.5); MSVC's STL rejects it. Use int over [0,255].
|
|
81
|
+
std::uniform_int_distribution<int> dist{0, 255};
|
|
78
82
|
|
|
79
83
|
for (auto bitsPerCode : {4, 5, 6, 8, 16, 32}) {
|
|
80
84
|
for (auto dims : {1, 7, 8, 31, 32}) {
|
|
@@ -112,7 +116,9 @@ TEST(TestCodePacking, InterleavedCodes_UnpackPack) {
|
|
|
112
116
|
// deterministic
|
|
113
117
|
std::random_device rd;
|
|
114
118
|
std::mt19937 gen(rd());
|
|
115
|
-
|
|
119
|
+
// uint8_t is not a conforming uniform_int_distribution type (N4950
|
|
120
|
+
// [rand.req.genl]/1.5); MSVC's STL rejects it. Use int over [0,255].
|
|
121
|
+
std::uniform_int_distribution<int> dist{0, 255};
|
|
116
122
|
|
|
117
123
|
for (auto bitsPerCode : {4, 5, 6, 8, 16, 32}) {
|
|
118
124
|
for (auto dims : {1, 7, 8, 31, 32}) {
|
|
@@ -249,7 +255,9 @@ TEST(TestCodePacking, InterleavedCodes_PackUnpack) {
|
|
|
249
255
|
// deterministic
|
|
250
256
|
std::random_device rd;
|
|
251
257
|
std::mt19937 gen(rd());
|
|
252
|
-
|
|
258
|
+
// uint8_t is not a conforming uniform_int_distribution type (N4950
|
|
259
|
+
// [rand.req.genl]/1.5); MSVC's STL rejects it. Use int over [0,255].
|
|
260
|
+
std::uniform_int_distribution<int> dist{0, 255};
|
|
253
261
|
|
|
254
262
|
for (auto bitsPerCode : {4, 5, 6, 8, 16, 32}) {
|
|
255
263
|
for (auto dims : {1, 7, 8, 31, 32}) {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
#include <faiss/impl/IDSelector.h>
|
|
10
10
|
#include <faiss/utils/random.h>
|
|
11
11
|
#include <gtest/gtest.h>
|
|
12
|
-
#include <
|
|
12
|
+
#include <chrono>
|
|
13
13
|
#include <cmath>
|
|
14
14
|
#include <set>
|
|
15
15
|
#include <sstream>
|
|
@@ -100,10 +100,11 @@ std::mt19937 rng(1);
|
|
|
100
100
|
std::uniform_int_distribution<> distrib;
|
|
101
101
|
|
|
102
102
|
void newTestSeed() {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
auto ns = std::chrono::high_resolution_clock::now().time_since_epoch();
|
|
104
|
+
setTestSeed(
|
|
105
|
+
static_cast<long>(
|
|
106
|
+
std::chrono::duration_cast<std::chrono::nanoseconds>(ns)
|
|
107
|
+
.count()));
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
void setTestSeed(long seed) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -123,7 +123,7 @@ RangeSearchPartialResult::RangeSearchPartialResult(RangeSearchResult* res_in)
|
|
|
123
123
|
|
|
124
124
|
/// begin a new result
|
|
125
125
|
RangeQueryResult& RangeSearchPartialResult::new_result(idx_t qno) {
|
|
126
|
-
RangeQueryResult qres = {qno, 0, this};
|
|
126
|
+
RangeQueryResult qres = {qno, 0, this, {}};
|
|
127
127
|
queries.push_back(qres);
|
|
128
128
|
return queries.back();
|
|
129
129
|
}
|
|
@@ -392,6 +392,22 @@ void validate_initialization(
|
|
|
392
392
|
n_existing_centroids == 0 || existing_centroids != nullptr);
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
+
void init_random(
|
|
396
|
+
const ClusteringInitialization& initializer,
|
|
397
|
+
size_t n,
|
|
398
|
+
const float* x,
|
|
399
|
+
float* centroids) {
|
|
400
|
+
const size_t d = initializer.d;
|
|
401
|
+
// Use rand_perm for backward compatibility with Clustering.cpp
|
|
402
|
+
// This ensures the same random sequence as the original implementation
|
|
403
|
+
std::vector<int> perm(n);
|
|
404
|
+
rand_perm(perm.data(), n, initializer.seed);
|
|
405
|
+
|
|
406
|
+
for (size_t i = 0; i < initializer.k; i++) {
|
|
407
|
+
std::memcpy(centroids + i * d, x + perm[i] * d, d * sizeof(float));
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
395
411
|
} // namespace
|
|
396
412
|
|
|
397
413
|
ClusteringInitialization::ClusteringInitialization(size_t d_in, size_t k_in)
|
|
@@ -408,66 +424,31 @@ void ClusteringInitialization::init_centroids(
|
|
|
408
424
|
|
|
409
425
|
switch (method) {
|
|
410
426
|
case ClusteringInitMethod::RANDOM:
|
|
411
|
-
init_random(n, x, centroids);
|
|
427
|
+
init_random(*this, n, x, centroids);
|
|
412
428
|
break;
|
|
413
429
|
case ClusteringInitMethod::KMEANS_PLUS_PLUS:
|
|
414
|
-
|
|
415
|
-
|
|
430
|
+
init_kmeans_plus_plus_impl(
|
|
431
|
+
*this,
|
|
432
|
+
n,
|
|
433
|
+
FloatRows{d, x},
|
|
434
|
+
centroids,
|
|
435
|
+
n_existing_centroids,
|
|
436
|
+
existing_centroids);
|
|
416
437
|
break;
|
|
417
438
|
case ClusteringInitMethod::AFK_MC2:
|
|
418
|
-
|
|
419
|
-
|
|
439
|
+
init_afkmc2_impl(
|
|
440
|
+
*this,
|
|
441
|
+
n,
|
|
442
|
+
FloatRows{d, x},
|
|
443
|
+
centroids,
|
|
444
|
+
n_existing_centroids,
|
|
445
|
+
existing_centroids);
|
|
420
446
|
break;
|
|
421
447
|
default:
|
|
422
448
|
FAISS_THROW_MSG("Unknown initialization method");
|
|
423
449
|
}
|
|
424
450
|
}
|
|
425
451
|
|
|
426
|
-
void ClusteringInitialization::init_random(
|
|
427
|
-
size_t n,
|
|
428
|
-
const float* x,
|
|
429
|
-
float* centroids) const {
|
|
430
|
-
// Use rand_perm for backward compatibility with Clustering.cpp
|
|
431
|
-
// This ensures the same random sequence as the original implementation
|
|
432
|
-
std::vector<int> perm(n);
|
|
433
|
-
rand_perm(perm.data(), n, seed);
|
|
434
|
-
|
|
435
|
-
// Copy selected points to centroids
|
|
436
|
-
for (size_t i = 0; i < k; i++) {
|
|
437
|
-
std::memcpy(centroids + i * d, x + perm[i] * d, d * sizeof(float));
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
void ClusteringInitialization::init_kmeans_plus_plus(
|
|
442
|
-
size_t n,
|
|
443
|
-
const float* x,
|
|
444
|
-
float* centroids,
|
|
445
|
-
size_t n_existing_centroids,
|
|
446
|
-
const float* existing_centroids) const {
|
|
447
|
-
init_kmeans_plus_plus_impl(
|
|
448
|
-
*this,
|
|
449
|
-
n,
|
|
450
|
-
FloatRows{d, x},
|
|
451
|
-
centroids,
|
|
452
|
-
n_existing_centroids,
|
|
453
|
-
existing_centroids);
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
void ClusteringInitialization::init_afkmc2(
|
|
457
|
-
size_t n,
|
|
458
|
-
const float* x,
|
|
459
|
-
float* centroids,
|
|
460
|
-
size_t n_existing_centroids,
|
|
461
|
-
const float* existing_centroids) const {
|
|
462
|
-
init_afkmc2_impl(
|
|
463
|
-
*this,
|
|
464
|
-
n,
|
|
465
|
-
FloatRows{d, x},
|
|
466
|
-
centroids,
|
|
467
|
-
n_existing_centroids,
|
|
468
|
-
existing_centroids);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
452
|
namespace detail {
|
|
472
453
|
|
|
473
454
|
void init_centroids_fp16(
|
|
@@ -87,21 +87,6 @@ struct ClusteringInitialization {
|
|
|
87
87
|
float* centroids,
|
|
88
88
|
size_t n_existing_centroids = 0,
|
|
89
89
|
const float* existing_centroids = nullptr) const;
|
|
90
|
-
|
|
91
|
-
private:
|
|
92
|
-
void init_random(size_t n, const float* x, float* centroids) const;
|
|
93
|
-
void init_kmeans_plus_plus(
|
|
94
|
-
size_t n,
|
|
95
|
-
const float* x,
|
|
96
|
-
float* centroids,
|
|
97
|
-
size_t n_existing_centroids,
|
|
98
|
-
const float* existing_centroids) const;
|
|
99
|
-
void init_afkmc2(
|
|
100
|
-
size_t n,
|
|
101
|
-
const float* x,
|
|
102
|
-
float* centroids,
|
|
103
|
-
size_t n_existing_centroids,
|
|
104
|
-
const float* existing_centroids) const;
|
|
105
90
|
};
|
|
106
91
|
|
|
107
92
|
} // namespace faiss
|
|
@@ -50,7 +50,7 @@ void CodePackerFlat::unpack_all(const uint8_t* block, uint8_t* flat_codes)
|
|
|
50
50
|
|
|
51
51
|
void CodePackerFlat::pack_1(
|
|
52
52
|
const uint8_t* flat_code,
|
|
53
|
-
size_t offset,
|
|
53
|
+
[[maybe_unused]] size_t offset,
|
|
54
54
|
uint8_t* block) const {
|
|
55
55
|
assert(offset == 0);
|
|
56
56
|
pack_all(flat_code, block);
|
|
@@ -58,7 +58,7 @@ void CodePackerFlat::pack_1(
|
|
|
58
58
|
|
|
59
59
|
void CodePackerFlat::unpack_1(
|
|
60
60
|
const uint8_t* block,
|
|
61
|
-
size_t offset,
|
|
61
|
+
[[maybe_unused]] size_t offset,
|
|
62
62
|
uint8_t* flat_code) const {
|
|
63
63
|
assert(offset == 0);
|
|
64
64
|
unpack_all(block, flat_code);
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
namespace faiss {
|
|
14
14
|
|
|
15
15
|
CodePackerRaBitQ::CodePackerRaBitQ(
|
|
16
|
-
size_t
|
|
16
|
+
size_t nsq_in,
|
|
17
17
|
size_t bbs,
|
|
18
18
|
size_t aux_per_vector) {
|
|
19
|
-
|
|
19
|
+
nsq = nsq_in;
|
|
20
20
|
this->aux_size_per_vec = aux_per_vector;
|
|
21
21
|
nvec = bbs;
|
|
22
22
|
const size_t pq4_bytes = (nsq * 4 + 7) / 8;
|