faiss 0.5.3 → 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 +12 -0
- data/ext/faiss/ext.cpp +1 -1
- data/ext/faiss/extconf.rb +4 -4
- data/ext/faiss/index.cpp +63 -45
- data/ext/faiss/index_binary.cpp +37 -27
- data/ext/faiss/kmeans.cpp +9 -8
- data/ext/faiss/pca_matrix.cpp +9 -7
- data/ext/faiss/product_quantizer.cpp +13 -11
- data/ext/faiss/utils.cpp +4 -2
- data/ext/faiss/utils.h +4 -0
- data/lib/faiss/version.rb +1 -1
- data/lib/faiss.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +214 -82
- data/vendor/faiss/faiss/AutoTune.h +14 -1
- data/vendor/faiss/faiss/Clustering.cpp +97 -249
- data/vendor/faiss/faiss/Clustering.h +18 -0
- data/vendor/faiss/faiss/IVFlib.cpp +67 -44
- data/vendor/faiss/faiss/Index.cpp +25 -12
- data/vendor/faiss/faiss/Index.h +26 -4
- data/vendor/faiss/faiss/Index2Layer.cpp +37 -53
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +68 -61
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +36 -34
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +4 -1
- data/vendor/faiss/faiss/IndexBinary.cpp +6 -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 +92 -95
- 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 +120 -414
- data/vendor/faiss/faiss/IndexFastScan.cpp +105 -129
- data/vendor/faiss/faiss/IndexFastScan.h +35 -24
- data/vendor/faiss/faiss/IndexFlat.cpp +216 -152
- data/vendor/faiss/faiss/IndexFlat.h +32 -14
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +88 -41
- data/vendor/faiss/faiss/IndexFlatCodes.h +7 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +299 -187
- data/vendor/faiss/faiss/IndexHNSW.h +30 -14
- data/vendor/faiss/faiss/IndexIDMap.cpp +26 -22
- data/vendor/faiss/faiss/IndexIDMap.h +9 -7
- data/vendor/faiss/faiss/IndexIVF.cpp +535 -405
- data/vendor/faiss/faiss/IndexIVF.h +47 -16
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +77 -74
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +105 -99
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +6 -3
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +379 -249
- data/vendor/faiss/faiss/IndexIVFFastScan.h +65 -60
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +41 -124
- data/vendor/faiss/faiss/IndexIVFFlat.h +32 -0
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.cpp +89 -138
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.h +3 -1
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.cpp +18 -15
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +77 -907
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +184 -122
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +3 -0
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +23 -18
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +59 -60
- data/vendor/faiss/faiss/IndexIVFRaBitQ.h +4 -3
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +564 -416
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +269 -111
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +41 -127
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +1 -1
- data/vendor/faiss/faiss/IndexLSH.cpp +44 -25
- data/vendor/faiss/faiss/IndexLattice.cpp +41 -36
- data/vendor/faiss/faiss/IndexNNDescent.cpp +37 -21
- data/vendor/faiss/faiss/IndexNNDescent.h +2 -2
- data/vendor/faiss/faiss/IndexNSG.cpp +40 -23
- data/vendor/faiss/faiss/IndexNSG.h +0 -2
- data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +32 -12
- data/vendor/faiss/faiss/IndexPQ.cpp +129 -213
- 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 +31 -43
- data/vendor/faiss/faiss/IndexRaBitQ.h +4 -3
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +135 -317
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +192 -34
- data/vendor/faiss/faiss/IndexRefine.cpp +30 -55
- 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 +13 -13
- 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 +29 -6
- data/vendor/faiss/faiss/SuperKMeans.cpp +656 -0
- data/vendor/faiss/faiss/SuperKMeans.h +97 -0
- data/vendor/faiss/faiss/VectorTransform.cpp +349 -141
- data/vendor/faiss/faiss/VectorTransform.h +39 -16
- data/vendor/faiss/faiss/build.cpp +23 -0
- data/vendor/faiss/faiss/build.h +15 -0
- data/vendor/faiss/faiss/clone_index.cpp +55 -51
- 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/{cppcontrib/factory_tools.cpp → factory_tools.cpp} +6 -1
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +1 -1
- 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 +64 -34
- 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 -28
- 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 +367 -0
- data/vendor/faiss/faiss/impl/ClusteringInitialization.h +107 -0
- data/vendor/faiss/faiss/impl/CodePacker.cpp +7 -3
- data/vendor/faiss/faiss/impl/CodePacker.h +11 -3
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +83 -0
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.h +47 -0
- data/vendor/faiss/faiss/impl/DistanceComputer.h +8 -8
- data/vendor/faiss/faiss/impl/FaissAssert.h +64 -3
- data/vendor/faiss/faiss/impl/FaissException.h +50 -3
- data/vendor/faiss/faiss/impl/HNSW.cpp +117 -351
- data/vendor/faiss/faiss/impl/HNSW.h +21 -40
- 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 +114 -102
- data/vendor/faiss/faiss/impl/NNDescent.cpp +63 -26
- data/vendor/faiss/faiss/impl/NNDescent.h +6 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +44 -26
- data/vendor/faiss/faiss/impl/NSG.h +20 -10
- data/vendor/faiss/faiss/impl/Panorama.cpp +76 -52
- data/vendor/faiss/faiss/impl/Panorama.h +265 -78
- 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 +62 -37
- 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 +99 -80
- data/vendor/faiss/faiss/impl/Quantizer.h +2 -2
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +135 -37
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +148 -21
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +298 -301
- data/vendor/faiss/faiss/impl/RaBitQuantizer.h +3 -10
- data/vendor/faiss/faiss/impl/RaBitQuantizerMultiBit.cpp +15 -41
- data/vendor/faiss/faiss/impl/RaBitQuantizerMultiBit.h +0 -4
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +40 -32
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ResultHandler.h +218 -113
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +119 -2362
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +27 -3
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +14 -11
- data/vendor/faiss/faiss/impl/VisitedTable.cpp +42 -0
- data/vendor/faiss/faiss/impl/VisitedTable.h +76 -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 +163 -0
- 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} +176 -4
- 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 -348
- 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} +290 -142
- 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 +1950 -505
- data/vendor/faiss/faiss/impl/index_read_utils.h +1 -2
- data/vendor/faiss/faiss/impl/index_write.cpp +112 -21
- 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 +81 -40
- data/vendor/faiss/faiss/impl/lattice_Zn.h +6 -6
- data/vendor/faiss/faiss/impl/mapped_io.cpp +15 -8
- 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/{code_distance/code_distance-avx2.h → pq_code_distance/pq_code_distance-avx2.h} +43 -220
- data/vendor/faiss/faiss/impl/{code_distance/code_distance-avx512.h → pq_code_distance/pq_code_distance-avx512.h} +25 -112
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.cpp +59 -0
- 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 +256 -0
- data/vendor/faiss/faiss/impl/{code_distance/code_distance-sve.h → pq_code_distance/pq_code_distance-sve.cpp} +57 -146
- data/vendor/faiss/faiss/impl/pq_code_distance/rvv.cpp +68 -0
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +320 -483
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/codecs.h +121 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +137 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +371 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +190 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/similarities.h +94 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +603 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +597 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +388 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +630 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-rvv.cpp +311 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.cpp +387 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.h +54 -0
- data/vendor/faiss/faiss/impl/simd_dispatch.h +173 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib.h +57 -0
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_avx2.h +274 -171
- 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 +275 -217
- 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 +115 -28
- data/vendor/faiss/faiss/index_io.h +53 -3
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +73 -20
- 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 +14 -14
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +9 -19
- data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +2 -2
- data/vendor/faiss/faiss/svs/IndexSVSFlat.h +2 -0
- 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 +19 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.cpp +19 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.h +14 -0
- data/vendor/faiss/faiss/utils/Heap.cpp +56 -10
- data/vendor/faiss/faiss/utils/Heap.h +21 -0
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +54 -40
- 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 +507 -559
- data/vendor/faiss/faiss/utils/distances.h +118 -1
- data/vendor/faiss/faiss/utils/distances_dispatch.h +250 -0
- 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 +72 -3681
- data/vendor/faiss/faiss/utils/extra_distances.cpp +60 -102
- data/vendor/faiss/faiss/utils/extra_distances.h +79 -7
- 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 +251 -0
- 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 +124 -343
- 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 +154 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +777 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +306 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +1431 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +1095 -0
- 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 +392 -0
- 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 +334 -0
- data/vendor/faiss/faiss/utils/simd_levels.h +183 -0
- data/vendor/faiss/faiss/utils/sorting.cpp +48 -36
- data/vendor/faiss/faiss/utils/utils.cpp +21 -14
- data/vendor/faiss/faiss/utils/utils.h +3 -3
- metadata +156 -42
- data/vendor/faiss/faiss/impl/RaBitQStats.cpp +0 -29
- data/vendor/faiss/faiss/impl/RaBitQStats.h +0 -56
- data/vendor/faiss/faiss/impl/code_distance/code_distance-generic.h +0 -81
- data/vendor/faiss/faiss/impl/code_distance/code_distance.h +0 -186
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +0 -216
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +0 -224
- 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 -228
- 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 -450
- 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 -296
- /data/vendor/faiss/faiss/{cppcontrib/factory_tools.h → factory_tools.h} +0 -0
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
#include <faiss/utils/random.h>
|
|
20
20
|
#include <faiss/utils/utils.h>
|
|
21
21
|
|
|
22
|
+
#include <faiss/IndexBinaryHNSW.h>
|
|
23
|
+
#include <faiss/IndexBinaryIVF.h>
|
|
22
24
|
#include <faiss/IndexHNSW.h>
|
|
23
25
|
#include <faiss/IndexIDMap.h>
|
|
24
26
|
#include <faiss/IndexIVF.h>
|
|
@@ -31,35 +33,36 @@
|
|
|
31
33
|
|
|
32
34
|
namespace faiss {
|
|
33
35
|
|
|
34
|
-
AutoTuneCriterion::AutoTuneCriterion(idx_t
|
|
35
|
-
: nq(
|
|
36
|
+
AutoTuneCriterion::AutoTuneCriterion(idx_t nq_in, idx_t nnn_in)
|
|
37
|
+
: nq(nq_in), nnn(nnn_in), gt_nnn(0) {}
|
|
36
38
|
|
|
37
39
|
void AutoTuneCriterion::set_groundtruth(
|
|
38
|
-
int
|
|
40
|
+
int gt_nnn_in,
|
|
39
41
|
const float* gt_D_in,
|
|
40
42
|
const idx_t* gt_I_in) {
|
|
41
|
-
this->gt_nnn =
|
|
43
|
+
this->gt_nnn = gt_nnn_in;
|
|
42
44
|
if (gt_D_in) { // allow null for this, as it is often not used
|
|
43
|
-
gt_D.resize(nq *
|
|
44
|
-
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);
|
|
45
47
|
}
|
|
46
|
-
gt_I.resize(nq *
|
|
47
|
-
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);
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
OneRecallAtRCriterion::OneRecallAtRCriterion(idx_t
|
|
51
|
-
: AutoTuneCriterion(
|
|
52
|
+
OneRecallAtRCriterion::OneRecallAtRCriterion(idx_t nq_in, idx_t R_in)
|
|
53
|
+
: AutoTuneCriterion(nq_in, R_in), R(R_in) {}
|
|
52
54
|
|
|
53
55
|
double OneRecallAtRCriterion::evaluate(const float* /*D*/, const idx_t* I)
|
|
54
56
|
const {
|
|
55
57
|
FAISS_THROW_IF_NOT_MSG(
|
|
56
|
-
(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),
|
|
57
60
|
"ground truth not initialized");
|
|
58
61
|
idx_t n_ok = 0;
|
|
59
62
|
for (idx_t q = 0; q < nq; q++) {
|
|
60
63
|
idx_t gt_nn = gt_I[q * gt_nnn];
|
|
61
64
|
const idx_t* I_line = I + q * nnn;
|
|
62
|
-
for (
|
|
65
|
+
for (idx_t i = 0; i < R; i++) {
|
|
63
66
|
if (I_line[i] == gt_nn) {
|
|
64
67
|
n_ok++;
|
|
65
68
|
break;
|
|
@@ -69,13 +72,14 @@ double OneRecallAtRCriterion::evaluate(const float* /*D*/, const idx_t* I)
|
|
|
69
72
|
return n_ok / double(nq);
|
|
70
73
|
}
|
|
71
74
|
|
|
72
|
-
IntersectionCriterion::IntersectionCriterion(idx_t
|
|
73
|
-
: AutoTuneCriterion(
|
|
75
|
+
IntersectionCriterion::IntersectionCriterion(idx_t nq_in, idx_t R_in)
|
|
76
|
+
: AutoTuneCriterion(nq_in, R_in), R(R_in) {}
|
|
74
77
|
|
|
75
78
|
double IntersectionCriterion::evaluate(const float* /*D*/, const idx_t* I)
|
|
76
79
|
const {
|
|
77
80
|
FAISS_THROW_IF_NOT_MSG(
|
|
78
|
-
(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),
|
|
79
83
|
"ground truth not initialized");
|
|
80
84
|
int64_t n_ok = 0;
|
|
81
85
|
#pragma omp parallel for reduction(+ : n_ok)
|
|
@@ -124,14 +128,14 @@ bool OperatingPoints::add(
|
|
|
124
128
|
return false;
|
|
125
129
|
}
|
|
126
130
|
} else {
|
|
127
|
-
|
|
131
|
+
size_t i;
|
|
128
132
|
// stricto sensu this should be a bisection
|
|
129
133
|
for (i = 0; i < a.size(); i++) {
|
|
130
134
|
if (a[i].perf >= perf) {
|
|
131
135
|
break;
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
|
-
|
|
138
|
+
FAISS_THROW_IF_NOT(i < a.size());
|
|
135
139
|
if (t < a[i].t) {
|
|
136
140
|
if (a[i].perf == perf) {
|
|
137
141
|
a[i] = op;
|
|
@@ -143,7 +147,7 @@ bool OperatingPoints::add(
|
|
|
143
147
|
}
|
|
144
148
|
}
|
|
145
149
|
// remove non-optimal points from array
|
|
146
|
-
for (
|
|
150
|
+
for (size_t i = a.size() - 1; i > 0; --i) {
|
|
147
151
|
if (a[i].t < a[i - 1].t) {
|
|
148
152
|
a.erase(a.begin() + (i - 1));
|
|
149
153
|
}
|
|
@@ -155,7 +159,7 @@ int OperatingPoints::merge_with(
|
|
|
155
159
|
const OperatingPoints& other,
|
|
156
160
|
const std::string& prefix) {
|
|
157
161
|
int n_add = 0;
|
|
158
|
-
for (
|
|
162
|
+
for (size_t i = 0; i < other.all_pts.size(); i++) {
|
|
159
163
|
const OperatingPoint& op = other.all_pts[i];
|
|
160
164
|
if (add(op.perf, op.t, prefix + op.key, op.cno)) {
|
|
161
165
|
n_add++;
|
|
@@ -170,7 +174,7 @@ double OperatingPoints::t_for_perf(double perf) const {
|
|
|
170
174
|
if (perf > a.back().perf) {
|
|
171
175
|
return 1e50;
|
|
172
176
|
}
|
|
173
|
-
int i0 = -1, i1 = a.size() - 1;
|
|
177
|
+
int i0 = -1, i1 = static_cast<int>(a.size()) - 1;
|
|
174
178
|
while (i0 + 1 < i1) {
|
|
175
179
|
int imed = (i0 + i1 + 1) / 2;
|
|
176
180
|
if (a[imed].perf < perf) {
|
|
@@ -189,7 +193,7 @@ void OperatingPoints::all_to_gnuplot(const char* fname) const {
|
|
|
189
193
|
perror("");
|
|
190
194
|
abort();
|
|
191
195
|
}
|
|
192
|
-
for (
|
|
196
|
+
for (size_t i = 0; i < all_pts.size(); i++) {
|
|
193
197
|
const OperatingPoint& op = all_pts[i];
|
|
194
198
|
fprintf(f, "%g %g %s\n", op.perf, op.t, op.key.c_str());
|
|
195
199
|
}
|
|
@@ -204,7 +208,7 @@ void OperatingPoints::optimal_to_gnuplot(const char* fname) const {
|
|
|
204
208
|
abort();
|
|
205
209
|
}
|
|
206
210
|
double prev_perf = 0.0;
|
|
207
|
-
for (
|
|
211
|
+
for (size_t i = 0; i < optimal_pts.size(); i++) {
|
|
208
212
|
const OperatingPoint& op = optimal_pts[i];
|
|
209
213
|
fprintf(f, "%g %g\n", prev_perf, op.t);
|
|
210
214
|
fprintf(f, "%g %g %s\n", op.perf, op.t, op.key.c_str());
|
|
@@ -220,11 +224,11 @@ void OperatingPoints::display(bool only_optimal) const {
|
|
|
220
224
|
all_pts.size(),
|
|
221
225
|
optimal_pts.size());
|
|
222
226
|
|
|
223
|
-
for (
|
|
227
|
+
for (size_t i = 0; i < pts.size(); i++) {
|
|
224
228
|
const OperatingPoint& op = pts[i];
|
|
225
229
|
const char* star = "";
|
|
226
230
|
if (!only_optimal) {
|
|
227
|
-
for (
|
|
231
|
+
for (size_t j = 0; j < optimal_pts.size(); j++) {
|
|
228
232
|
if (op.cno == optimal_pts[j].cno) {
|
|
229
233
|
star = "*";
|
|
230
234
|
break;
|
|
@@ -267,7 +271,7 @@ ParameterSpace::ParameterSpace (Index *index):
|
|
|
267
271
|
|
|
268
272
|
size_t ParameterSpace::n_combinations() const {
|
|
269
273
|
size_t n = 1;
|
|
270
|
-
for (
|
|
274
|
+
for (size_t i = 0; i < parameter_ranges.size(); i++) {
|
|
271
275
|
n *= parameter_ranges[i].values.size();
|
|
272
276
|
}
|
|
273
277
|
return n;
|
|
@@ -275,9 +279,10 @@ size_t ParameterSpace::n_combinations() const {
|
|
|
275
279
|
|
|
276
280
|
/// get string representation of the combination
|
|
277
281
|
std::string ParameterSpace::combination_name(size_t cno) const {
|
|
278
|
-
char buf[1000]
|
|
282
|
+
char buf[1000];
|
|
283
|
+
char* wp = buf;
|
|
279
284
|
*wp = 0;
|
|
280
|
-
for (
|
|
285
|
+
for (size_t i = 0; i < parameter_ranges.size(); i++) {
|
|
281
286
|
FAISS_THROW_IF_NOT_MSG(
|
|
282
287
|
buf + 1000 - wp >= 0, "Overflow detected in snprintf");
|
|
283
288
|
const ParameterRange& pr = parameter_ranges[i];
|
|
@@ -295,8 +300,8 @@ std::string ParameterSpace::combination_name(size_t cno) const {
|
|
|
295
300
|
}
|
|
296
301
|
|
|
297
302
|
bool ParameterSpace::combination_ge(size_t c1, size_t c2) const {
|
|
298
|
-
for (
|
|
299
|
-
|
|
303
|
+
for (size_t i = 0; i < parameter_ranges.size(); i++) {
|
|
304
|
+
size_t nval = parameter_ranges[i].values.size();
|
|
300
305
|
size_t j1 = c1 % nval;
|
|
301
306
|
size_t j2 = c2 % nval;
|
|
302
307
|
if (!(j1 >= j2)) {
|
|
@@ -314,7 +319,7 @@ static void init_pq_ParameterRange(
|
|
|
314
319
|
if (pq.code_size % 4 == 0) {
|
|
315
320
|
// Polysemous not supported for code sizes that are not a
|
|
316
321
|
// multiple of 4
|
|
317
|
-
for (
|
|
322
|
+
for (size_t i = 2; i <= pq.code_size * 8 / 2; i += 2) {
|
|
318
323
|
pr.values.push_back(i);
|
|
319
324
|
}
|
|
320
325
|
}
|
|
@@ -334,22 +339,22 @@ ParameterRange& ParameterSpace::add_range(const std::string& name) {
|
|
|
334
339
|
|
|
335
340
|
// Do not use this macro if ix will be unused
|
|
336
341
|
#define DC(classname) \
|
|
337
|
-
const classname*
|
|
342
|
+
const classname* ix_c = dynamic_cast<const classname*>(index)
|
|
338
343
|
|
|
339
344
|
/// initialize with reasonable parameters for this type of index
|
|
340
345
|
void ParameterSpace::initialize(const Index* index) {
|
|
341
346
|
if (DC(IndexPreTransform)) {
|
|
342
|
-
index =
|
|
347
|
+
index = ix_c->index;
|
|
343
348
|
}
|
|
344
349
|
if (DC(IndexRefine)) {
|
|
345
350
|
ParameterRange& pr = add_range("k_factor_rf");
|
|
346
351
|
for (int i = 0; i <= 6; i++) {
|
|
347
352
|
pr.values.push_back(1 << i);
|
|
348
353
|
}
|
|
349
|
-
index =
|
|
354
|
+
index = ix_c->base_index;
|
|
350
355
|
}
|
|
351
356
|
if (DC(IndexPreTransform)) {
|
|
352
|
-
index =
|
|
357
|
+
index = ix_c->index;
|
|
353
358
|
}
|
|
354
359
|
|
|
355
360
|
if (DC(IndexIVFInterface)) {
|
|
@@ -357,14 +362,14 @@ void ParameterSpace::initialize(const Index* index) {
|
|
|
357
362
|
ParameterRange& pr = add_range("nprobe");
|
|
358
363
|
for (int i = 0; i < 13; i++) {
|
|
359
364
|
size_t nprobe = 1 << i;
|
|
360
|
-
if (nprobe >=
|
|
365
|
+
if (nprobe >= ix_c->nlist) {
|
|
361
366
|
break;
|
|
362
367
|
}
|
|
363
368
|
pr.values.push_back(nprobe);
|
|
364
369
|
}
|
|
365
370
|
}
|
|
366
371
|
ParameterSpace ivf_pspace;
|
|
367
|
-
ivf_pspace.initialize(
|
|
372
|
+
ivf_pspace.initialize(ix_c->quantizer);
|
|
368
373
|
|
|
369
374
|
for (const ParameterRange& p : ivf_pspace.parameter_ranges) {
|
|
370
375
|
ParameterRange& pr = add_range("quantizer_" + p.name);
|
|
@@ -373,16 +378,16 @@ void ParameterSpace::initialize(const Index* index) {
|
|
|
373
378
|
}
|
|
374
379
|
if (DC(IndexPQ)) {
|
|
375
380
|
ParameterRange& pr = add_range("ht");
|
|
376
|
-
init_pq_ParameterRange(
|
|
381
|
+
init_pq_ParameterRange(ix_c->pq, pr);
|
|
377
382
|
}
|
|
378
383
|
if (DC(IndexIVFPQ)) {
|
|
379
384
|
ParameterRange& pr = add_range("ht");
|
|
380
|
-
init_pq_ParameterRange(
|
|
385
|
+
init_pq_ParameterRange(ix_c->pq, pr);
|
|
381
386
|
}
|
|
382
387
|
|
|
383
388
|
if (DC(IndexIVF)) {
|
|
384
389
|
const MultiIndexQuantizer* miq =
|
|
385
|
-
dynamic_cast<const MultiIndexQuantizer*>(
|
|
390
|
+
dynamic_cast<const MultiIndexQuantizer*>(ix_c->quantizer);
|
|
386
391
|
if (miq) {
|
|
387
392
|
ParameterRange& pr_max_codes = add_range("max_codes");
|
|
388
393
|
for (int i = 8; i < 20; i++) {
|
|
@@ -408,21 +413,24 @@ void ParameterSpace::initialize(const Index* index) {
|
|
|
408
413
|
|
|
409
414
|
#undef DC
|
|
410
415
|
|
|
411
|
-
|
|
412
|
-
void
|
|
413
|
-
|
|
414
|
-
|
|
416
|
+
template <typename SetParamFunc>
|
|
417
|
+
static void set_index_parameters_common(
|
|
418
|
+
const ParameterSpace* ps,
|
|
419
|
+
size_t cno,
|
|
420
|
+
SetParamFunc set_param) {
|
|
421
|
+
for (size_t i = 0; i < ps->parameter_ranges.size(); i++) {
|
|
422
|
+
const ParameterRange& pr = ps->parameter_ranges[i];
|
|
415
423
|
size_t j = cno % pr.values.size();
|
|
416
424
|
cno /= pr.values.size();
|
|
417
425
|
double val = pr.values[j];
|
|
418
|
-
|
|
426
|
+
set_param(pr.name, val);
|
|
419
427
|
}
|
|
420
428
|
}
|
|
421
429
|
|
|
422
|
-
|
|
423
|
-
void
|
|
424
|
-
|
|
425
|
-
|
|
430
|
+
template <typename SetParamFunc>
|
|
431
|
+
static void set_index_parameters_string_common(
|
|
432
|
+
const char* description_in,
|
|
433
|
+
SetParamFunc set_param) {
|
|
426
434
|
std::string description(description_in);
|
|
427
435
|
char* ptr;
|
|
428
436
|
|
|
@@ -433,13 +441,50 @@ void ParameterSpace::set_index_parameters(
|
|
|
433
441
|
int ret = sscanf(tok, "%99[^=]=%lf", name, &val);
|
|
434
442
|
FAISS_THROW_IF_NOT_FMT(
|
|
435
443
|
ret == 2, "could not interpret parameters %s", tok);
|
|
436
|
-
|
|
444
|
+
set_param(name, val);
|
|
437
445
|
}
|
|
438
446
|
}
|
|
439
447
|
|
|
448
|
+
/// set a combination of parameters on an index
|
|
449
|
+
void ParameterSpace::set_index_parameters(Index* index, size_t cno) const {
|
|
450
|
+
set_index_parameters_common(
|
|
451
|
+
this, cno, [this, index](const std::string& name, double val) {
|
|
452
|
+
this->set_index_parameter(index, name, val);
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/// set a combination of parameters on an index
|
|
457
|
+
void ParameterSpace::set_index_parameters(
|
|
458
|
+
Index* index,
|
|
459
|
+
const char* description_in) const {
|
|
460
|
+
set_index_parameters_string_common(
|
|
461
|
+
description_in, [this, index](const std::string& name, double val) {
|
|
462
|
+
this->set_index_parameter(index, name, val);
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/// set a combination of parameters on a binary index
|
|
467
|
+
void ParameterSpace::set_index_parameters(IndexBinary* index, size_t cno)
|
|
468
|
+
const {
|
|
469
|
+
set_index_parameters_common(
|
|
470
|
+
this, cno, [this, index](const std::string& name, double val) {
|
|
471
|
+
this->set_index_parameter(index, name, val);
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/// set a combination of parameters on a binary index
|
|
476
|
+
void ParameterSpace::set_index_parameters(
|
|
477
|
+
IndexBinary* index,
|
|
478
|
+
const char* description_in) const {
|
|
479
|
+
set_index_parameters_string_common(
|
|
480
|
+
description_in, [this, index](const std::string& name, double val) {
|
|
481
|
+
this->set_index_parameter(index, name, val);
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
|
|
440
485
|
// non-const version
|
|
441
486
|
// Do not use this macro if ix will be unused
|
|
442
|
-
#define DC(classname) classname*
|
|
487
|
+
#define DC(classname) classname* ix_ = dynamic_cast<classname*>(index)
|
|
443
488
|
|
|
444
489
|
void ParameterSpace::set_index_parameter(
|
|
445
490
|
Index* index,
|
|
@@ -454,11 +499,11 @@ void ParameterSpace::set_index_parameter(
|
|
|
454
499
|
// and fall through to also enable it on sub-indexes
|
|
455
500
|
}
|
|
456
501
|
if (DC(IndexIDMap)) {
|
|
457
|
-
set_index_parameter(
|
|
502
|
+
set_index_parameter(ix_->index, name, val);
|
|
458
503
|
return;
|
|
459
504
|
}
|
|
460
505
|
if (DC(IndexPreTransform)) {
|
|
461
|
-
set_index_parameter(
|
|
506
|
+
set_index_parameter(ix_->index, name, val);
|
|
462
507
|
return;
|
|
463
508
|
}
|
|
464
509
|
if (DC(IndexShardsIVF)) {
|
|
@@ -467,7 +512,7 @@ void ParameterSpace::set_index_parameter(
|
|
|
467
512
|
if (name.find("quantizer_") == 0 && name != "nprobe" &&
|
|
468
513
|
name != "quantizer_nprobe") {
|
|
469
514
|
std::string sub_name = name.substr(strlen("quantizer_"));
|
|
470
|
-
set_index_parameter(
|
|
515
|
+
set_index_parameter(ix_->quantizer, sub_name, val);
|
|
471
516
|
return;
|
|
472
517
|
}
|
|
473
518
|
}
|
|
@@ -476,45 +521,45 @@ void ParameterSpace::set_index_parameter(
|
|
|
476
521
|
auto fn = [this, name, val](int /* no */, Index* subIndex) {
|
|
477
522
|
set_index_parameter(subIndex, name, val);
|
|
478
523
|
};
|
|
479
|
-
|
|
524
|
+
ix_->runOnIndex(fn);
|
|
480
525
|
return;
|
|
481
526
|
}
|
|
482
527
|
if (DC(IndexRefine)) {
|
|
483
528
|
if (name == "k_factor_rf") {
|
|
484
|
-
|
|
529
|
+
ix_->k_factor = int(val);
|
|
485
530
|
return;
|
|
486
531
|
}
|
|
487
532
|
// otherwise it is for the sub-index
|
|
488
|
-
set_index_parameter(
|
|
533
|
+
set_index_parameter(ix_->base_index, name, val);
|
|
489
534
|
return;
|
|
490
535
|
}
|
|
491
536
|
|
|
492
537
|
if (name == "verbose") {
|
|
493
|
-
index->verbose = int(val);
|
|
494
538
|
return; // last verbose that we could find
|
|
495
539
|
}
|
|
496
540
|
|
|
497
541
|
if (name == "nprobe") {
|
|
498
542
|
if (DC(IndexIVF)) {
|
|
499
|
-
|
|
543
|
+
ix_->nprobe = int(val);
|
|
500
544
|
return;
|
|
501
545
|
}
|
|
502
546
|
}
|
|
503
547
|
|
|
504
548
|
if (name == "ht") {
|
|
505
549
|
if (DC(IndexPQ)) {
|
|
506
|
-
if (val >=
|
|
507
|
-
|
|
550
|
+
if (val >= ix_->pq.code_size * 8) {
|
|
551
|
+
ix_->search_type = IndexPQ::ST_PQ;
|
|
508
552
|
} else {
|
|
509
|
-
|
|
510
|
-
|
|
553
|
+
ix_->search_type = IndexPQ::ST_polysemous;
|
|
554
|
+
ix_->polysemous_ht = int(val);
|
|
511
555
|
}
|
|
512
556
|
return;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
|
|
557
|
+
}
|
|
558
|
+
if (DC(IndexIVFPQ)) {
|
|
559
|
+
if (val >= ix_->pq.code_size * 8) {
|
|
560
|
+
ix_->polysemous_ht = 0;
|
|
516
561
|
} else {
|
|
517
|
-
|
|
562
|
+
ix_->polysemous_ht = int(val);
|
|
518
563
|
}
|
|
519
564
|
return;
|
|
520
565
|
}
|
|
@@ -522,24 +567,31 @@ void ParameterSpace::set_index_parameter(
|
|
|
522
567
|
|
|
523
568
|
if (name == "k_factor") {
|
|
524
569
|
if (DC(IndexIVFPQR)) {
|
|
525
|
-
|
|
570
|
+
ix_->k_factor = val;
|
|
526
571
|
return;
|
|
527
572
|
}
|
|
528
573
|
}
|
|
529
574
|
if (name == "max_codes") {
|
|
530
575
|
if (DC(IndexIVF)) {
|
|
531
|
-
|
|
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;
|
|
532
584
|
return;
|
|
533
585
|
}
|
|
534
586
|
}
|
|
535
587
|
|
|
536
588
|
if (name == "efConstruction") {
|
|
537
589
|
if (DC(IndexHNSW)) {
|
|
538
|
-
|
|
590
|
+
ix_->hnsw.efConstruction = int(val);
|
|
539
591
|
return;
|
|
540
592
|
}
|
|
541
593
|
if (DC(IndexIVF)) {
|
|
542
|
-
if (IndexHNSW* cq = dynamic_cast<IndexHNSW*>(
|
|
594
|
+
if (IndexHNSW* cq = dynamic_cast<IndexHNSW*>(ix_->quantizer)) {
|
|
543
595
|
cq->hnsw.efConstruction = int(val);
|
|
544
596
|
return;
|
|
545
597
|
}
|
|
@@ -548,11 +600,11 @@ void ParameterSpace::set_index_parameter(
|
|
|
548
600
|
|
|
549
601
|
if (name == "efSearch") {
|
|
550
602
|
if (DC(IndexHNSW)) {
|
|
551
|
-
|
|
603
|
+
ix_->hnsw.efSearch = int(val);
|
|
552
604
|
return;
|
|
553
605
|
}
|
|
554
606
|
if (DC(IndexIVF)) {
|
|
555
|
-
if (IndexHNSW* cq = dynamic_cast<IndexHNSW*>(
|
|
607
|
+
if (IndexHNSW* cq = dynamic_cast<IndexHNSW*>(ix_->quantizer)) {
|
|
556
608
|
cq->hnsw.efSearch = int(val);
|
|
557
609
|
return;
|
|
558
610
|
}
|
|
@@ -562,7 +614,7 @@ void ParameterSpace::set_index_parameter(
|
|
|
562
614
|
if (name.find("quantizer_") == 0) {
|
|
563
615
|
if (DC(IndexIVF)) {
|
|
564
616
|
std::string sub_name = name.substr(strlen("quantizer_"));
|
|
565
|
-
set_index_parameter(
|
|
617
|
+
set_index_parameter(ix_->quantizer, sub_name, val);
|
|
566
618
|
return;
|
|
567
619
|
}
|
|
568
620
|
}
|
|
@@ -573,17 +625,95 @@ void ParameterSpace::set_index_parameter(
|
|
|
573
625
|
name.c_str());
|
|
574
626
|
}
|
|
575
627
|
|
|
628
|
+
void ParameterSpace::set_index_parameter(
|
|
629
|
+
IndexBinary* index,
|
|
630
|
+
const std::string& name,
|
|
631
|
+
double val) const {
|
|
632
|
+
if (verbose > 1) {
|
|
633
|
+
printf(" set_index_parameter (binary) %s=%g\n", name.c_str(), val);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (name == "verbose") {
|
|
637
|
+
index->verbose = int(val);
|
|
638
|
+
// and fall through to also enable it on sub-indexes
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
if (DC(IndexBinaryIDMap)) {
|
|
642
|
+
set_index_parameter(ix_->index, name, val);
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (name == "verbose") {
|
|
647
|
+
return; // last verbose that we could find
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
if (name == "nprobe") {
|
|
651
|
+
if (DC(IndexBinaryIVF)) {
|
|
652
|
+
ix_->nprobe = int(val);
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (name == "max_codes") {
|
|
658
|
+
if (DC(IndexBinaryIVF)) {
|
|
659
|
+
ix_->max_codes = std::isfinite(val) ? size_t(val) : 0;
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
if (name == "efConstruction") {
|
|
665
|
+
if (DC(IndexBinaryHNSW)) {
|
|
666
|
+
ix_->hnsw.efConstruction = int(val);
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
if (DC(IndexBinaryIVF)) {
|
|
670
|
+
if (IndexBinaryHNSW* cq =
|
|
671
|
+
dynamic_cast<IndexBinaryHNSW*>(ix_->quantizer)) {
|
|
672
|
+
cq->hnsw.efConstruction = int(val);
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
if (name == "efSearch") {
|
|
679
|
+
if (DC(IndexBinaryHNSW)) {
|
|
680
|
+
ix_->hnsw.efSearch = int(val);
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
if (DC(IndexBinaryIVF)) {
|
|
684
|
+
if (IndexBinaryHNSW* cq =
|
|
685
|
+
dynamic_cast<IndexBinaryHNSW*>(ix_->quantizer)) {
|
|
686
|
+
cq->hnsw.efSearch = int(val);
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
if (name.find("quantizer_") == 0) {
|
|
693
|
+
if (DC(IndexBinaryIVF)) {
|
|
694
|
+
std::string sub_name = name.substr(strlen("quantizer_"));
|
|
695
|
+
set_index_parameter(ix_->quantizer, sub_name, val);
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
FAISS_THROW_FMT(
|
|
701
|
+
"ParameterSpace::set_index_parameter:"
|
|
702
|
+
"could not set parameter %s on binary index",
|
|
703
|
+
name.c_str());
|
|
704
|
+
}
|
|
705
|
+
|
|
576
706
|
#undef DC
|
|
577
707
|
|
|
578
708
|
void ParameterSpace::display() const {
|
|
579
709
|
printf("ParameterSpace, %zd parameters, %zd combinations:\n",
|
|
580
710
|
parameter_ranges.size(),
|
|
581
711
|
n_combinations());
|
|
582
|
-
for (
|
|
712
|
+
for (size_t i = 0; i < parameter_ranges.size(); i++) {
|
|
583
713
|
const ParameterRange& pr = parameter_ranges[i];
|
|
584
714
|
printf(" %s: ", pr.name.c_str());
|
|
585
715
|
char sep = '[';
|
|
586
|
-
for (
|
|
716
|
+
for (size_t j = 0; j < pr.values.size(); j++) {
|
|
587
717
|
printf("%c %g", sep, pr.values[j]);
|
|
588
718
|
sep = ',';
|
|
589
719
|
}
|
|
@@ -615,7 +745,8 @@ void ParameterSpace::explore(
|
|
|
615
745
|
const AutoTuneCriterion& crit,
|
|
616
746
|
OperatingPoints* ops) const {
|
|
617
747
|
FAISS_THROW_IF_NOT_MSG(
|
|
618
|
-
nq == crit.nq,
|
|
748
|
+
nq == static_cast<size_t>(crit.nq),
|
|
749
|
+
"criterion does not have the same nb of queries");
|
|
619
750
|
|
|
620
751
|
size_t n_comb = n_combinations();
|
|
621
752
|
|
|
@@ -646,7 +777,7 @@ void ParameterSpace::explore(
|
|
|
646
777
|
return;
|
|
647
778
|
}
|
|
648
779
|
|
|
649
|
-
|
|
780
|
+
size_t n_exp = static_cast<size_t>(n_experiments);
|
|
650
781
|
|
|
651
782
|
if (n_exp > n_comb) {
|
|
652
783
|
n_exp = n_comb;
|
|
@@ -656,9 +787,9 @@ void ParameterSpace::explore(
|
|
|
656
787
|
// make sure the slowest and fastest experiment are run
|
|
657
788
|
perm[0] = 0;
|
|
658
789
|
if (n_comb > 1) {
|
|
659
|
-
perm[1] = n_comb - 1;
|
|
790
|
+
perm[1] = static_cast<int>(n_comb - 1);
|
|
660
791
|
rand_perm(&perm[2], n_comb - 2, 1234);
|
|
661
|
-
for (
|
|
792
|
+
for (size_t i = 2; i < perm.size(); i++) {
|
|
662
793
|
perm[i]++;
|
|
663
794
|
}
|
|
664
795
|
}
|
|
@@ -667,7 +798,7 @@ void ParameterSpace::explore(
|
|
|
667
798
|
size_t cno = perm[xp];
|
|
668
799
|
|
|
669
800
|
if (verbose) {
|
|
670
|
-
printf(" %zd/%
|
|
801
|
+
printf(" %zd/%zd: cno=%zd %s ",
|
|
671
802
|
xp,
|
|
672
803
|
n_exp,
|
|
673
804
|
cno,
|
|
@@ -677,7 +808,7 @@ void ParameterSpace::explore(
|
|
|
677
808
|
{
|
|
678
809
|
double lower_bound_t = 0.0;
|
|
679
810
|
double upper_bound_perf = 1.0;
|
|
680
|
-
for (
|
|
811
|
+
for (size_t i = 0; i < ops->all_pts.size(); i++) {
|
|
681
812
|
update_bounds(
|
|
682
813
|
cno,
|
|
683
814
|
ops->all_pts[i],
|
|
@@ -708,7 +839,8 @@ void ParameterSpace::explore(
|
|
|
708
839
|
do {
|
|
709
840
|
if (thread_over_batches) {
|
|
710
841
|
#pragma omp parallel for
|
|
711
|
-
for (
|
|
842
|
+
for (int64_t q0 = 0; q0 < static_cast<int64_t>(nq);
|
|
843
|
+
q0 += batchsize) {
|
|
712
844
|
size_t q1 = q0 + batchsize;
|
|
713
845
|
if (q1 > nq) {
|
|
714
846
|
q1 = nq;
|
|
@@ -177,12 +177,25 @@ struct ParameterSpace {
|
|
|
177
177
|
/// set a combination of parameters described by a string
|
|
178
178
|
void set_index_parameters(Index* index, const char* param_string) const;
|
|
179
179
|
|
|
180
|
-
/// set one of the parameters
|
|
180
|
+
/// set one of the parameters
|
|
181
181
|
virtual void set_index_parameter(
|
|
182
182
|
Index* index,
|
|
183
183
|
const std::string& name,
|
|
184
184
|
double val) const;
|
|
185
185
|
|
|
186
|
+
/// set a combination of parameters on a binary index
|
|
187
|
+
void set_index_parameters(IndexBinary* index, size_t cno) const;
|
|
188
|
+
|
|
189
|
+
/// set a combination of parameters described by a string on a binary index
|
|
190
|
+
void set_index_parameters(IndexBinary* index, const char* param_string)
|
|
191
|
+
const;
|
|
192
|
+
|
|
193
|
+
/// set one of the parameters on a binary index
|
|
194
|
+
virtual void set_index_parameter(
|
|
195
|
+
IndexBinary* index,
|
|
196
|
+
const std::string& name,
|
|
197
|
+
double val) const;
|
|
198
|
+
|
|
186
199
|
/** find an upper bound on the performance and a lower bound on t
|
|
187
200
|
* for configuration cno given another operating point op */
|
|
188
201
|
void update_bounds(
|