faiss 0.6.0 → 0.6.1
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 +4 -0
- data/ext/faiss/extconf.rb +2 -1
- data/ext/faiss/{index_rb.cpp → index.cpp} +1 -1
- data/ext/faiss/index_binary.cpp +1 -1
- data/ext/faiss/kmeans.cpp +1 -1
- data/ext/faiss/pca_matrix.cpp +1 -1
- data/ext/faiss/product_quantizer.cpp +1 -1
- data/ext/faiss/{utils_rb.cpp → utils.cpp} +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +93 -80
- data/vendor/faiss/faiss/Clustering.cpp +39 -240
- data/vendor/faiss/faiss/Clustering.h +6 -0
- data/vendor/faiss/faiss/IVFlib.cpp +41 -21
- data/vendor/faiss/faiss/Index.cpp +6 -5
- data/vendor/faiss/faiss/Index.h +5 -5
- data/vendor/faiss/faiss/Index2Layer.cpp +37 -53
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +49 -37
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +36 -34
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +4 -1
- data/vendor/faiss/faiss/IndexBinary.cpp +5 -3
- data/vendor/faiss/faiss/IndexBinary.h +4 -4
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +1 -1
- data/vendor/faiss/faiss/IndexBinaryFlat.h +1 -1
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +4 -4
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +84 -92
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +9 -3
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +45 -236
- data/vendor/faiss/faiss/IndexBinaryHash.h +6 -6
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +87 -415
- data/vendor/faiss/faiss/IndexFastScan.cpp +72 -109
- data/vendor/faiss/faiss/IndexFastScan.h +25 -23
- data/vendor/faiss/faiss/IndexFlat.cpp +27 -20
- data/vendor/faiss/faiss/IndexFlat.h +21 -18
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +42 -19
- data/vendor/faiss/faiss/IndexHNSW.cpp +283 -145
- data/vendor/faiss/faiss/IndexHNSW.h +16 -2
- data/vendor/faiss/faiss/IndexIDMap.cpp +25 -21
- data/vendor/faiss/faiss/IndexIDMap.h +9 -7
- data/vendor/faiss/faiss/IndexIVF.cpp +465 -362
- data/vendor/faiss/faiss/IndexIVF.h +33 -12
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +77 -74
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +96 -93
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +4 -1
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +357 -238
- data/vendor/faiss/faiss/IndexIVFFastScan.h +42 -41
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +36 -68
- data/vendor/faiss/faiss/IndexIVFFlat.h +32 -0
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.cpp +53 -30
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.h +3 -1
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.cpp +18 -15
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +71 -843
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +151 -121
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +3 -0
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +21 -17
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +26 -39
- data/vendor/faiss/faiss/IndexIVFRaBitQ.h +2 -1
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +475 -476
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +248 -93
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +41 -127
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +1 -1
- data/vendor/faiss/faiss/IndexLSH.cpp +36 -19
- data/vendor/faiss/faiss/IndexLattice.cpp +13 -13
- data/vendor/faiss/faiss/IndexNNDescent.cpp +36 -21
- data/vendor/faiss/faiss/IndexNNDescent.h +2 -2
- data/vendor/faiss/faiss/IndexNSG.cpp +39 -23
- data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +31 -11
- data/vendor/faiss/faiss/IndexPQ.cpp +128 -221
- data/vendor/faiss/faiss/IndexPQ.h +3 -2
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +20 -14
- data/vendor/faiss/faiss/IndexPQFastScan.h +3 -0
- data/vendor/faiss/faiss/IndexPreTransform.cpp +25 -18
- data/vendor/faiss/faiss/IndexPreTransform.h +1 -1
- data/vendor/faiss/faiss/IndexRaBitQ.cpp +11 -36
- data/vendor/faiss/faiss/IndexRaBitQ.h +2 -1
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +41 -277
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +183 -27
- data/vendor/faiss/faiss/IndexRefine.cpp +30 -25
- data/vendor/faiss/faiss/IndexRefine.h +4 -4
- data/vendor/faiss/faiss/IndexReplicas.cpp +6 -6
- data/vendor/faiss/faiss/IndexRowwiseMinMax.cpp +15 -14
- data/vendor/faiss/faiss/IndexRowwiseMinMax.h +1 -1
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +82 -14
- data/vendor/faiss/faiss/IndexShards.cpp +10 -9
- data/vendor/faiss/faiss/IndexShardsIVF.cpp +21 -15
- data/vendor/faiss/faiss/MatrixStats.cpp +5 -4
- data/vendor/faiss/faiss/MetaIndexes.cpp +19 -17
- data/vendor/faiss/faiss/MetaIndexes.h +1 -1
- data/vendor/faiss/faiss/MetricType.h +14 -7
- data/vendor/faiss/faiss/SuperKMeans.cpp +656 -0
- data/vendor/faiss/faiss/SuperKMeans.h +97 -0
- data/vendor/faiss/faiss/VectorTransform.cpp +237 -149
- data/vendor/faiss/faiss/VectorTransform.h +16 -16
- data/vendor/faiss/faiss/build.cpp +23 -0
- data/vendor/faiss/faiss/build.h +15 -0
- data/vendor/faiss/faiss/clone_index.cpp +48 -47
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +47 -47
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +11 -0
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-avx2-inl.h +38 -38
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-inl.h +11 -0
- data/vendor/faiss/faiss/factory_tools.cpp +5 -0
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +6 -5
- data/vendor/faiss/faiss/gpu/GpuResources.h +1 -1
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +9 -9
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +4 -3
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +46 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +56 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +78 -1
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +72 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +23 -0
- data/vendor/faiss/faiss/gpu/utils/CuvsFilterConvert.h +1 -1
- data/vendor/faiss/faiss/gpu/utils/CuvsUtils.h +21 -10
- data/vendor/faiss/faiss/gpu_metal/GpuIndexFlat.h +22 -0
- data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +35 -0
- data/vendor/faiss/faiss/gpu_metal/MetalFlatKernels.h +40 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +51 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndexFlat.h +65 -0
- data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +66 -0
- data/vendor/faiss/faiss/gpu_metal/MetalResources.h +79 -0
- data/vendor/faiss/faiss/gpu_metal/StandardMetalResources.h +35 -0
- data/vendor/faiss/faiss/impl/AdSampling.cpp +103 -0
- data/vendor/faiss/faiss/impl/AdSampling.h +35 -0
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +29 -25
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +1 -0
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +10 -9
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +3 -0
- data/vendor/faiss/faiss/impl/ClusteringHelpers.cpp +244 -0
- data/vendor/faiss/faiss/impl/ClusteringHelpers.h +94 -0
- data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +16 -16
- data/vendor/faiss/faiss/impl/CodePacker.cpp +3 -3
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +1 -1
- data/vendor/faiss/faiss/impl/DistanceComputer.h +8 -8
- data/vendor/faiss/faiss/impl/FaissAssert.h +6 -3
- data/vendor/faiss/faiss/impl/FaissException.h +50 -3
- data/vendor/faiss/faiss/impl/HNSW.cpp +92 -317
- data/vendor/faiss/faiss/impl/HNSW.h +13 -34
- data/vendor/faiss/faiss/impl/IDSelector.cpp +15 -11
- data/vendor/faiss/faiss/impl/IDSelector.h +8 -8
- data/vendor/faiss/faiss/impl/InvertedListScannerStats.h +26 -0
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +82 -77
- data/vendor/faiss/faiss/impl/NNDescent.cpp +62 -25
- data/vendor/faiss/faiss/impl/NNDescent.h +6 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +38 -21
- data/vendor/faiss/faiss/impl/NSG.h +4 -4
- data/vendor/faiss/faiss/impl/Panorama.cpp +23 -6
- data/vendor/faiss/faiss/impl/Panorama.h +258 -87
- data/vendor/faiss/faiss/impl/PdxLayout.cpp +93 -0
- data/vendor/faiss/faiss/impl/PdxLayout.h +41 -0
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +46 -32
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +3 -3
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +35 -35
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +21 -16
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +30 -23
- data/vendor/faiss/faiss/impl/Quantizer.h +2 -2
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +55 -49
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +65 -0
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +296 -283
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +26 -23
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ResultHandler.h +99 -75
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +52 -4
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +27 -1
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +14 -11
- data/vendor/faiss/faiss/impl/VisitedTable.h +7 -0
- data/vendor/faiss/faiss/impl/approx_topk/approx_topk.h +276 -0
- data/vendor/faiss/faiss/impl/approx_topk/avx2.cpp +68 -0
- data/vendor/faiss/faiss/{utils → impl}/approx_topk/generic.h +15 -8
- data/vendor/faiss/faiss/impl/approx_topk/neon.cpp +68 -0
- data/vendor/faiss/faiss/impl/approx_topk/rq_beam_search_tab-inl.h +169 -0
- data/vendor/faiss/faiss/impl/approx_topk/rq_beam_search_tab.h +117 -0
- data/vendor/faiss/faiss/impl/approx_topk/simdlib256-inl.h +146 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHNSW_impl.h +73 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHash_impl.h +270 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryIVF_impl.h +460 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexIVFSpectralHash_impl.h +159 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexPQ_impl.h +92 -0
- data/vendor/faiss/faiss/impl/binary_hamming/avx2.cpp +26 -0
- data/vendor/faiss/faiss/impl/binary_hamming/avx512.cpp +26 -0
- data/vendor/faiss/faiss/impl/binary_hamming/dispatch.h +143 -0
- data/vendor/faiss/faiss/impl/binary_hamming/neon.cpp +26 -0
- data/vendor/faiss/faiss/impl/binary_hamming/rvv.cpp +26 -0
- data/vendor/faiss/faiss/impl/expanded_scanners.h +8 -3
- data/vendor/faiss/faiss/impl/{FastScanDistancePostProcessing.h → fast_scan/FastScanDistancePostProcessing.h} +13 -6
- data/vendor/faiss/faiss/impl/{LookupTableScaler.h → fast_scan/LookupTableScaler.h} +16 -5
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops.h +237 -0
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops_512.h +185 -0
- data/vendor/faiss/faiss/impl/fast_scan/decompose_qbs.h +229 -0
- data/vendor/faiss/faiss/impl/fast_scan/dispatching.h +268 -0
- data/vendor/faiss/faiss/impl/{pq4_fast_scan.cpp → fast_scan/fast_scan.cpp} +169 -2
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.h +341 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +36 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +40 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +120 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-riscv.cpp +104 -0
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd256.h +213 -0
- data/vendor/faiss/faiss/impl/{pq4_fast_scan_search_qbs.cpp → fast_scan/kernels_simd512.h} +26 -356
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_dispatching.h +90 -0
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_result_handler.h +108 -0
- data/vendor/faiss/faiss/impl/{simd_result_handlers.h → fast_scan/simd_result_handlers.h} +282 -134
- data/vendor/faiss/faiss/impl/hnsw/LockVector.cpp +54 -0
- data/vendor/faiss/faiss/impl/hnsw/LockVector.h +64 -0
- data/vendor/faiss/faiss/impl/hnsw/MinimaxHeap.cpp +91 -0
- data/vendor/faiss/faiss/impl/hnsw/MinimaxHeap.h +64 -0
- data/vendor/faiss/faiss/impl/hnsw/avx2.cpp +104 -0
- data/vendor/faiss/faiss/impl/hnsw/avx512.cpp +111 -0
- data/vendor/faiss/faiss/impl/index_read.cpp +1132 -45
- data/vendor/faiss/faiss/impl/index_read_utils.h +1 -1
- data/vendor/faiss/faiss/impl/index_write.cpp +95 -13
- data/vendor/faiss/faiss/impl/io.cpp +6 -6
- data/vendor/faiss/faiss/impl/io_macros.h +33 -16
- data/vendor/faiss/faiss/impl/kmeans1d.cpp +10 -10
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +37 -23
- data/vendor/faiss/faiss/impl/lattice_Zn.h +6 -6
- data/vendor/faiss/faiss/impl/mapped_io.cpp +6 -6
- data/vendor/faiss/faiss/impl/platform_macros.h +11 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +549 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.cpp +245 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.h +105 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/PQDistanceComputer_impl.h +106 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx2.cpp +21 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx512.cpp +21 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/neon.cpp +21 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/{pq_code_distance-avx2.cpp → pq_code_distance-avx2.h} +9 -13
- data/vendor/faiss/faiss/impl/pq_code_distance/{pq_code_distance-avx512.cpp → pq_code_distance-avx512.h} +9 -57
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.cpp +29 -111
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.h +96 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-inl.h +238 -5
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-sve.cpp +5 -7
- data/vendor/faiss/faiss/impl/pq_code_distance/rvv.cpp +68 -0
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +311 -477
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/codecs.h +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +3 -2
- data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +102 -11
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +27 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/similarities.h +3 -3
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +148 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +167 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +59 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +163 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-rvv.cpp +311 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.cpp +192 -8
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.h +12 -0
- data/vendor/faiss/faiss/impl/simd_dispatch.h +100 -66
- data/vendor/faiss/faiss/impl/simdlib/simdlib.h +57 -0
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_avx2.h +264 -172
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx512.h +414 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_dispatch.h +44 -0
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_emulated.h +231 -166
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_neon.h +270 -218
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_ppc64.h +201 -160
- data/vendor/faiss/faiss/impl/svs_io.cpp +12 -3
- data/vendor/faiss/faiss/impl/svs_io.h +8 -2
- data/vendor/faiss/faiss/index_factory.cpp +86 -18
- data/vendor/faiss/faiss/index_io.h +24 -0
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +66 -16
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +24 -14
- data/vendor/faiss/faiss/invlists/DirectMap.h +4 -3
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +157 -73
- data/vendor/faiss/faiss/invlists/InvertedLists.h +86 -23
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +4 -4
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +13 -13
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +2 -2
- data/vendor/faiss/faiss/svs/IndexSVSIVF.cpp +350 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVF.h +128 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLVQ.cpp +40 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLVQ.h +43 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLeanVec.cpp +225 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLeanVec.h +71 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +25 -1
- data/vendor/faiss/faiss/svs/IndexSVSVamana.h +18 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.cpp +12 -3
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.h +7 -2
- data/vendor/faiss/faiss/utils/Heap.cpp +10 -10
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +47 -36
- data/vendor/faiss/faiss/utils/NeuralNet.h +1 -1
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +10 -4
- data/vendor/faiss/faiss/utils/distances.cpp +390 -560
- data/vendor/faiss/faiss/utils/distances.h +20 -1
- data/vendor/faiss/faiss/utils/distances_dispatch.h +117 -37
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +8 -7
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +33 -14
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.h +12 -1
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +16 -293
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based_neon.cpp +57 -0
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_kernel-inl.h +290 -0
- data/vendor/faiss/faiss/utils/distances_simd.cpp +5 -177
- data/vendor/faiss/faiss/utils/extra_distances.cpp +9 -8
- data/vendor/faiss/faiss/utils/extra_distances.h +32 -6
- data/vendor/faiss/faiss/utils/hamming-inl.h +13 -11
- data/vendor/faiss/faiss/utils/hamming.cpp +66 -517
- data/vendor/faiss/faiss/utils/hamming.h +92 -2
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +287 -10
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx2.cpp +15 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512.cpp +15 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx2.h +142 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512.h +234 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-generic.h +368 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-neon.h +322 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-rvv.h +39 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer.h +146 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_impl.h +481 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_neon.cpp +15 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_rvv.cpp +15 -0
- data/vendor/faiss/faiss/utils/partitioning.cpp +66 -987
- data/vendor/faiss/faiss/utils/partitioning.h +31 -0
- data/vendor/faiss/faiss/utils/popcount.h +29 -0
- data/vendor/faiss/faiss/utils/pq_code_distance.h +2 -2
- data/vendor/faiss/faiss/utils/prefetch.h +2 -2
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +30 -30
- data/vendor/faiss/faiss/utils/quantize_lut.h +1 -1
- data/vendor/faiss/faiss/utils/rabitq_simd.h +57 -536
- data/vendor/faiss/faiss/utils/random.cpp +6 -6
- data/vendor/faiss/faiss/utils/simd_impl/IVFFlatScanner-inl.h +51 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_aarch64.cpp +5 -1
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +213 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +163 -10
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +250 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +7 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv.cpp +189 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_simdlib256.h +195 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_sse-inl.h +2 -1
- data/vendor/faiss/faiss/utils/{distances_fused/simdlib_based.h → simd_impl/exhaustive_L2sqr_blas_cmax.h} +5 -10
- data/vendor/faiss/faiss/utils/simd_impl/hamming_impl.h +481 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_avx2.cpp +14 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_neon.cpp +14 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_simdlib256.h +1085 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp +355 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +477 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_neon.cpp +55 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_rvv.cpp +55 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_dispatch.h +32 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels.h +43 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx2.cpp +57 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx512.cpp +45 -0
- data/vendor/faiss/faiss/utils/simd_levels.cpp +17 -5
- data/vendor/faiss/faiss/utils/simd_levels.h +93 -1
- data/vendor/faiss/faiss/utils/sorting.cpp +48 -36
- data/vendor/faiss/faiss/utils/utils.cpp +5 -5
- data/vendor/faiss/faiss/utils/utils.h +3 -3
- metadata +119 -34
- data/vendor/faiss/faiss/impl/RaBitQStats.cpp +0 -29
- data/vendor/faiss/faiss/impl/RaBitQStats.h +0 -56
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +0 -224
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +0 -230
- data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +0 -84
- data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +0 -196
- data/vendor/faiss/faiss/utils/approx_topk/mode.h +0 -34
- data/vendor/faiss/faiss/utils/distances_fused/avx512.h +0 -36
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +0 -235
- data/vendor/faiss/faiss/utils/hamming_distance/avx2-inl.h +0 -462
- data/vendor/faiss/faiss/utils/hamming_distance/avx512-inl.h +0 -490
- data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +0 -449
- data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +0 -87
- data/vendor/faiss/faiss/utils/hamming_distance/neon-inl.h +0 -524
- data/vendor/faiss/faiss/utils/simdlib.h +0 -42
- data/vendor/faiss/faiss/utils/simdlib_avx512.h +0 -365
- /data/ext/faiss/{utils_rb.h → utils.h} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '08fc3bcca329e78e913982923c3fb3743e07591ffd717f5f3027e0609037b5de'
|
|
4
|
+
data.tar.gz: 2a1a79aeaef1756a974fe7e9c3448794496ef145046da39aae3b6ce04a9bf131
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 86e6528125608c64ab9bec3f289019cc0a4125e6719d8c43ca7e9f8eb09cb57ce42f9e040fd0290969f45f70fb25c789a50de7aceef07c38b0acb5ca5e674c49
|
|
7
|
+
data.tar.gz: 4efe37e9e855ab4da2e620e391ac817e6bfa808ca227ea047b55eaff4e7cfdae4c5af59d35b57963653d208e50334edc048fc168fd6d49f805cdb07d3dbc115e
|
data/CHANGELOG.md
CHANGED
data/ext/faiss/extconf.rb
CHANGED
|
@@ -34,7 +34,8 @@ vendor = File.expand_path("../../vendor/faiss", __dir__)
|
|
|
34
34
|
|
|
35
35
|
$srcs = Dir["{#{ext},#{vendor}/faiss,#{vendor}/faiss/{impl,invlists,utils}/**}/*.{cpp}"]
|
|
36
36
|
$srcs -= ["avx2", "avx512", "aarch64", "arm_sve"].map { |v| "#{vendor}/faiss/utils/simd_impl/distances_#{v}.cpp" }
|
|
37
|
+
$objs = $srcs.map { |v| v.sub(/cpp\z/, "o") }
|
|
37
38
|
abort "Faiss not found" unless find_header("faiss/Index.h", vendor)
|
|
38
|
-
$VPATH
|
|
39
|
+
$VPATH << vendor
|
|
39
40
|
|
|
40
41
|
create_makefile("faiss/ext")
|
data/ext/faiss/index_binary.cpp
CHANGED
data/ext/faiss/kmeans.cpp
CHANGED
data/ext/faiss/pca_matrix.cpp
CHANGED
data/lib/faiss/version.rb
CHANGED
|
@@ -33,35 +33,36 @@
|
|
|
33
33
|
|
|
34
34
|
namespace faiss {
|
|
35
35
|
|
|
36
|
-
AutoTuneCriterion::AutoTuneCriterion(idx_t
|
|
37
|
-
: nq(
|
|
36
|
+
AutoTuneCriterion::AutoTuneCriterion(idx_t nq_in, idx_t nnn_in)
|
|
37
|
+
: nq(nq_in), nnn(nnn_in), gt_nnn(0) {}
|
|
38
38
|
|
|
39
39
|
void AutoTuneCriterion::set_groundtruth(
|
|
40
|
-
int
|
|
40
|
+
int gt_nnn_in,
|
|
41
41
|
const float* gt_D_in,
|
|
42
42
|
const idx_t* gt_I_in) {
|
|
43
|
-
this->gt_nnn =
|
|
43
|
+
this->gt_nnn = gt_nnn_in;
|
|
44
44
|
if (gt_D_in) { // allow null for this, as it is often not used
|
|
45
|
-
gt_D.resize(nq *
|
|
46
|
-
memcpy(gt_D.data(), gt_D_in, sizeof(gt_D[0]) * nq *
|
|
45
|
+
gt_D.resize(nq * gt_nnn_in);
|
|
46
|
+
memcpy(gt_D.data(), gt_D_in, sizeof(gt_D[0]) * nq * gt_nnn_in);
|
|
47
47
|
}
|
|
48
|
-
gt_I.resize(nq *
|
|
49
|
-
memcpy(gt_I.data(), gt_I_in, sizeof(gt_I[0]) * nq *
|
|
48
|
+
gt_I.resize(nq * gt_nnn_in);
|
|
49
|
+
memcpy(gt_I.data(), gt_I_in, sizeof(gt_I[0]) * nq * gt_nnn_in);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
OneRecallAtRCriterion::OneRecallAtRCriterion(idx_t
|
|
53
|
-
: AutoTuneCriterion(
|
|
52
|
+
OneRecallAtRCriterion::OneRecallAtRCriterion(idx_t nq_in, idx_t R_in)
|
|
53
|
+
: AutoTuneCriterion(nq_in, R_in), R(R_in) {}
|
|
54
54
|
|
|
55
55
|
double OneRecallAtRCriterion::evaluate(const float* /*D*/, const idx_t* I)
|
|
56
56
|
const {
|
|
57
57
|
FAISS_THROW_IF_NOT_MSG(
|
|
58
|
-
(gt_I.size() == gt_nnn * nq && gt_nnn >= 1 &&
|
|
58
|
+
(gt_I.size() == static_cast<size_t>(gt_nnn * nq) && gt_nnn >= 1 &&
|
|
59
|
+
nnn >= R),
|
|
59
60
|
"ground truth not initialized");
|
|
60
61
|
idx_t n_ok = 0;
|
|
61
62
|
for (idx_t q = 0; q < nq; q++) {
|
|
62
63
|
idx_t gt_nn = gt_I[q * gt_nnn];
|
|
63
64
|
const idx_t* I_line = I + q * nnn;
|
|
64
|
-
for (
|
|
65
|
+
for (idx_t i = 0; i < R; i++) {
|
|
65
66
|
if (I_line[i] == gt_nn) {
|
|
66
67
|
n_ok++;
|
|
67
68
|
break;
|
|
@@ -71,13 +72,14 @@ double OneRecallAtRCriterion::evaluate(const float* /*D*/, const idx_t* I)
|
|
|
71
72
|
return n_ok / double(nq);
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
IntersectionCriterion::IntersectionCriterion(idx_t
|
|
75
|
-
: AutoTuneCriterion(
|
|
75
|
+
IntersectionCriterion::IntersectionCriterion(idx_t nq_in, idx_t R_in)
|
|
76
|
+
: AutoTuneCriterion(nq_in, R_in), R(R_in) {}
|
|
76
77
|
|
|
77
78
|
double IntersectionCriterion::evaluate(const float* /*D*/, const idx_t* I)
|
|
78
79
|
const {
|
|
79
80
|
FAISS_THROW_IF_NOT_MSG(
|
|
80
|
-
(gt_I.size() == gt_nnn * nq && gt_nnn >= R &&
|
|
81
|
+
(gt_I.size() == static_cast<size_t>(gt_nnn * nq) && gt_nnn >= R &&
|
|
82
|
+
nnn >= R),
|
|
81
83
|
"ground truth not initialized");
|
|
82
84
|
int64_t n_ok = 0;
|
|
83
85
|
#pragma omp parallel for reduction(+ : n_ok)
|
|
@@ -126,14 +128,14 @@ bool OperatingPoints::add(
|
|
|
126
128
|
return false;
|
|
127
129
|
}
|
|
128
130
|
} else {
|
|
129
|
-
|
|
131
|
+
size_t i;
|
|
130
132
|
// stricto sensu this should be a bisection
|
|
131
133
|
for (i = 0; i < a.size(); i++) {
|
|
132
134
|
if (a[i].perf >= perf) {
|
|
133
135
|
break;
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
|
-
|
|
138
|
+
FAISS_THROW_IF_NOT(i < a.size());
|
|
137
139
|
if (t < a[i].t) {
|
|
138
140
|
if (a[i].perf == perf) {
|
|
139
141
|
a[i] = op;
|
|
@@ -145,7 +147,7 @@ bool OperatingPoints::add(
|
|
|
145
147
|
}
|
|
146
148
|
}
|
|
147
149
|
// remove non-optimal points from array
|
|
148
|
-
for (
|
|
150
|
+
for (size_t i = a.size() - 1; i > 0; --i) {
|
|
149
151
|
if (a[i].t < a[i - 1].t) {
|
|
150
152
|
a.erase(a.begin() + (i - 1));
|
|
151
153
|
}
|
|
@@ -157,7 +159,7 @@ int OperatingPoints::merge_with(
|
|
|
157
159
|
const OperatingPoints& other,
|
|
158
160
|
const std::string& prefix) {
|
|
159
161
|
int n_add = 0;
|
|
160
|
-
for (
|
|
162
|
+
for (size_t i = 0; i < other.all_pts.size(); i++) {
|
|
161
163
|
const OperatingPoint& op = other.all_pts[i];
|
|
162
164
|
if (add(op.perf, op.t, prefix + op.key, op.cno)) {
|
|
163
165
|
n_add++;
|
|
@@ -172,7 +174,7 @@ double OperatingPoints::t_for_perf(double perf) const {
|
|
|
172
174
|
if (perf > a.back().perf) {
|
|
173
175
|
return 1e50;
|
|
174
176
|
}
|
|
175
|
-
int i0 = -1, i1 = a.size() - 1;
|
|
177
|
+
int i0 = -1, i1 = static_cast<int>(a.size()) - 1;
|
|
176
178
|
while (i0 + 1 < i1) {
|
|
177
179
|
int imed = (i0 + i1 + 1) / 2;
|
|
178
180
|
if (a[imed].perf < perf) {
|
|
@@ -191,7 +193,7 @@ void OperatingPoints::all_to_gnuplot(const char* fname) const {
|
|
|
191
193
|
perror("");
|
|
192
194
|
abort();
|
|
193
195
|
}
|
|
194
|
-
for (
|
|
196
|
+
for (size_t i = 0; i < all_pts.size(); i++) {
|
|
195
197
|
const OperatingPoint& op = all_pts[i];
|
|
196
198
|
fprintf(f, "%g %g %s\n", op.perf, op.t, op.key.c_str());
|
|
197
199
|
}
|
|
@@ -206,7 +208,7 @@ void OperatingPoints::optimal_to_gnuplot(const char* fname) const {
|
|
|
206
208
|
abort();
|
|
207
209
|
}
|
|
208
210
|
double prev_perf = 0.0;
|
|
209
|
-
for (
|
|
211
|
+
for (size_t i = 0; i < optimal_pts.size(); i++) {
|
|
210
212
|
const OperatingPoint& op = optimal_pts[i];
|
|
211
213
|
fprintf(f, "%g %g\n", prev_perf, op.t);
|
|
212
214
|
fprintf(f, "%g %g %s\n", op.perf, op.t, op.key.c_str());
|
|
@@ -222,11 +224,11 @@ void OperatingPoints::display(bool only_optimal) const {
|
|
|
222
224
|
all_pts.size(),
|
|
223
225
|
optimal_pts.size());
|
|
224
226
|
|
|
225
|
-
for (
|
|
227
|
+
for (size_t i = 0; i < pts.size(); i++) {
|
|
226
228
|
const OperatingPoint& op = pts[i];
|
|
227
229
|
const char* star = "";
|
|
228
230
|
if (!only_optimal) {
|
|
229
|
-
for (
|
|
231
|
+
for (size_t j = 0; j < optimal_pts.size(); j++) {
|
|
230
232
|
if (op.cno == optimal_pts[j].cno) {
|
|
231
233
|
star = "*";
|
|
232
234
|
break;
|
|
@@ -269,7 +271,7 @@ ParameterSpace::ParameterSpace (Index *index):
|
|
|
269
271
|
|
|
270
272
|
size_t ParameterSpace::n_combinations() const {
|
|
271
273
|
size_t n = 1;
|
|
272
|
-
for (
|
|
274
|
+
for (size_t i = 0; i < parameter_ranges.size(); i++) {
|
|
273
275
|
n *= parameter_ranges[i].values.size();
|
|
274
276
|
}
|
|
275
277
|
return n;
|
|
@@ -277,9 +279,10 @@ size_t ParameterSpace::n_combinations() const {
|
|
|
277
279
|
|
|
278
280
|
/// get string representation of the combination
|
|
279
281
|
std::string ParameterSpace::combination_name(size_t cno) const {
|
|
280
|
-
char buf[1000]
|
|
282
|
+
char buf[1000];
|
|
283
|
+
char* wp = buf;
|
|
281
284
|
*wp = 0;
|
|
282
|
-
for (
|
|
285
|
+
for (size_t i = 0; i < parameter_ranges.size(); i++) {
|
|
283
286
|
FAISS_THROW_IF_NOT_MSG(
|
|
284
287
|
buf + 1000 - wp >= 0, "Overflow detected in snprintf");
|
|
285
288
|
const ParameterRange& pr = parameter_ranges[i];
|
|
@@ -297,8 +300,8 @@ std::string ParameterSpace::combination_name(size_t cno) const {
|
|
|
297
300
|
}
|
|
298
301
|
|
|
299
302
|
bool ParameterSpace::combination_ge(size_t c1, size_t c2) const {
|
|
300
|
-
for (
|
|
301
|
-
|
|
303
|
+
for (size_t i = 0; i < parameter_ranges.size(); i++) {
|
|
304
|
+
size_t nval = parameter_ranges[i].values.size();
|
|
302
305
|
size_t j1 = c1 % nval;
|
|
303
306
|
size_t j2 = c2 % nval;
|
|
304
307
|
if (!(j1 >= j2)) {
|
|
@@ -316,7 +319,7 @@ static void init_pq_ParameterRange(
|
|
|
316
319
|
if (pq.code_size % 4 == 0) {
|
|
317
320
|
// Polysemous not supported for code sizes that are not a
|
|
318
321
|
// multiple of 4
|
|
319
|
-
for (
|
|
322
|
+
for (size_t i = 2; i <= pq.code_size * 8 / 2; i += 2) {
|
|
320
323
|
pr.values.push_back(i);
|
|
321
324
|
}
|
|
322
325
|
}
|
|
@@ -336,22 +339,22 @@ ParameterRange& ParameterSpace::add_range(const std::string& name) {
|
|
|
336
339
|
|
|
337
340
|
// Do not use this macro if ix will be unused
|
|
338
341
|
#define DC(classname) \
|
|
339
|
-
const classname*
|
|
342
|
+
const classname* ix_c = dynamic_cast<const classname*>(index)
|
|
340
343
|
|
|
341
344
|
/// initialize with reasonable parameters for this type of index
|
|
342
345
|
void ParameterSpace::initialize(const Index* index) {
|
|
343
346
|
if (DC(IndexPreTransform)) {
|
|
344
|
-
index =
|
|
347
|
+
index = ix_c->index;
|
|
345
348
|
}
|
|
346
349
|
if (DC(IndexRefine)) {
|
|
347
350
|
ParameterRange& pr = add_range("k_factor_rf");
|
|
348
351
|
for (int i = 0; i <= 6; i++) {
|
|
349
352
|
pr.values.push_back(1 << i);
|
|
350
353
|
}
|
|
351
|
-
index =
|
|
354
|
+
index = ix_c->base_index;
|
|
352
355
|
}
|
|
353
356
|
if (DC(IndexPreTransform)) {
|
|
354
|
-
index =
|
|
357
|
+
index = ix_c->index;
|
|
355
358
|
}
|
|
356
359
|
|
|
357
360
|
if (DC(IndexIVFInterface)) {
|
|
@@ -359,14 +362,14 @@ void ParameterSpace::initialize(const Index* index) {
|
|
|
359
362
|
ParameterRange& pr = add_range("nprobe");
|
|
360
363
|
for (int i = 0; i < 13; i++) {
|
|
361
364
|
size_t nprobe = 1 << i;
|
|
362
|
-
if (nprobe >=
|
|
365
|
+
if (nprobe >= ix_c->nlist) {
|
|
363
366
|
break;
|
|
364
367
|
}
|
|
365
368
|
pr.values.push_back(nprobe);
|
|
366
369
|
}
|
|
367
370
|
}
|
|
368
371
|
ParameterSpace ivf_pspace;
|
|
369
|
-
ivf_pspace.initialize(
|
|
372
|
+
ivf_pspace.initialize(ix_c->quantizer);
|
|
370
373
|
|
|
371
374
|
for (const ParameterRange& p : ivf_pspace.parameter_ranges) {
|
|
372
375
|
ParameterRange& pr = add_range("quantizer_" + p.name);
|
|
@@ -375,16 +378,16 @@ void ParameterSpace::initialize(const Index* index) {
|
|
|
375
378
|
}
|
|
376
379
|
if (DC(IndexPQ)) {
|
|
377
380
|
ParameterRange& pr = add_range("ht");
|
|
378
|
-
init_pq_ParameterRange(
|
|
381
|
+
init_pq_ParameterRange(ix_c->pq, pr);
|
|
379
382
|
}
|
|
380
383
|
if (DC(IndexIVFPQ)) {
|
|
381
384
|
ParameterRange& pr = add_range("ht");
|
|
382
|
-
init_pq_ParameterRange(
|
|
385
|
+
init_pq_ParameterRange(ix_c->pq, pr);
|
|
383
386
|
}
|
|
384
387
|
|
|
385
388
|
if (DC(IndexIVF)) {
|
|
386
389
|
const MultiIndexQuantizer* miq =
|
|
387
|
-
dynamic_cast<const MultiIndexQuantizer*>(
|
|
390
|
+
dynamic_cast<const MultiIndexQuantizer*>(ix_c->quantizer);
|
|
388
391
|
if (miq) {
|
|
389
392
|
ParameterRange& pr_max_codes = add_range("max_codes");
|
|
390
393
|
for (int i = 8; i < 20; i++) {
|
|
@@ -415,7 +418,7 @@ static void set_index_parameters_common(
|
|
|
415
418
|
const ParameterSpace* ps,
|
|
416
419
|
size_t cno,
|
|
417
420
|
SetParamFunc set_param) {
|
|
418
|
-
for (
|
|
421
|
+
for (size_t i = 0; i < ps->parameter_ranges.size(); i++) {
|
|
419
422
|
const ParameterRange& pr = ps->parameter_ranges[i];
|
|
420
423
|
size_t j = cno % pr.values.size();
|
|
421
424
|
cno /= pr.values.size();
|
|
@@ -481,7 +484,7 @@ void ParameterSpace::set_index_parameters(
|
|
|
481
484
|
|
|
482
485
|
// non-const version
|
|
483
486
|
// Do not use this macro if ix will be unused
|
|
484
|
-
#define DC(classname) classname*
|
|
487
|
+
#define DC(classname) classname* ix_ = dynamic_cast<classname*>(index)
|
|
485
488
|
|
|
486
489
|
void ParameterSpace::set_index_parameter(
|
|
487
490
|
Index* index,
|
|
@@ -496,11 +499,11 @@ void ParameterSpace::set_index_parameter(
|
|
|
496
499
|
// and fall through to also enable it on sub-indexes
|
|
497
500
|
}
|
|
498
501
|
if (DC(IndexIDMap)) {
|
|
499
|
-
set_index_parameter(
|
|
502
|
+
set_index_parameter(ix_->index, name, val);
|
|
500
503
|
return;
|
|
501
504
|
}
|
|
502
505
|
if (DC(IndexPreTransform)) {
|
|
503
|
-
set_index_parameter(
|
|
506
|
+
set_index_parameter(ix_->index, name, val);
|
|
504
507
|
return;
|
|
505
508
|
}
|
|
506
509
|
if (DC(IndexShardsIVF)) {
|
|
@@ -509,7 +512,7 @@ void ParameterSpace::set_index_parameter(
|
|
|
509
512
|
if (name.find("quantizer_") == 0 && name != "nprobe" &&
|
|
510
513
|
name != "quantizer_nprobe") {
|
|
511
514
|
std::string sub_name = name.substr(strlen("quantizer_"));
|
|
512
|
-
set_index_parameter(
|
|
515
|
+
set_index_parameter(ix_->quantizer, sub_name, val);
|
|
513
516
|
return;
|
|
514
517
|
}
|
|
515
518
|
}
|
|
@@ -518,16 +521,16 @@ void ParameterSpace::set_index_parameter(
|
|
|
518
521
|
auto fn = [this, name, val](int /* no */, Index* subIndex) {
|
|
519
522
|
set_index_parameter(subIndex, name, val);
|
|
520
523
|
};
|
|
521
|
-
|
|
524
|
+
ix_->runOnIndex(fn);
|
|
522
525
|
return;
|
|
523
526
|
}
|
|
524
527
|
if (DC(IndexRefine)) {
|
|
525
528
|
if (name == "k_factor_rf") {
|
|
526
|
-
|
|
529
|
+
ix_->k_factor = int(val);
|
|
527
530
|
return;
|
|
528
531
|
}
|
|
529
532
|
// otherwise it is for the sub-index
|
|
530
|
-
set_index_parameter(
|
|
533
|
+
set_index_parameter(ix_->base_index, name, val);
|
|
531
534
|
return;
|
|
532
535
|
}
|
|
533
536
|
|
|
@@ -537,25 +540,26 @@ void ParameterSpace::set_index_parameter(
|
|
|
537
540
|
|
|
538
541
|
if (name == "nprobe") {
|
|
539
542
|
if (DC(IndexIVF)) {
|
|
540
|
-
|
|
543
|
+
ix_->nprobe = int(val);
|
|
541
544
|
return;
|
|
542
545
|
}
|
|
543
546
|
}
|
|
544
547
|
|
|
545
548
|
if (name == "ht") {
|
|
546
549
|
if (DC(IndexPQ)) {
|
|
547
|
-
if (val >=
|
|
548
|
-
|
|
550
|
+
if (val >= ix_->pq.code_size * 8) {
|
|
551
|
+
ix_->search_type = IndexPQ::ST_PQ;
|
|
549
552
|
} else {
|
|
550
|
-
|
|
551
|
-
|
|
553
|
+
ix_->search_type = IndexPQ::ST_polysemous;
|
|
554
|
+
ix_->polysemous_ht = int(val);
|
|
552
555
|
}
|
|
553
556
|
return;
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
+
}
|
|
558
|
+
if (DC(IndexIVFPQ)) {
|
|
559
|
+
if (val >= ix_->pq.code_size * 8) {
|
|
560
|
+
ix_->polysemous_ht = 0;
|
|
557
561
|
} else {
|
|
558
|
-
|
|
562
|
+
ix_->polysemous_ht = int(val);
|
|
559
563
|
}
|
|
560
564
|
return;
|
|
561
565
|
}
|
|
@@ -563,24 +567,31 @@ void ParameterSpace::set_index_parameter(
|
|
|
563
567
|
|
|
564
568
|
if (name == "k_factor") {
|
|
565
569
|
if (DC(IndexIVFPQR)) {
|
|
566
|
-
|
|
570
|
+
ix_->k_factor = val;
|
|
567
571
|
return;
|
|
568
572
|
}
|
|
569
573
|
}
|
|
570
574
|
if (name == "max_codes") {
|
|
571
575
|
if (DC(IndexIVF)) {
|
|
572
|
-
|
|
576
|
+
ix_->max_codes = std::isfinite(val) ? size_t(val) : 0;
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
if (name == "prune_headroom") {
|
|
582
|
+
if (DC(IndexHNSW)) {
|
|
583
|
+
ix_->hnsw.prune_headroom = val;
|
|
573
584
|
return;
|
|
574
585
|
}
|
|
575
586
|
}
|
|
576
587
|
|
|
577
588
|
if (name == "efConstruction") {
|
|
578
589
|
if (DC(IndexHNSW)) {
|
|
579
|
-
|
|
590
|
+
ix_->hnsw.efConstruction = int(val);
|
|
580
591
|
return;
|
|
581
592
|
}
|
|
582
593
|
if (DC(IndexIVF)) {
|
|
583
|
-
if (IndexHNSW* cq = dynamic_cast<IndexHNSW*>(
|
|
594
|
+
if (IndexHNSW* cq = dynamic_cast<IndexHNSW*>(ix_->quantizer)) {
|
|
584
595
|
cq->hnsw.efConstruction = int(val);
|
|
585
596
|
return;
|
|
586
597
|
}
|
|
@@ -589,11 +600,11 @@ void ParameterSpace::set_index_parameter(
|
|
|
589
600
|
|
|
590
601
|
if (name == "efSearch") {
|
|
591
602
|
if (DC(IndexHNSW)) {
|
|
592
|
-
|
|
603
|
+
ix_->hnsw.efSearch = int(val);
|
|
593
604
|
return;
|
|
594
605
|
}
|
|
595
606
|
if (DC(IndexIVF)) {
|
|
596
|
-
if (IndexHNSW* cq = dynamic_cast<IndexHNSW*>(
|
|
607
|
+
if (IndexHNSW* cq = dynamic_cast<IndexHNSW*>(ix_->quantizer)) {
|
|
597
608
|
cq->hnsw.efSearch = int(val);
|
|
598
609
|
return;
|
|
599
610
|
}
|
|
@@ -603,7 +614,7 @@ void ParameterSpace::set_index_parameter(
|
|
|
603
614
|
if (name.find("quantizer_") == 0) {
|
|
604
615
|
if (DC(IndexIVF)) {
|
|
605
616
|
std::string sub_name = name.substr(strlen("quantizer_"));
|
|
606
|
-
set_index_parameter(
|
|
617
|
+
set_index_parameter(ix_->quantizer, sub_name, val);
|
|
607
618
|
return;
|
|
608
619
|
}
|
|
609
620
|
}
|
|
@@ -628,7 +639,7 @@ void ParameterSpace::set_index_parameter(
|
|
|
628
639
|
}
|
|
629
640
|
|
|
630
641
|
if (DC(IndexBinaryIDMap)) {
|
|
631
|
-
set_index_parameter(
|
|
642
|
+
set_index_parameter(ix_->index, name, val);
|
|
632
643
|
return;
|
|
633
644
|
}
|
|
634
645
|
|
|
@@ -638,26 +649,26 @@ void ParameterSpace::set_index_parameter(
|
|
|
638
649
|
|
|
639
650
|
if (name == "nprobe") {
|
|
640
651
|
if (DC(IndexBinaryIVF)) {
|
|
641
|
-
|
|
652
|
+
ix_->nprobe = int(val);
|
|
642
653
|
return;
|
|
643
654
|
}
|
|
644
655
|
}
|
|
645
656
|
|
|
646
657
|
if (name == "max_codes") {
|
|
647
658
|
if (DC(IndexBinaryIVF)) {
|
|
648
|
-
|
|
659
|
+
ix_->max_codes = std::isfinite(val) ? size_t(val) : 0;
|
|
649
660
|
return;
|
|
650
661
|
}
|
|
651
662
|
}
|
|
652
663
|
|
|
653
664
|
if (name == "efConstruction") {
|
|
654
665
|
if (DC(IndexBinaryHNSW)) {
|
|
655
|
-
|
|
666
|
+
ix_->hnsw.efConstruction = int(val);
|
|
656
667
|
return;
|
|
657
668
|
}
|
|
658
669
|
if (DC(IndexBinaryIVF)) {
|
|
659
670
|
if (IndexBinaryHNSW* cq =
|
|
660
|
-
dynamic_cast<IndexBinaryHNSW*>(
|
|
671
|
+
dynamic_cast<IndexBinaryHNSW*>(ix_->quantizer)) {
|
|
661
672
|
cq->hnsw.efConstruction = int(val);
|
|
662
673
|
return;
|
|
663
674
|
}
|
|
@@ -666,12 +677,12 @@ void ParameterSpace::set_index_parameter(
|
|
|
666
677
|
|
|
667
678
|
if (name == "efSearch") {
|
|
668
679
|
if (DC(IndexBinaryHNSW)) {
|
|
669
|
-
|
|
680
|
+
ix_->hnsw.efSearch = int(val);
|
|
670
681
|
return;
|
|
671
682
|
}
|
|
672
683
|
if (DC(IndexBinaryIVF)) {
|
|
673
684
|
if (IndexBinaryHNSW* cq =
|
|
674
|
-
dynamic_cast<IndexBinaryHNSW*>(
|
|
685
|
+
dynamic_cast<IndexBinaryHNSW*>(ix_->quantizer)) {
|
|
675
686
|
cq->hnsw.efSearch = int(val);
|
|
676
687
|
return;
|
|
677
688
|
}
|
|
@@ -681,7 +692,7 @@ void ParameterSpace::set_index_parameter(
|
|
|
681
692
|
if (name.find("quantizer_") == 0) {
|
|
682
693
|
if (DC(IndexBinaryIVF)) {
|
|
683
694
|
std::string sub_name = name.substr(strlen("quantizer_"));
|
|
684
|
-
set_index_parameter(
|
|
695
|
+
set_index_parameter(ix_->quantizer, sub_name, val);
|
|
685
696
|
return;
|
|
686
697
|
}
|
|
687
698
|
}
|
|
@@ -698,11 +709,11 @@ void ParameterSpace::display() const {
|
|
|
698
709
|
printf("ParameterSpace, %zd parameters, %zd combinations:\n",
|
|
699
710
|
parameter_ranges.size(),
|
|
700
711
|
n_combinations());
|
|
701
|
-
for (
|
|
712
|
+
for (size_t i = 0; i < parameter_ranges.size(); i++) {
|
|
702
713
|
const ParameterRange& pr = parameter_ranges[i];
|
|
703
714
|
printf(" %s: ", pr.name.c_str());
|
|
704
715
|
char sep = '[';
|
|
705
|
-
for (
|
|
716
|
+
for (size_t j = 0; j < pr.values.size(); j++) {
|
|
706
717
|
printf("%c %g", sep, pr.values[j]);
|
|
707
718
|
sep = ',';
|
|
708
719
|
}
|
|
@@ -734,7 +745,8 @@ void ParameterSpace::explore(
|
|
|
734
745
|
const AutoTuneCriterion& crit,
|
|
735
746
|
OperatingPoints* ops) const {
|
|
736
747
|
FAISS_THROW_IF_NOT_MSG(
|
|
737
|
-
nq == crit.nq,
|
|
748
|
+
nq == static_cast<size_t>(crit.nq),
|
|
749
|
+
"criterion does not have the same nb of queries");
|
|
738
750
|
|
|
739
751
|
size_t n_comb = n_combinations();
|
|
740
752
|
|
|
@@ -765,7 +777,7 @@ void ParameterSpace::explore(
|
|
|
765
777
|
return;
|
|
766
778
|
}
|
|
767
779
|
|
|
768
|
-
|
|
780
|
+
size_t n_exp = static_cast<size_t>(n_experiments);
|
|
769
781
|
|
|
770
782
|
if (n_exp > n_comb) {
|
|
771
783
|
n_exp = n_comb;
|
|
@@ -775,9 +787,9 @@ void ParameterSpace::explore(
|
|
|
775
787
|
// make sure the slowest and fastest experiment are run
|
|
776
788
|
perm[0] = 0;
|
|
777
789
|
if (n_comb > 1) {
|
|
778
|
-
perm[1] = n_comb - 1;
|
|
790
|
+
perm[1] = static_cast<int>(n_comb - 1);
|
|
779
791
|
rand_perm(&perm[2], n_comb - 2, 1234);
|
|
780
|
-
for (
|
|
792
|
+
for (size_t i = 2; i < perm.size(); i++) {
|
|
781
793
|
perm[i]++;
|
|
782
794
|
}
|
|
783
795
|
}
|
|
@@ -786,7 +798,7 @@ void ParameterSpace::explore(
|
|
|
786
798
|
size_t cno = perm[xp];
|
|
787
799
|
|
|
788
800
|
if (verbose) {
|
|
789
|
-
printf(" %zd/%
|
|
801
|
+
printf(" %zd/%zd: cno=%zd %s ",
|
|
790
802
|
xp,
|
|
791
803
|
n_exp,
|
|
792
804
|
cno,
|
|
@@ -796,7 +808,7 @@ void ParameterSpace::explore(
|
|
|
796
808
|
{
|
|
797
809
|
double lower_bound_t = 0.0;
|
|
798
810
|
double upper_bound_perf = 1.0;
|
|
799
|
-
for (
|
|
811
|
+
for (size_t i = 0; i < ops->all_pts.size(); i++) {
|
|
800
812
|
update_bounds(
|
|
801
813
|
cno,
|
|
802
814
|
ops->all_pts[i],
|
|
@@ -827,7 +839,8 @@ void ParameterSpace::explore(
|
|
|
827
839
|
do {
|
|
828
840
|
if (thread_over_batches) {
|
|
829
841
|
#pragma omp parallel for
|
|
830
|
-
for (
|
|
842
|
+
for (int64_t q0 = 0; q0 < static_cast<int64_t>(nq);
|
|
843
|
+
q0 += batchsize) {
|
|
831
844
|
size_t q1 = q0 + batchsize;
|
|
832
845
|
if (q1 > nq) {
|
|
833
846
|
q1 = nq;
|