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
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Portions Copyright 2026 Intel Corporation
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#include <faiss/svs/IndexSVSFaissUtils.h>
|
|
25
|
+
#include <faiss/svs/IndexSVSIVF.h>
|
|
26
|
+
|
|
27
|
+
#include <faiss/Index.h>
|
|
28
|
+
|
|
29
|
+
#include <svs/runtime/api_defs.h>
|
|
30
|
+
#include <svs/runtime/dynamic_ivf_index.h>
|
|
31
|
+
#include <svs/runtime/ivf_index.h>
|
|
32
|
+
|
|
33
|
+
#include <cstddef>
|
|
34
|
+
#include <numeric>
|
|
35
|
+
#include <span>
|
|
36
|
+
#include <type_traits>
|
|
37
|
+
#include <vector>
|
|
38
|
+
|
|
39
|
+
namespace faiss {
|
|
40
|
+
namespace {
|
|
41
|
+
svs_runtime::IVFIndex::SearchParams make_ivf_search_parameters(
|
|
42
|
+
const IndexSVSIVF& index,
|
|
43
|
+
const SearchParameters* params) {
|
|
44
|
+
FAISS_THROW_IF_NOT(index.impl);
|
|
45
|
+
|
|
46
|
+
auto n_probes = index.n_probes;
|
|
47
|
+
auto k_reorder = index.k_reorder;
|
|
48
|
+
|
|
49
|
+
if (auto svs_params = dynamic_cast<const SearchParametersSVSIVF*>(params)) {
|
|
50
|
+
if (svs_params->n_probes > 0) {
|
|
51
|
+
n_probes = svs_params->n_probes;
|
|
52
|
+
}
|
|
53
|
+
if (svs_params->k_reorder > 0) {
|
|
54
|
+
k_reorder = svs_params->k_reorder;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {n_probes, k_reorder};
|
|
59
|
+
}
|
|
60
|
+
} // namespace
|
|
61
|
+
|
|
62
|
+
IndexSVSIVF::IndexSVSIVF() = default;
|
|
63
|
+
|
|
64
|
+
IndexSVSIVF::IndexSVSIVF(
|
|
65
|
+
idx_t d,
|
|
66
|
+
size_t nlist,
|
|
67
|
+
MetricType metric,
|
|
68
|
+
SVSStorageKind storage,
|
|
69
|
+
bool is_static)
|
|
70
|
+
: Index(d, metric),
|
|
71
|
+
num_centroids{nlist},
|
|
72
|
+
is_static{is_static},
|
|
73
|
+
storage_kind{storage} {
|
|
74
|
+
is_trained = false;
|
|
75
|
+
|
|
76
|
+
// Validate the requested storage kind is available in current runtime.
|
|
77
|
+
auto svs_storage = to_svs_storage_kind(storage_kind);
|
|
78
|
+
auto status = is_static
|
|
79
|
+
? svs_runtime::IVFIndex::check_storage_kind(svs_storage)
|
|
80
|
+
: svs_runtime::DynamicIVFIndex::check_storage_kind(svs_storage);
|
|
81
|
+
if (!status.ok()) {
|
|
82
|
+
FAISS_THROW_MSG(status.message());
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
bool IndexSVSIVF::is_lvq_leanvec_enabled() {
|
|
87
|
+
auto lvq = to_svs_storage_kind(SVS_LVQ4x0);
|
|
88
|
+
auto status = svs_runtime::IVFIndex::check_storage_kind(lvq);
|
|
89
|
+
if (!status.ok()) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
status = svs_runtime::DynamicIVFIndex::check_storage_kind(lvq);
|
|
93
|
+
if (!status.ok()) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
auto leanvec = to_svs_storage_kind(SVS_LeanVec4x4);
|
|
97
|
+
status = svs_runtime::IVFIndex::check_storage_kind(leanvec);
|
|
98
|
+
if (!status.ok()) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
status = svs_runtime::DynamicIVFIndex::check_storage_kind(leanvec);
|
|
102
|
+
if (!status.ok()) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
IndexSVSIVF::~IndexSVSIVF() {
|
|
109
|
+
if (impl) {
|
|
110
|
+
svs_runtime::Status status;
|
|
111
|
+
if (is_static) {
|
|
112
|
+
status = svs_runtime::IVFIndex::destroy(impl);
|
|
113
|
+
} else {
|
|
114
|
+
status = svs_runtime::DynamicIVFIndex::destroy(
|
|
115
|
+
static_cast<svs_runtime::DynamicIVFIndex*>(impl));
|
|
116
|
+
}
|
|
117
|
+
FAISS_ASSERT(status.ok());
|
|
118
|
+
impl = nullptr;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
void IndexSVSIVF::train(idx_t n, const float* x) {
|
|
123
|
+
FAISS_THROW_IF_MSG(impl, "Index already trained or contains data.");
|
|
124
|
+
create_impl(n, x);
|
|
125
|
+
is_trained = true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
void IndexSVSIVF::add(idx_t n, const float* x) {
|
|
129
|
+
FAISS_THROW_IF_MSG(
|
|
130
|
+
is_static,
|
|
131
|
+
"Static IVF index does not support add() after initial index "
|
|
132
|
+
"creation. All data must be provided during train().");
|
|
133
|
+
FAISS_THROW_IF_MSG(
|
|
134
|
+
!is_trained, "Index not trained: call train() before add().");
|
|
135
|
+
FAISS_THROW_IF_NOT(impl);
|
|
136
|
+
|
|
137
|
+
auto* dyn = dynamic_impl();
|
|
138
|
+
std::vector<size_t> labels(n);
|
|
139
|
+
std::iota(labels.begin(), labels.end(), ntotal);
|
|
140
|
+
|
|
141
|
+
auto status = dyn->add(n, labels.data(), x);
|
|
142
|
+
if (!status.ok()) {
|
|
143
|
+
FAISS_THROW_MSG(status.message());
|
|
144
|
+
}
|
|
145
|
+
ntotal += n;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
void IndexSVSIVF::reset() {
|
|
149
|
+
if (impl) {
|
|
150
|
+
svs_runtime::Status status;
|
|
151
|
+
if (is_static) {
|
|
152
|
+
status = svs_runtime::IVFIndex::destroy(impl);
|
|
153
|
+
} else {
|
|
154
|
+
status = svs_runtime::DynamicIVFIndex::destroy(
|
|
155
|
+
static_cast<svs_runtime::DynamicIVFIndex*>(impl));
|
|
156
|
+
}
|
|
157
|
+
FAISS_ASSERT(status.ok());
|
|
158
|
+
impl = nullptr;
|
|
159
|
+
}
|
|
160
|
+
is_trained = false;
|
|
161
|
+
ntotal = 0;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
void IndexSVSIVF::search(
|
|
165
|
+
idx_t n,
|
|
166
|
+
const float* x,
|
|
167
|
+
idx_t k,
|
|
168
|
+
float* distances,
|
|
169
|
+
idx_t* labels,
|
|
170
|
+
const SearchParameters* params) const {
|
|
171
|
+
if (!impl) {
|
|
172
|
+
for (idx_t i = 0; i < n * k; ++i) {
|
|
173
|
+
distances[i] = std::numeric_limits<float>::infinity();
|
|
174
|
+
labels[i] = -1;
|
|
175
|
+
}
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
FAISS_THROW_IF_NOT(k > 0);
|
|
179
|
+
FAISS_THROW_IF_NOT(is_trained);
|
|
180
|
+
|
|
181
|
+
// Sync thread settings to the SVS backend before searching
|
|
182
|
+
{
|
|
183
|
+
size_t current_threads = 0;
|
|
184
|
+
impl->get_num_threads(¤t_threads);
|
|
185
|
+
if (num_threads > 0 && current_threads != num_threads) {
|
|
186
|
+
auto st = impl->set_num_threads(num_threads);
|
|
187
|
+
if (!st.ok()) {
|
|
188
|
+
FAISS_THROW_MSG(st.message());
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
auto sp = make_ivf_search_parameters(*this, params);
|
|
194
|
+
auto status = impl->search(
|
|
195
|
+
static_cast<size_t>(n),
|
|
196
|
+
x,
|
|
197
|
+
static_cast<size_t>(k),
|
|
198
|
+
distances,
|
|
199
|
+
convert_output_buffer<size_t>(labels, static_cast<size_t>(n * k)),
|
|
200
|
+
&sp);
|
|
201
|
+
|
|
202
|
+
if (!status.ok()) {
|
|
203
|
+
FAISS_THROW_MSG(status.message());
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
size_t IndexSVSIVF::remove_ids(const IDSelector& sel) {
|
|
208
|
+
FAISS_THROW_IF_MSG(
|
|
209
|
+
is_static,
|
|
210
|
+
"Static IVF index does not support remove_ids(). "
|
|
211
|
+
"The index is immutable after creation.");
|
|
212
|
+
FAISS_THROW_IF_NOT(impl);
|
|
213
|
+
auto* dyn = dynamic_impl();
|
|
214
|
+
auto id_filter = FaissIDFilter{sel};
|
|
215
|
+
size_t removed = 0;
|
|
216
|
+
auto status = dyn->remove_selected(&removed, id_filter);
|
|
217
|
+
if (!status.ok()) {
|
|
218
|
+
FAISS_THROW_MSG(status.message());
|
|
219
|
+
}
|
|
220
|
+
ntotal -= removed;
|
|
221
|
+
return removed;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
void IndexSVSIVF::create_impl(idx_t n, const float* x) {
|
|
225
|
+
FAISS_THROW_IF_NOT(!impl);
|
|
226
|
+
ntotal = 0;
|
|
227
|
+
auto svs_metric = to_svs_metric(metric_type);
|
|
228
|
+
auto svs_storage_kind = to_svs_storage_kind(storage_kind);
|
|
229
|
+
auto build_params = svs_runtime::IVFIndex::BuildParams{
|
|
230
|
+
.num_centroids = num_centroids,
|
|
231
|
+
.minibatch_size = minibatch_size,
|
|
232
|
+
.num_iterations = num_iterations,
|
|
233
|
+
.is_hierarchical = is_hierarchical,
|
|
234
|
+
.training_fraction = training_fraction,
|
|
235
|
+
.hierarchical_level1_clusters = hierarchical_level1_clusters,
|
|
236
|
+
.seed = seed,
|
|
237
|
+
};
|
|
238
|
+
auto search_params = svs_runtime::IVFIndex::SearchParams{
|
|
239
|
+
.n_probes = n_probes,
|
|
240
|
+
.k_reorder = k_reorder,
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
svs_runtime::Status status;
|
|
244
|
+
if (is_static) {
|
|
245
|
+
status = svs_runtime::IVFIndex::build(
|
|
246
|
+
&impl,
|
|
247
|
+
d,
|
|
248
|
+
svs_metric,
|
|
249
|
+
svs_storage_kind,
|
|
250
|
+
static_cast<size_t>(n),
|
|
251
|
+
x,
|
|
252
|
+
build_params,
|
|
253
|
+
search_params,
|
|
254
|
+
num_threads,
|
|
255
|
+
intra_query_threads);
|
|
256
|
+
} else {
|
|
257
|
+
std::vector<size_t> labels(n);
|
|
258
|
+
std::iota(labels.begin(), labels.end(), 0);
|
|
259
|
+
|
|
260
|
+
svs_runtime::DynamicIVFIndex* dyn_impl = nullptr;
|
|
261
|
+
status = svs_runtime::DynamicIVFIndex::build(
|
|
262
|
+
&dyn_impl,
|
|
263
|
+
d,
|
|
264
|
+
svs_metric,
|
|
265
|
+
svs_storage_kind,
|
|
266
|
+
static_cast<size_t>(n),
|
|
267
|
+
x,
|
|
268
|
+
labels.data(),
|
|
269
|
+
build_params,
|
|
270
|
+
search_params,
|
|
271
|
+
num_threads,
|
|
272
|
+
intra_query_threads);
|
|
273
|
+
impl = dyn_impl;
|
|
274
|
+
}
|
|
275
|
+
if (!status.ok()) {
|
|
276
|
+
FAISS_THROW_MSG(status.message());
|
|
277
|
+
}
|
|
278
|
+
FAISS_THROW_IF_NOT(impl);
|
|
279
|
+
|
|
280
|
+
// Force reinitialization of SVS search infrastructure after build.
|
|
281
|
+
// Same workaround as in deserialize_impl — the move chain through
|
|
282
|
+
// the orchestrator wrappers can leave matmul_results_ inconsistent
|
|
283
|
+
// when threads > centroids.
|
|
284
|
+
size_t current_threads = 0;
|
|
285
|
+
impl->get_num_threads(¤t_threads);
|
|
286
|
+
auto st = impl->set_num_threads(current_threads);
|
|
287
|
+
if (!st.ok()) {
|
|
288
|
+
FAISS_THROW_MSG(st.message());
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
ntotal = n;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
void IndexSVSIVF::serialize_impl(std::ostream& out) const {
|
|
295
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
296
|
+
impl, "Cannot serialize: SVS IVF index not initialized.");
|
|
297
|
+
|
|
298
|
+
auto status = impl->save(out);
|
|
299
|
+
if (!status.ok()) {
|
|
300
|
+
FAISS_THROW_MSG(status.message());
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
void IndexSVSIVF::deserialize_impl(std::istream& in) {
|
|
305
|
+
FAISS_THROW_IF_MSG(
|
|
306
|
+
impl, "Cannot deserialize: SVS IVF index already loaded.");
|
|
307
|
+
auto svs_metric = to_svs_metric(metric_type);
|
|
308
|
+
auto svs_storage_kind = to_svs_storage_kind(storage_kind);
|
|
309
|
+
|
|
310
|
+
svs_runtime::Status status;
|
|
311
|
+
if (is_static) {
|
|
312
|
+
status = svs_runtime::IVFIndex::load(
|
|
313
|
+
&impl,
|
|
314
|
+
in,
|
|
315
|
+
svs_metric,
|
|
316
|
+
svs_storage_kind,
|
|
317
|
+
num_threads,
|
|
318
|
+
intra_query_threads);
|
|
319
|
+
} else {
|
|
320
|
+
svs_runtime::DynamicIVFIndex* dyn_impl = nullptr;
|
|
321
|
+
status = svs_runtime::DynamicIVFIndex::load(
|
|
322
|
+
&dyn_impl,
|
|
323
|
+
in,
|
|
324
|
+
svs_metric,
|
|
325
|
+
svs_storage_kind,
|
|
326
|
+
num_threads,
|
|
327
|
+
intra_query_threads);
|
|
328
|
+
impl = dyn_impl;
|
|
329
|
+
}
|
|
330
|
+
if (!status.ok()) {
|
|
331
|
+
FAISS_THROW_MSG(status.message());
|
|
332
|
+
}
|
|
333
|
+
FAISS_THROW_IF_NOT_MSG(impl, "SVS IVF load returned ok but impl is null");
|
|
334
|
+
|
|
335
|
+
size_t current_threads = 0;
|
|
336
|
+
impl->get_num_threads(¤t_threads);
|
|
337
|
+
auto st = impl->set_num_threads(current_threads);
|
|
338
|
+
if (!st.ok()) {
|
|
339
|
+
FAISS_THROW_MSG(st.message());
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
svs_runtime::DynamicIVFIndex* IndexSVSIVF::dynamic_impl() const {
|
|
344
|
+
FAISS_THROW_IF_MSG(
|
|
345
|
+
is_static, "Operation not supported on a static IVF index.");
|
|
346
|
+
FAISS_THROW_IF_NOT(impl);
|
|
347
|
+
return static_cast<svs_runtime::DynamicIVFIndex*>(impl);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
} // namespace faiss
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Portions Copyright 2026 Intel Corporation
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#pragma once
|
|
25
|
+
|
|
26
|
+
#include <faiss/Index.h>
|
|
27
|
+
#include <faiss/svs/IndexSVSFaissUtils.h>
|
|
28
|
+
#include <faiss/svs/IndexSVSVamana.h> // for SVSStorageKind, to_svs_storage_kind
|
|
29
|
+
|
|
30
|
+
#include <svs/runtime/api_defs.h>
|
|
31
|
+
#include <svs/runtime/dynamic_ivf_index.h>
|
|
32
|
+
#include <svs/runtime/ivf_index.h>
|
|
33
|
+
|
|
34
|
+
#include <iostream>
|
|
35
|
+
|
|
36
|
+
namespace faiss {
|
|
37
|
+
|
|
38
|
+
struct SearchParametersSVSIVF : public SearchParameters {
|
|
39
|
+
size_t n_probes = 0;
|
|
40
|
+
float k_reorder = 0;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
struct IndexSVSIVF : Index {
|
|
44
|
+
/// Number of centroids / clusters
|
|
45
|
+
size_t num_centroids = 1000;
|
|
46
|
+
/// Minibatch size for k-means clustering
|
|
47
|
+
size_t minibatch_size = 10000;
|
|
48
|
+
/// Number of iterations for k-means clustering
|
|
49
|
+
size_t num_iterations = 10;
|
|
50
|
+
/// Whether to use hierarchical clustering
|
|
51
|
+
bool is_hierarchical = true;
|
|
52
|
+
/// Fraction of data to use for training (0.0 to 1.0)
|
|
53
|
+
float training_fraction = 0.1f;
|
|
54
|
+
/// Number of level-1 clusters for hierarchical clustering
|
|
55
|
+
size_t hierarchical_level1_clusters = 0;
|
|
56
|
+
/// Random seed for clustering
|
|
57
|
+
size_t seed = 42;
|
|
58
|
+
|
|
59
|
+
/// Number of probes for search
|
|
60
|
+
size_t n_probes = 10;
|
|
61
|
+
/// Reranking multiplier for compressed datasets
|
|
62
|
+
float k_reorder = 1.0f;
|
|
63
|
+
|
|
64
|
+
/// Number of threads for inter-query parallelism (0 = use all available)
|
|
65
|
+
size_t num_threads = 0;
|
|
66
|
+
/// Number of threads for intra-query parallelism (cluster exploration).
|
|
67
|
+
/// NOTE: Must be set before train() or deserialize_impl(); changes after
|
|
68
|
+
/// index creation are not propagated to the SVS backend. This is a
|
|
69
|
+
/// limitation of the current SVS runtime API and will be fixed in a
|
|
70
|
+
/// future SVS version.
|
|
71
|
+
size_t intra_query_threads = 1;
|
|
72
|
+
|
|
73
|
+
/// Whether this is a static (immutable) IVF index
|
|
74
|
+
bool is_static = false;
|
|
75
|
+
|
|
76
|
+
SVSStorageKind storage_kind = SVSStorageKind::SVS_FP32;
|
|
77
|
+
|
|
78
|
+
IndexSVSIVF();
|
|
79
|
+
|
|
80
|
+
IndexSVSIVF(
|
|
81
|
+
idx_t d,
|
|
82
|
+
size_t nlist,
|
|
83
|
+
MetricType metric = METRIC_L2,
|
|
84
|
+
SVSStorageKind storage = SVSStorageKind::SVS_FP32,
|
|
85
|
+
bool is_static = false);
|
|
86
|
+
|
|
87
|
+
~IndexSVSIVF() override;
|
|
88
|
+
|
|
89
|
+
IndexSVSIVF(const IndexSVSIVF&) = delete;
|
|
90
|
+
IndexSVSIVF& operator=(const IndexSVSIVF&) = delete;
|
|
91
|
+
|
|
92
|
+
// static member that exposes whether or not LVQ/LeanVec are enabled for
|
|
93
|
+
// this build and runtime.
|
|
94
|
+
static bool is_lvq_leanvec_enabled();
|
|
95
|
+
|
|
96
|
+
void train(idx_t n, const float* x) override;
|
|
97
|
+
|
|
98
|
+
void add(idx_t n, const float* x) override;
|
|
99
|
+
|
|
100
|
+
void search(
|
|
101
|
+
idx_t n,
|
|
102
|
+
const float* x,
|
|
103
|
+
idx_t k,
|
|
104
|
+
float* distances,
|
|
105
|
+
idx_t* labels,
|
|
106
|
+
const SearchParameters* params = nullptr) const override;
|
|
107
|
+
|
|
108
|
+
size_t remove_ids(const IDSelector& sel) override;
|
|
109
|
+
|
|
110
|
+
void reset() override;
|
|
111
|
+
|
|
112
|
+
/* Serialization and deserialization helpers */
|
|
113
|
+
void serialize_impl(std::ostream& out) const;
|
|
114
|
+
virtual void deserialize_impl(std::istream& in);
|
|
115
|
+
|
|
116
|
+
/* The actual SVS implementation (IVFIndex is the base for both
|
|
117
|
+
static and dynamic variants) */
|
|
118
|
+
svs_runtime::IVFIndex* impl{nullptr};
|
|
119
|
+
|
|
120
|
+
protected:
|
|
121
|
+
/* Initializes the implementation from training data */
|
|
122
|
+
virtual void create_impl(idx_t n, const float* x);
|
|
123
|
+
|
|
124
|
+
/* Returns the dynamic impl pointer, throwing if static */
|
|
125
|
+
svs_runtime::DynamicIVFIndex* dynamic_impl() const;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
} // namespace faiss
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Portions Copyright 2026 Intel Corporation
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#include <faiss/svs/IndexSVSIVFLVQ.h>
|
|
25
|
+
|
|
26
|
+
namespace faiss {
|
|
27
|
+
|
|
28
|
+
IndexSVSIVFLVQ::IndexSVSIVFLVQ() : IndexSVSIVF() {
|
|
29
|
+
storage_kind = SVSStorageKind::SVS_LVQ4x0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
IndexSVSIVFLVQ::IndexSVSIVFLVQ(
|
|
33
|
+
idx_t d,
|
|
34
|
+
size_t nlist,
|
|
35
|
+
MetricType metric,
|
|
36
|
+
SVSStorageKind storage,
|
|
37
|
+
bool is_static)
|
|
38
|
+
: IndexSVSIVF(d, nlist, metric, storage, is_static) {}
|
|
39
|
+
|
|
40
|
+
} // namespace faiss
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Portions Copyright 2026 Intel Corporation
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#pragma once
|
|
25
|
+
|
|
26
|
+
#include <faiss/svs/IndexSVSIVF.h>
|
|
27
|
+
|
|
28
|
+
namespace faiss {
|
|
29
|
+
|
|
30
|
+
struct IndexSVSIVFLVQ : IndexSVSIVF {
|
|
31
|
+
IndexSVSIVFLVQ();
|
|
32
|
+
|
|
33
|
+
IndexSVSIVFLVQ(
|
|
34
|
+
idx_t d,
|
|
35
|
+
size_t nlist,
|
|
36
|
+
MetricType metric = METRIC_L2,
|
|
37
|
+
SVSStorageKind storage = SVSStorageKind::SVS_LVQ4x0,
|
|
38
|
+
bool is_static = false);
|
|
39
|
+
|
|
40
|
+
~IndexSVSIVFLVQ() override = default;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
} // namespace faiss
|