faiss 0.3.1 → 0.3.3
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 +8 -0
- data/LICENSE.txt +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +2 -2
- data/vendor/faiss/faiss/AutoTune.h +3 -3
- data/vendor/faiss/faiss/Clustering.cpp +37 -6
- data/vendor/faiss/faiss/Clustering.h +12 -3
- data/vendor/faiss/faiss/IVFlib.cpp +6 -3
- data/vendor/faiss/faiss/IVFlib.h +2 -2
- data/vendor/faiss/faiss/Index.cpp +6 -2
- data/vendor/faiss/faiss/Index.h +30 -8
- data/vendor/faiss/faiss/Index2Layer.cpp +2 -2
- data/vendor/faiss/faiss/Index2Layer.h +2 -2
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +7 -7
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +14 -16
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +2 -2
- data/vendor/faiss/faiss/IndexBinary.cpp +13 -2
- data/vendor/faiss/faiss/IndexBinary.h +8 -2
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +2 -3
- data/vendor/faiss/faiss/IndexBinaryFlat.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +2 -2
- data/vendor/faiss/faiss/IndexBinaryFromFloat.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +2 -7
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +3 -3
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +2 -3
- data/vendor/faiss/faiss/IndexBinaryHash.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +3 -3
- data/vendor/faiss/faiss/IndexBinaryIVF.h +2 -2
- data/vendor/faiss/faiss/IndexFastScan.cpp +32 -18
- data/vendor/faiss/faiss/IndexFastScan.h +11 -2
- data/vendor/faiss/faiss/IndexFlat.cpp +13 -10
- data/vendor/faiss/faiss/IndexFlat.h +2 -2
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +170 -7
- data/vendor/faiss/faiss/IndexFlatCodes.h +25 -5
- data/vendor/faiss/faiss/IndexHNSW.cpp +156 -96
- data/vendor/faiss/faiss/IndexHNSW.h +54 -5
- data/vendor/faiss/faiss/IndexIDMap.cpp +19 -3
- data/vendor/faiss/faiss/IndexIDMap.h +5 -2
- data/vendor/faiss/faiss/IndexIVF.cpp +5 -6
- data/vendor/faiss/faiss/IndexIVF.h +13 -4
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +21 -7
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.h +5 -2
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +3 -14
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +2 -4
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +201 -91
- data/vendor/faiss/faiss/IndexIVFFastScan.h +33 -9
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFFlat.h +2 -2
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +3 -6
- data/vendor/faiss/faiss/IndexIVFPQ.h +2 -2
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +7 -14
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +2 -4
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFPQR.h +2 -2
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +2 -3
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +2 -2
- data/vendor/faiss/faiss/IndexLSH.cpp +2 -3
- data/vendor/faiss/faiss/IndexLSH.h +2 -2
- data/vendor/faiss/faiss/IndexLattice.cpp +3 -21
- data/vendor/faiss/faiss/IndexLattice.h +5 -24
- data/vendor/faiss/faiss/IndexNNDescent.cpp +2 -31
- data/vendor/faiss/faiss/IndexNNDescent.h +3 -3
- data/vendor/faiss/faiss/IndexNSG.cpp +2 -5
- data/vendor/faiss/faiss/IndexNSG.h +3 -3
- data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +56 -0
- data/vendor/faiss/faiss/IndexNeuralNetCodec.h +49 -0
- data/vendor/faiss/faiss/IndexPQ.cpp +26 -26
- data/vendor/faiss/faiss/IndexPQ.h +2 -2
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +2 -5
- data/vendor/faiss/faiss/IndexPQFastScan.h +2 -11
- data/vendor/faiss/faiss/IndexPreTransform.cpp +2 -2
- data/vendor/faiss/faiss/IndexPreTransform.h +3 -3
- data/vendor/faiss/faiss/IndexRefine.cpp +46 -9
- data/vendor/faiss/faiss/IndexRefine.h +9 -2
- data/vendor/faiss/faiss/IndexReplicas.cpp +2 -2
- data/vendor/faiss/faiss/IndexReplicas.h +2 -2
- data/vendor/faiss/faiss/IndexRowwiseMinMax.cpp +2 -2
- data/vendor/faiss/faiss/IndexRowwiseMinMax.h +2 -2
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +5 -4
- data/vendor/faiss/faiss/IndexScalarQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexShards.cpp +2 -2
- data/vendor/faiss/faiss/IndexShards.h +2 -2
- data/vendor/faiss/faiss/IndexShardsIVF.cpp +2 -2
- data/vendor/faiss/faiss/IndexShardsIVF.h +2 -2
- data/vendor/faiss/faiss/MatrixStats.cpp +2 -2
- data/vendor/faiss/faiss/MatrixStats.h +2 -2
- data/vendor/faiss/faiss/MetaIndexes.cpp +2 -3
- data/vendor/faiss/faiss/MetaIndexes.h +2 -2
- data/vendor/faiss/faiss/MetricType.h +9 -4
- data/vendor/faiss/faiss/VectorTransform.cpp +2 -2
- data/vendor/faiss/faiss/VectorTransform.h +2 -2
- data/vendor/faiss/faiss/clone_index.cpp +2 -2
- data/vendor/faiss/faiss/clone_index.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/SaDecodeKernels.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/detail/CoarseBitType.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/detail/UintReader.h +97 -19
- data/vendor/faiss/faiss/cppcontrib/factory_tools.cpp +192 -0
- data/vendor/faiss/faiss/cppcontrib/factory_tools.h +29 -0
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +85 -32
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-neon-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMax-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMaxFP16-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-neon-inl.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuAutoTune.cpp +2 -5
- data/vendor/faiss/faiss/gpu/GpuAutoTune.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +45 -13
- data/vendor/faiss/faiss/gpu/GpuCloner.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +12 -6
- data/vendor/faiss/faiss/gpu/GpuDistance.h +11 -7
- data/vendor/faiss/faiss/gpu/GpuFaissAssert.h +3 -3
- data/vendor/faiss/faiss/gpu/GpuIcmEncoder.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndex.h +10 -15
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +285 -0
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +8 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +4 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +3 -3
- data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndicesOptions.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuResources.cpp +7 -2
- data/vendor/faiss/faiss/gpu/GpuResources.h +11 -4
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +66 -11
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +15 -5
- data/vendor/faiss/faiss/gpu/impl/IndexUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +28 -23
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.h +2 -2
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +2 -2
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/PerfClustering.cpp +8 -2
- data/vendor/faiss/faiss/gpu/perf/PerfIVFPQAdd.cpp +2 -3
- data/vendor/faiss/faiss/gpu/perf/WriteIndex.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +10 -7
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +54 -54
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +144 -77
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +51 -51
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestGpuMemoryException.cpp +3 -3
- data/vendor/faiss/faiss/gpu/test/TestGpuResidualQuantizer.cpp +70 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +74 -4
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/test/demo_ivfpq_indexing_gpu.cpp +3 -3
- data/vendor/faiss/faiss/gpu/utils/{RaftUtils.h → CuvsUtils.h} +12 -11
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +8 -2
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +2 -2
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.h +2 -2
- data/vendor/faiss/faiss/gpu/utils/StaticUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/utils/Timer.cpp +6 -3
- data/vendor/faiss/faiss/gpu/utils/Timer.h +3 -3
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +79 -11
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +17 -5
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +27 -2
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +11 -3
- data/vendor/faiss/faiss/impl/CodePacker.cpp +2 -2
- data/vendor/faiss/faiss/impl/CodePacker.h +2 -2
- data/vendor/faiss/faiss/impl/DistanceComputer.h +48 -2
- data/vendor/faiss/faiss/impl/FaissAssert.h +6 -4
- data/vendor/faiss/faiss/impl/FaissException.cpp +2 -2
- data/vendor/faiss/faiss/impl/FaissException.h +2 -3
- data/vendor/faiss/faiss/impl/HNSW.cpp +378 -205
- data/vendor/faiss/faiss/impl/HNSW.h +55 -24
- data/vendor/faiss/faiss/impl/IDSelector.cpp +2 -2
- data/vendor/faiss/faiss/impl/IDSelector.h +2 -2
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +10 -10
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +2 -2
- data/vendor/faiss/faiss/impl/LookupTableScaler.h +36 -2
- data/vendor/faiss/faiss/impl/NNDescent.cpp +15 -10
- data/vendor/faiss/faiss/impl/NNDescent.h +2 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +26 -49
- data/vendor/faiss/faiss/impl/NSG.h +20 -8
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +2 -2
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +2 -2
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +2 -4
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.h +2 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +2 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +3 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +7 -3
- data/vendor/faiss/faiss/impl/Quantizer.h +2 -2
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +2 -36
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +3 -13
- data/vendor/faiss/faiss/impl/ResultHandler.h +153 -34
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +721 -104
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +5 -2
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +2 -2
- data/vendor/faiss/faiss/impl/ThreadedIndex.h +2 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-avx2.h +7 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-avx512.h +248 -0
- data/vendor/faiss/faiss/impl/code_distance/code_distance-generic.h +2 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-sve.h +440 -0
- data/vendor/faiss/faiss/impl/code_distance/code_distance.h +55 -2
- data/vendor/faiss/faiss/impl/index_read.cpp +31 -20
- data/vendor/faiss/faiss/impl/index_read_utils.h +37 -0
- data/vendor/faiss/faiss/impl/index_write.cpp +30 -16
- data/vendor/faiss/faiss/impl/io.cpp +15 -7
- data/vendor/faiss/faiss/impl/io.h +6 -6
- data/vendor/faiss/faiss/impl/io_macros.h +8 -9
- data/vendor/faiss/faiss/impl/kmeans1d.cpp +2 -3
- data/vendor/faiss/faiss/impl/kmeans1d.h +2 -2
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +2 -3
- data/vendor/faiss/faiss/impl/lattice_Zn.h +2 -2
- data/vendor/faiss/faiss/impl/platform_macros.h +34 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +13 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +20 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +3 -3
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +450 -3
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +8 -8
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +3 -3
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +151 -67
- data/vendor/faiss/faiss/index_factory.cpp +51 -34
- data/vendor/faiss/faiss/index_factory.h +2 -2
- data/vendor/faiss/faiss/index_io.h +14 -7
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +30 -10
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +5 -2
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +11 -3
- data/vendor/faiss/faiss/invlists/DirectMap.h +2 -2
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +57 -19
- data/vendor/faiss/faiss/invlists/InvertedLists.h +20 -11
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +2 -2
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +2 -2
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +23 -9
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +4 -3
- data/vendor/faiss/faiss/python/python_callbacks.cpp +5 -5
- data/vendor/faiss/faiss/python/python_callbacks.h +2 -2
- data/vendor/faiss/faiss/utils/AlignedTable.h +5 -3
- data/vendor/faiss/faiss/utils/Heap.cpp +2 -2
- data/vendor/faiss/faiss/utils/Heap.h +107 -2
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +346 -0
- data/vendor/faiss/faiss/utils/NeuralNet.h +147 -0
- data/vendor/faiss/faiss/utils/WorkerThread.cpp +2 -2
- data/vendor/faiss/faiss/utils/WorkerThread.h +2 -2
- 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/generic.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/mode.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +2 -2
- data/vendor/faiss/faiss/utils/bf16.h +36 -0
- data/vendor/faiss/faiss/utils/distances.cpp +249 -90
- data/vendor/faiss/faiss/utils/distances.h +8 -8
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/avx512.h +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.h +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.h +2 -2
- data/vendor/faiss/faiss/utils/distances_simd.cpp +1543 -56
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +72 -2
- data/vendor/faiss/faiss/utils/extra_distances.cpp +87 -140
- data/vendor/faiss/faiss/utils/extra_distances.h +5 -4
- data/vendor/faiss/faiss/utils/fp16-arm.h +2 -2
- data/vendor/faiss/faiss/utils/fp16-fp16c.h +2 -2
- data/vendor/faiss/faiss/utils/fp16-inl.h +2 -2
- data/vendor/faiss/faiss/utils/fp16.h +2 -2
- data/vendor/faiss/faiss/utils/hamming-inl.h +2 -2
- data/vendor/faiss/faiss/utils/hamming.cpp +3 -4
- data/vendor/faiss/faiss/utils/hamming.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/avx512-inl.h +490 -0
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +6 -3
- data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +7 -3
- data/vendor/faiss/faiss/utils/hamming_distance/neon-inl.h +5 -5
- data/vendor/faiss/faiss/utils/ordered_key_value.h +2 -2
- data/vendor/faiss/faiss/utils/partitioning.cpp +2 -2
- data/vendor/faiss/faiss/utils/partitioning.h +2 -2
- data/vendor/faiss/faiss/utils/prefetch.h +2 -2
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +2 -2
- data/vendor/faiss/faiss/utils/quantize_lut.h +2 -2
- data/vendor/faiss/faiss/utils/random.cpp +45 -2
- data/vendor/faiss/faiss/utils/random.h +27 -2
- data/vendor/faiss/faiss/utils/simdlib.h +12 -3
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_avx512.h +296 -0
- data/vendor/faiss/faiss/utils/simdlib_emulated.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_neon.h +7 -4
- data/vendor/faiss/faiss/utils/simdlib_ppc64.h +1084 -0
- data/vendor/faiss/faiss/utils/sorting.cpp +2 -2
- data/vendor/faiss/faiss/utils/sorting.h +2 -2
- data/vendor/faiss/faiss/utils/transpose/transpose-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +176 -0
- data/vendor/faiss/faiss/utils/utils.cpp +17 -10
- data/vendor/faiss/faiss/utils/utils.h +7 -3
- metadata +22 -11
- data/vendor/faiss/faiss/impl/code_distance/code_distance_avx512.h +0 -102
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -24,7 +24,6 @@
|
|
24
24
|
#include <faiss/utils/Heap.h>
|
25
25
|
#include <faiss/utils/distances.h>
|
26
26
|
#include <faiss/utils/hamming.h>
|
27
|
-
#include <faiss/utils/utils.h>
|
28
27
|
|
29
28
|
extern "C" {
|
30
29
|
|
@@ -152,6 +151,40 @@ void AdditiveQuantizer::train_norm(size_t n, const float* norms) {
|
|
152
151
|
}
|
153
152
|
}
|
154
153
|
|
154
|
+
void AdditiveQuantizer::compute_codebook_tables() {
|
155
|
+
centroid_norms.resize(total_codebook_size);
|
156
|
+
fvec_norms_L2sqr(
|
157
|
+
centroid_norms.data(), codebooks.data(), d, total_codebook_size);
|
158
|
+
size_t cross_table_size = 0;
|
159
|
+
for (int m = 0; m < M; m++) {
|
160
|
+
size_t K = (size_t)1 << nbits[m];
|
161
|
+
cross_table_size += K * codebook_offsets[m];
|
162
|
+
}
|
163
|
+
codebook_cross_products.resize(cross_table_size);
|
164
|
+
size_t ofs = 0;
|
165
|
+
for (int m = 1; m < M; m++) {
|
166
|
+
FINTEGER ki = (size_t)1 << nbits[m];
|
167
|
+
FINTEGER kk = codebook_offsets[m];
|
168
|
+
FINTEGER di = d;
|
169
|
+
float zero = 0, one = 1;
|
170
|
+
assert(ofs + ki * kk <= cross_table_size);
|
171
|
+
sgemm_("Transposed",
|
172
|
+
"Not transposed",
|
173
|
+
&ki,
|
174
|
+
&kk,
|
175
|
+
&di,
|
176
|
+
&one,
|
177
|
+
codebooks.data() + d * kk,
|
178
|
+
&di,
|
179
|
+
codebooks.data(),
|
180
|
+
&di,
|
181
|
+
&zero,
|
182
|
+
codebook_cross_products.data() + ofs,
|
183
|
+
&ki);
|
184
|
+
ofs += ki * kk;
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
155
188
|
namespace {
|
156
189
|
|
157
190
|
// TODO
|
@@ -471,7 +504,6 @@ namespace {
|
|
471
504
|
float accumulate_IPs(
|
472
505
|
const AdditiveQuantizer& aq,
|
473
506
|
BitstringReader& bs,
|
474
|
-
const uint8_t* codes,
|
475
507
|
const float* LUT) {
|
476
508
|
float accu = 0;
|
477
509
|
for (int m = 0; m < aq.M; m++) {
|
@@ -483,6 +515,29 @@ float accumulate_IPs(
|
|
483
515
|
return accu;
|
484
516
|
}
|
485
517
|
|
518
|
+
float compute_norm_from_LUT(const AdditiveQuantizer& aq, BitstringReader& bs) {
|
519
|
+
float accu = 0;
|
520
|
+
std::vector<int> idx(aq.M);
|
521
|
+
const float* c = aq.codebook_cross_products.data();
|
522
|
+
for (int m = 0; m < aq.M; m++) {
|
523
|
+
size_t nbit = aq.nbits[m];
|
524
|
+
int i = bs.read(nbit);
|
525
|
+
size_t K = 1 << nbit;
|
526
|
+
idx[m] = i;
|
527
|
+
|
528
|
+
accu += aq.centroid_norms[aq.codebook_offsets[m] + i];
|
529
|
+
|
530
|
+
for (int l = 0; l < m; l++) {
|
531
|
+
int j = idx[l];
|
532
|
+
accu += 2 * c[j * K + i];
|
533
|
+
c += (1 << aq.nbits[l]) * K;
|
534
|
+
}
|
535
|
+
}
|
536
|
+
// FAISS_THROW_IF_NOT(c == aq.codebook_cross_products.data() +
|
537
|
+
// aq.codebook_cross_products.size());
|
538
|
+
return accu;
|
539
|
+
}
|
540
|
+
|
486
541
|
} // anonymous namespace
|
487
542
|
|
488
543
|
template <>
|
@@ -491,7 +546,7 @@ float AdditiveQuantizer::
|
|
491
546
|
const uint8_t* codes,
|
492
547
|
const float* LUT) const {
|
493
548
|
BitstringReader bs(codes, code_size);
|
494
|
-
return accumulate_IPs(*this, bs,
|
549
|
+
return accumulate_IPs(*this, bs, LUT);
|
495
550
|
}
|
496
551
|
|
497
552
|
template <>
|
@@ -500,7 +555,7 @@ float AdditiveQuantizer::
|
|
500
555
|
const uint8_t* codes,
|
501
556
|
const float* LUT) const {
|
502
557
|
BitstringReader bs(codes, code_size);
|
503
|
-
return -accumulate_IPs(*this, bs,
|
558
|
+
return -accumulate_IPs(*this, bs, LUT);
|
504
559
|
}
|
505
560
|
|
506
561
|
template <>
|
@@ -509,7 +564,7 @@ float AdditiveQuantizer::
|
|
509
564
|
const uint8_t* codes,
|
510
565
|
const float* LUT) const {
|
511
566
|
BitstringReader bs(codes, code_size);
|
512
|
-
float accu = accumulate_IPs(*this, bs,
|
567
|
+
float accu = accumulate_IPs(*this, bs, LUT);
|
513
568
|
uint32_t norm_i = bs.read(32);
|
514
569
|
float norm2;
|
515
570
|
memcpy(&norm2, &norm_i, 4);
|
@@ -522,7 +577,7 @@ float AdditiveQuantizer::
|
|
522
577
|
const uint8_t* codes,
|
523
578
|
const float* LUT) const {
|
524
579
|
BitstringReader bs(codes, code_size);
|
525
|
-
float accu = accumulate_IPs(*this, bs,
|
580
|
+
float accu = accumulate_IPs(*this, bs, LUT);
|
526
581
|
uint32_t norm_i = bs.read(8);
|
527
582
|
float norm2 = decode_qcint(norm_i);
|
528
583
|
return norm2 - 2 * accu;
|
@@ -534,7 +589,7 @@ float AdditiveQuantizer::
|
|
534
589
|
const uint8_t* codes,
|
535
590
|
const float* LUT) const {
|
536
591
|
BitstringReader bs(codes, code_size);
|
537
|
-
float accu = accumulate_IPs(*this, bs,
|
592
|
+
float accu = accumulate_IPs(*this, bs, LUT);
|
538
593
|
uint32_t norm_i = bs.read(4);
|
539
594
|
float norm2 = decode_qcint(norm_i);
|
540
595
|
return norm2 - 2 * accu;
|
@@ -546,7 +601,7 @@ float AdditiveQuantizer::
|
|
546
601
|
const uint8_t* codes,
|
547
602
|
const float* LUT) const {
|
548
603
|
BitstringReader bs(codes, code_size);
|
549
|
-
float accu = accumulate_IPs(*this, bs,
|
604
|
+
float accu = accumulate_IPs(*this, bs, LUT);
|
550
605
|
uint32_t norm_i = bs.read(8);
|
551
606
|
float norm2 = decode_qint8(norm_i, norm_min, norm_max);
|
552
607
|
return norm2 - 2 * accu;
|
@@ -558,10 +613,23 @@ float AdditiveQuantizer::
|
|
558
613
|
const uint8_t* codes,
|
559
614
|
const float* LUT) const {
|
560
615
|
BitstringReader bs(codes, code_size);
|
561
|
-
float accu = accumulate_IPs(*this, bs,
|
616
|
+
float accu = accumulate_IPs(*this, bs, LUT);
|
562
617
|
uint32_t norm_i = bs.read(4);
|
563
618
|
float norm2 = decode_qint4(norm_i, norm_min, norm_max);
|
564
619
|
return norm2 - 2 * accu;
|
565
620
|
}
|
566
621
|
|
622
|
+
template <>
|
623
|
+
float AdditiveQuantizer::
|
624
|
+
compute_1_distance_LUT<false, AdditiveQuantizer::ST_norm_from_LUT>(
|
625
|
+
const uint8_t* codes,
|
626
|
+
const float* LUT) const {
|
627
|
+
FAISS_THROW_IF_NOT(codebook_cross_products.size() > 0);
|
628
|
+
BitstringReader bs(codes, code_size);
|
629
|
+
float accu = accumulate_IPs(*this, bs, LUT);
|
630
|
+
BitstringReader bs2(codes, code_size);
|
631
|
+
float norm2 = compute_norm_from_LUT(*this, bs2);
|
632
|
+
return norm2 - 2 * accu;
|
633
|
+
}
|
634
|
+
|
567
635
|
} // namespace faiss
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -29,6 +29,8 @@ struct AdditiveQuantizer : Quantizer {
|
|
29
29
|
std::vector<float> codebooks; ///< codebooks
|
30
30
|
|
31
31
|
// derived values
|
32
|
+
/// codebook #1 is stored in rows codebook_offsets[i]:codebook_offsets[i+1]
|
33
|
+
/// in the codebooks table of size total_codebook_size by d
|
32
34
|
std::vector<uint64_t> codebook_offsets;
|
33
35
|
size_t tot_bits = 0; ///< total number of bits (indexes + norms)
|
34
36
|
size_t norm_bits = 0; ///< bits allocated for the norms
|
@@ -38,9 +40,19 @@ struct AdditiveQuantizer : Quantizer {
|
|
38
40
|
bool verbose = false; ///< verbose during training?
|
39
41
|
bool is_trained = false; ///< is trained or not
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
/// auxiliary data for ST_norm_lsq2x4 and ST_norm_rq2x4
|
44
|
+
/// store norms of codebook entries for 4-bit fastscan
|
45
|
+
std::vector<float> norm_tabs;
|
46
|
+
IndexFlat1D qnorm; ///< store and search norms
|
47
|
+
|
48
|
+
void compute_codebook_tables();
|
49
|
+
|
50
|
+
/// norms of all codebook entries (size total_codebook_size)
|
51
|
+
std::vector<float> centroid_norms;
|
52
|
+
|
53
|
+
/// dot products of all codebook entries with the previous codebooks
|
54
|
+
/// size sum(codebook_offsets[m] * 2^nbits[m], m=0..M-1)
|
55
|
+
std::vector<float> codebook_cross_products;
|
44
56
|
|
45
57
|
/// norms and distance matrixes with beam search can get large, so use this
|
46
58
|
/// to control for the amount of memory that can be allocated
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -236,4 +236,29 @@ size_t InterruptCallback::get_period_hint(size_t flops) {
|
|
236
236
|
return std::max((size_t)10 * 10 * 1000 * 1000 / (flops + 1), (size_t)1);
|
237
237
|
}
|
238
238
|
|
239
|
+
void TimeoutCallback::set_timeout(double timeout_in_seconds) {
|
240
|
+
timeout = timeout_in_seconds;
|
241
|
+
start = std::chrono::steady_clock::now();
|
242
|
+
}
|
243
|
+
|
244
|
+
bool TimeoutCallback::want_interrupt() {
|
245
|
+
if (timeout == 0) {
|
246
|
+
return false;
|
247
|
+
}
|
248
|
+
auto end = std::chrono::steady_clock::now();
|
249
|
+
std::chrono::duration<float, std::milli> duration = end - start;
|
250
|
+
float elapsed_in_seconds = duration.count() / 1000.0;
|
251
|
+
if (elapsed_in_seconds > timeout) {
|
252
|
+
timeout = 0;
|
253
|
+
return true;
|
254
|
+
}
|
255
|
+
return false;
|
256
|
+
}
|
257
|
+
|
258
|
+
void TimeoutCallback::reset(double timeout_in_seconds) {
|
259
|
+
auto tc(new faiss::TimeoutCallback());
|
260
|
+
faiss::InterruptCallback::instance.reset(tc);
|
261
|
+
tc->set_timeout(timeout_in_seconds);
|
262
|
+
}
|
263
|
+
|
239
264
|
} // namespace faiss
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -122,7 +122,7 @@ struct RangeSearchPartialResult : BufferList {
|
|
122
122
|
void copy_result(bool incremental = false);
|
123
123
|
|
124
124
|
/// merge a set of PartialResult's into one RangeSearchResult
|
125
|
-
/// on
|
125
|
+
/// on output the partialresults are empty!
|
126
126
|
static void merge(
|
127
127
|
std::vector<RangeSearchPartialResult*>& partial_results,
|
128
128
|
bool do_delete = true);
|
@@ -161,6 +161,14 @@ struct FAISS_API InterruptCallback {
|
|
161
161
|
static size_t get_period_hint(size_t flops);
|
162
162
|
};
|
163
163
|
|
164
|
+
struct TimeoutCallback : InterruptCallback {
|
165
|
+
std::chrono::time_point<std::chrono::steady_clock> start;
|
166
|
+
double timeout;
|
167
|
+
bool want_interrupt() override;
|
168
|
+
void set_timeout(double timeout_in_seconds);
|
169
|
+
static void reset(double timeout_in_seconds);
|
170
|
+
};
|
171
|
+
|
164
172
|
/// set implementation optimized for fast access.
|
165
173
|
struct VisitedTable {
|
166
174
|
std::vector<uint8_t> visited;
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -59,6 +59,52 @@ struct DistanceComputer {
|
|
59
59
|
virtual ~DistanceComputer() {}
|
60
60
|
};
|
61
61
|
|
62
|
+
/* Wrap the distance computer into one that negates the
|
63
|
+
distances. This makes supporting INNER_PRODUCE search easier */
|
64
|
+
|
65
|
+
struct NegativeDistanceComputer : DistanceComputer {
|
66
|
+
/// owned by this
|
67
|
+
DistanceComputer* basedis;
|
68
|
+
|
69
|
+
explicit NegativeDistanceComputer(DistanceComputer* basedis)
|
70
|
+
: basedis(basedis) {}
|
71
|
+
|
72
|
+
void set_query(const float* x) override {
|
73
|
+
basedis->set_query(x);
|
74
|
+
}
|
75
|
+
|
76
|
+
/// compute distance of vector i to current query
|
77
|
+
float operator()(idx_t i) override {
|
78
|
+
return -(*basedis)(i);
|
79
|
+
}
|
80
|
+
|
81
|
+
void distances_batch_4(
|
82
|
+
const idx_t idx0,
|
83
|
+
const idx_t idx1,
|
84
|
+
const idx_t idx2,
|
85
|
+
const idx_t idx3,
|
86
|
+
float& dis0,
|
87
|
+
float& dis1,
|
88
|
+
float& dis2,
|
89
|
+
float& dis3) override {
|
90
|
+
basedis->distances_batch_4(
|
91
|
+
idx0, idx1, idx2, idx3, dis0, dis1, dis2, dis3);
|
92
|
+
dis0 = -dis0;
|
93
|
+
dis1 = -dis1;
|
94
|
+
dis2 = -dis2;
|
95
|
+
dis3 = -dis3;
|
96
|
+
}
|
97
|
+
|
98
|
+
/// compute distance between two stored vectors
|
99
|
+
float symmetric_dis(idx_t i, idx_t j) override {
|
100
|
+
return -basedis->symmetric_dis(i, j);
|
101
|
+
}
|
102
|
+
|
103
|
+
virtual ~NegativeDistanceComputer() {
|
104
|
+
delete basedis;
|
105
|
+
}
|
106
|
+
};
|
107
|
+
|
62
108
|
/*************************************************************
|
63
109
|
* Specialized version of the DistanceComputer when we know that codes are
|
64
110
|
* laid out in a flat index.
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -94,13 +94,15 @@
|
|
94
94
|
} \
|
95
95
|
} while (false)
|
96
96
|
|
97
|
-
#define
|
97
|
+
#define FAISS_THROW_IF_MSG(X, MSG) \
|
98
98
|
do { \
|
99
|
-
if (
|
99
|
+
if (X) { \
|
100
100
|
FAISS_THROW_FMT("Error: '%s' failed: " MSG, #X); \
|
101
101
|
} \
|
102
102
|
} while (false)
|
103
103
|
|
104
|
+
#define FAISS_THROW_IF_NOT_MSG(X, MSG) FAISS_THROW_IF_MSG(!(X), MSG)
|
105
|
+
|
104
106
|
#define FAISS_THROW_IF_NOT_FMT(X, FMT, ...) \
|
105
107
|
do { \
|
106
108
|
if (!(X)) { \
|