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.
|
@@ -112,7 +112,7 @@ struct ResidualQuantizer : AdditiveQuantizer {
|
|
112
112
|
|
113
113
|
/** lower-level encode function
|
114
114
|
*
|
115
|
-
* @param n number of vectors to
|
115
|
+
* @param n number of vectors to handle
|
116
116
|
* @param residuals vectors to encode, size (n, beam_size, d)
|
117
117
|
* @param beam_size input beam size
|
118
118
|
* @param new_beam_size output beam size (should be <= K * beam_size)
|
@@ -143,16 +143,6 @@ struct ResidualQuantizer : AdditiveQuantizer {
|
|
143
143
|
* @param beam_size if != -1, override the beam size
|
144
144
|
*/
|
145
145
|
size_t memory_per_point(int beam_size = -1) const;
|
146
|
-
|
147
|
-
/** Cross products used in codebook tables used for beam_LUT = 1
|
148
|
-
*/
|
149
|
-
void compute_codebook_tables();
|
150
|
-
|
151
|
-
/// dot products of all codebook entries with the previous codebooks
|
152
|
-
/// size sum(codebook_offsets[m] * 2^nbits[m], m=0..M-1)
|
153
|
-
std::vector<float> codebook_cross_products;
|
154
|
-
/// norms of all codebook entries (size total_codebook_size)
|
155
|
-
std::vector<float> cent_norms;
|
156
146
|
};
|
157
147
|
|
158
148
|
} // 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.
|
@@ -12,9 +12,14 @@
|
|
12
12
|
#pragma once
|
13
13
|
|
14
14
|
#include <faiss/impl/AuxIndexStructures.h>
|
15
|
+
#include <faiss/impl/FaissException.h>
|
16
|
+
#include <faiss/impl/IDSelector.h>
|
15
17
|
#include <faiss/utils/Heap.h>
|
16
18
|
#include <faiss/utils/partitioning.h>
|
17
19
|
|
20
|
+
#include <algorithm>
|
21
|
+
#include <iostream>
|
22
|
+
|
18
23
|
namespace faiss {
|
19
24
|
|
20
25
|
/*****************************************************************
|
@@ -24,16 +29,21 @@ namespace faiss {
|
|
24
29
|
* - by instanciating a SingleResultHandler that tracks results for a single
|
25
30
|
* query
|
26
31
|
* - with begin_multiple/add_results/end_multiple calls where a whole block of
|
27
|
-
*
|
32
|
+
* results is submitted
|
28
33
|
* All classes are templated on C which to define wheter the min or the max of
|
29
|
-
* results is to be kept
|
34
|
+
* results is to be kept, and on sel, so that the codepaths for with / without
|
35
|
+
* selector can be separated at compile time.
|
30
36
|
*****************************************************************/
|
31
37
|
|
32
|
-
template <class C>
|
38
|
+
template <class C, bool use_sel = false>
|
33
39
|
struct BlockResultHandler {
|
34
40
|
size_t nq; // number of queries for which we search
|
41
|
+
const IDSelector* sel;
|
35
42
|
|
36
|
-
explicit BlockResultHandler(size_t nq
|
43
|
+
explicit BlockResultHandler(size_t nq, const IDSelector* sel = nullptr)
|
44
|
+
: nq(nq), sel(sel) {
|
45
|
+
assert(!use_sel || sel);
|
46
|
+
}
|
37
47
|
|
38
48
|
// currently handled query range
|
39
49
|
size_t i0 = 0, i1 = 0;
|
@@ -51,13 +61,17 @@ struct BlockResultHandler {
|
|
51
61
|
virtual void end_multiple() {}
|
52
62
|
|
53
63
|
virtual ~BlockResultHandler() {}
|
64
|
+
|
65
|
+
bool is_in_selection(idx_t i) const {
|
66
|
+
return !use_sel || sel->is_member(i);
|
67
|
+
}
|
54
68
|
};
|
55
69
|
|
56
70
|
// handler for a single query
|
57
71
|
template <class C>
|
58
72
|
struct ResultHandler {
|
59
73
|
// if not better than threshold, then not necessary to call add_result
|
60
|
-
typename C::T threshold =
|
74
|
+
typename C::T threshold = C::neutral();
|
61
75
|
|
62
76
|
// return whether threshold was updated
|
63
77
|
virtual bool add_result(typename C::T dis, typename C::TI idx) = 0;
|
@@ -71,20 +85,26 @@ struct ResultHandler {
|
|
71
85
|
* some temporary data in memory.
|
72
86
|
*****************************************************************/
|
73
87
|
|
74
|
-
template <class C>
|
75
|
-
struct Top1BlockResultHandler : BlockResultHandler<C> {
|
88
|
+
template <class C, bool use_sel = false>
|
89
|
+
struct Top1BlockResultHandler : BlockResultHandler<C, use_sel> {
|
76
90
|
using T = typename C::T;
|
77
91
|
using TI = typename C::TI;
|
78
|
-
using BlockResultHandler<C>::i0;
|
79
|
-
using BlockResultHandler<C>::i1;
|
92
|
+
using BlockResultHandler<C, use_sel>::i0;
|
93
|
+
using BlockResultHandler<C, use_sel>::i1;
|
80
94
|
|
81
95
|
// contains exactly nq elements
|
82
96
|
T* dis_tab;
|
83
97
|
// contains exactly nq elements
|
84
98
|
TI* ids_tab;
|
85
99
|
|
86
|
-
Top1BlockResultHandler(
|
87
|
-
|
100
|
+
Top1BlockResultHandler(
|
101
|
+
size_t nq,
|
102
|
+
T* dis_tab,
|
103
|
+
TI* ids_tab,
|
104
|
+
const IDSelector* sel = nullptr)
|
105
|
+
: BlockResultHandler<C, use_sel>(nq, sel),
|
106
|
+
dis_tab(dis_tab),
|
107
|
+
ids_tab(ids_tab) {}
|
88
108
|
|
89
109
|
struct SingleResultHandler : ResultHandler<C> {
|
90
110
|
Top1BlockResultHandler& hr;
|
@@ -163,12 +183,12 @@ struct Top1BlockResultHandler : BlockResultHandler<C> {
|
|
163
183
|
* Heap based result handler
|
164
184
|
*****************************************************************/
|
165
185
|
|
166
|
-
template <class C>
|
167
|
-
struct HeapBlockResultHandler : BlockResultHandler<C> {
|
186
|
+
template <class C, bool use_sel = false>
|
187
|
+
struct HeapBlockResultHandler : BlockResultHandler<C, use_sel> {
|
168
188
|
using T = typename C::T;
|
169
189
|
using TI = typename C::TI;
|
170
|
-
using BlockResultHandler<C>::i0;
|
171
|
-
using BlockResultHandler<C>::i1;
|
190
|
+
using BlockResultHandler<C, use_sel>::i0;
|
191
|
+
using BlockResultHandler<C, use_sel>::i1;
|
172
192
|
|
173
193
|
T* heap_dis_tab;
|
174
194
|
TI* heap_ids_tab;
|
@@ -179,8 +199,9 @@ struct HeapBlockResultHandler : BlockResultHandler<C> {
|
|
179
199
|
size_t nq,
|
180
200
|
T* heap_dis_tab,
|
181
201
|
TI* heap_ids_tab,
|
182
|
-
size_t k
|
183
|
-
|
202
|
+
size_t k,
|
203
|
+
const IDSelector* sel = nullptr)
|
204
|
+
: BlockResultHandler<C, use_sel>(nq, sel),
|
184
205
|
heap_dis_tab(heap_dis_tab),
|
185
206
|
heap_ids_tab(heap_ids_tab),
|
186
207
|
k(k) {}
|
@@ -345,12 +366,12 @@ struct ReservoirTopN : ResultHandler<C> {
|
|
345
366
|
}
|
346
367
|
};
|
347
368
|
|
348
|
-
template <class C>
|
349
|
-
struct ReservoirBlockResultHandler : BlockResultHandler<C> {
|
369
|
+
template <class C, bool use_sel = false>
|
370
|
+
struct ReservoirBlockResultHandler : BlockResultHandler<C, use_sel> {
|
350
371
|
using T = typename C::T;
|
351
372
|
using TI = typename C::TI;
|
352
|
-
using BlockResultHandler<C>::i0;
|
353
|
-
using BlockResultHandler<C>::i1;
|
373
|
+
using BlockResultHandler<C, use_sel>::i0;
|
374
|
+
using BlockResultHandler<C, use_sel>::i1;
|
354
375
|
|
355
376
|
T* heap_dis_tab;
|
356
377
|
TI* heap_ids_tab;
|
@@ -362,8 +383,9 @@ struct ReservoirBlockResultHandler : BlockResultHandler<C> {
|
|
362
383
|
size_t nq,
|
363
384
|
T* heap_dis_tab,
|
364
385
|
TI* heap_ids_tab,
|
365
|
-
size_t k
|
366
|
-
|
386
|
+
size_t k,
|
387
|
+
const IDSelector* sel = nullptr)
|
388
|
+
: BlockResultHandler<C, use_sel>(nq, sel),
|
367
389
|
heap_dis_tab(heap_dis_tab),
|
368
390
|
heap_ids_tab(heap_ids_tab),
|
369
391
|
k(k) {
|
@@ -458,18 +480,23 @@ struct ReservoirBlockResultHandler : BlockResultHandler<C> {
|
|
458
480
|
* Result handler for range searches
|
459
481
|
*****************************************************************/
|
460
482
|
|
461
|
-
template <class C>
|
462
|
-
struct RangeSearchBlockResultHandler : BlockResultHandler<C> {
|
483
|
+
template <class C, bool use_sel = false>
|
484
|
+
struct RangeSearchBlockResultHandler : BlockResultHandler<C, use_sel> {
|
463
485
|
using T = typename C::T;
|
464
486
|
using TI = typename C::TI;
|
465
|
-
using BlockResultHandler<C>::i0;
|
466
|
-
using BlockResultHandler<C>::i1;
|
487
|
+
using BlockResultHandler<C, use_sel>::i0;
|
488
|
+
using BlockResultHandler<C, use_sel>::i1;
|
467
489
|
|
468
490
|
RangeSearchResult* res;
|
469
491
|
T radius;
|
470
492
|
|
471
|
-
RangeSearchBlockResultHandler(
|
472
|
-
|
493
|
+
RangeSearchBlockResultHandler(
|
494
|
+
RangeSearchResult* res,
|
495
|
+
float radius,
|
496
|
+
const IDSelector* sel = nullptr)
|
497
|
+
: BlockResultHandler<C, use_sel>(res->nq, sel),
|
498
|
+
res(res),
|
499
|
+
radius(radius) {}
|
473
500
|
|
474
501
|
/******************************************************
|
475
502
|
* API for 1 result at a time (each SingleResultHandler is
|
@@ -504,7 +531,15 @@ struct RangeSearchBlockResultHandler : BlockResultHandler<C> {
|
|
504
531
|
void end() {}
|
505
532
|
|
506
533
|
~SingleResultHandler() {
|
507
|
-
|
534
|
+
try {
|
535
|
+
// finalize the partial result
|
536
|
+
pres.finalize();
|
537
|
+
} catch (const faiss::FaissException& e) {
|
538
|
+
// Do nothing if allocation fails in finalizing partial results.
|
539
|
+
#ifndef NDEBUG
|
540
|
+
std::cerr << e.what() << std::endl;
|
541
|
+
#endif
|
542
|
+
}
|
508
543
|
}
|
509
544
|
};
|
510
545
|
|
@@ -559,10 +594,94 @@ struct RangeSearchBlockResultHandler : BlockResultHandler<C> {
|
|
559
594
|
}
|
560
595
|
|
561
596
|
~RangeSearchBlockResultHandler() {
|
562
|
-
|
563
|
-
|
597
|
+
try {
|
598
|
+
if (partial_results.size() > 0) {
|
599
|
+
RangeSearchPartialResult::merge(partial_results);
|
600
|
+
}
|
601
|
+
} catch (const faiss::FaissException& e) {
|
602
|
+
// Do nothing if allocation fails in merge.
|
603
|
+
#ifndef NDEBUG
|
604
|
+
std::cerr << e.what() << std::endl;
|
605
|
+
#endif
|
564
606
|
}
|
565
607
|
}
|
566
608
|
};
|
567
609
|
|
610
|
+
/*****************************************************************
|
611
|
+
* Dispatcher function to choose the right knn result handler depending on k
|
612
|
+
*****************************************************************/
|
613
|
+
|
614
|
+
// declared in distances.cpp
|
615
|
+
FAISS_API extern int distance_compute_min_k_reservoir;
|
616
|
+
|
617
|
+
template <class Consumer, class... Types>
|
618
|
+
typename Consumer::T dispatch_knn_ResultHandler(
|
619
|
+
size_t nx,
|
620
|
+
float* vals,
|
621
|
+
int64_t* ids,
|
622
|
+
size_t k,
|
623
|
+
MetricType metric,
|
624
|
+
const IDSelector* sel,
|
625
|
+
Consumer& consumer,
|
626
|
+
Types... args) {
|
627
|
+
#define DISPATCH_C_SEL(C, use_sel) \
|
628
|
+
if (k == 1) { \
|
629
|
+
Top1BlockResultHandler<C, use_sel> res(nx, vals, ids, sel); \
|
630
|
+
return consumer.template f<>(res, args...); \
|
631
|
+
} else if (k < distance_compute_min_k_reservoir) { \
|
632
|
+
HeapBlockResultHandler<C, use_sel> res(nx, vals, ids, k, sel); \
|
633
|
+
return consumer.template f<>(res, args...); \
|
634
|
+
} else { \
|
635
|
+
ReservoirBlockResultHandler<C, use_sel> res(nx, vals, ids, k, sel); \
|
636
|
+
return consumer.template f<>(res, args...); \
|
637
|
+
}
|
638
|
+
|
639
|
+
if (is_similarity_metric(metric)) {
|
640
|
+
using C = CMin<float, int64_t>;
|
641
|
+
if (sel) {
|
642
|
+
DISPATCH_C_SEL(C, true);
|
643
|
+
} else {
|
644
|
+
DISPATCH_C_SEL(C, false);
|
645
|
+
}
|
646
|
+
} else {
|
647
|
+
using C = CMax<float, int64_t>;
|
648
|
+
if (sel) {
|
649
|
+
DISPATCH_C_SEL(C, true);
|
650
|
+
} else {
|
651
|
+
DISPATCH_C_SEL(C, false);
|
652
|
+
}
|
653
|
+
}
|
654
|
+
#undef DISPATCH_C_SEL
|
655
|
+
}
|
656
|
+
|
657
|
+
template <class Consumer, class... Types>
|
658
|
+
typename Consumer::T dispatch_range_ResultHandler(
|
659
|
+
RangeSearchResult* res,
|
660
|
+
float radius,
|
661
|
+
MetricType metric,
|
662
|
+
const IDSelector* sel,
|
663
|
+
Consumer& consumer,
|
664
|
+
Types... args) {
|
665
|
+
#define DISPATCH_C_SEL(C, use_sel) \
|
666
|
+
RangeSearchBlockResultHandler<C, use_sel> resb(res, radius, sel); \
|
667
|
+
return consumer.template f<>(resb, args...);
|
668
|
+
|
669
|
+
if (is_similarity_metric(metric)) {
|
670
|
+
using C = CMin<float, int64_t>;
|
671
|
+
if (sel) {
|
672
|
+
DISPATCH_C_SEL(C, true);
|
673
|
+
} else {
|
674
|
+
DISPATCH_C_SEL(C, false);
|
675
|
+
}
|
676
|
+
} else {
|
677
|
+
using C = CMax<float, int64_t>;
|
678
|
+
if (sel) {
|
679
|
+
DISPATCH_C_SEL(C, true);
|
680
|
+
} else {
|
681
|
+
DISPATCH_C_SEL(C, false);
|
682
|
+
}
|
683
|
+
}
|
684
|
+
#undef DISPATCH_C_SEL
|
685
|
+
}
|
686
|
+
|
568
687
|
} // namespace faiss
|