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
|
@@ -0,0 +1,225 @@
|
|
|
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/IndexSVSIVFLeanVec.h>
|
|
26
|
+
|
|
27
|
+
#include <svs/runtime/dynamic_ivf_index.h>
|
|
28
|
+
#include <svs/runtime/ivf_index.h>
|
|
29
|
+
#include <svs/runtime/training.h>
|
|
30
|
+
|
|
31
|
+
#include <memory>
|
|
32
|
+
#include <numeric>
|
|
33
|
+
|
|
34
|
+
namespace faiss {
|
|
35
|
+
|
|
36
|
+
IndexSVSIVFLeanVec::IndexSVSIVFLeanVec() : IndexSVSIVF() {
|
|
37
|
+
is_trained = false;
|
|
38
|
+
storage_kind = SVSStorageKind::SVS_LeanVec4x4;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
IndexSVSIVFLeanVec::IndexSVSIVFLeanVec(
|
|
42
|
+
idx_t d,
|
|
43
|
+
size_t nlist,
|
|
44
|
+
MetricType metric,
|
|
45
|
+
size_t leanvec_dims,
|
|
46
|
+
SVSStorageKind storage_kind,
|
|
47
|
+
bool is_static)
|
|
48
|
+
: IndexSVSIVF(d, nlist, metric, storage_kind, is_static) {
|
|
49
|
+
is_trained = false;
|
|
50
|
+
leanvec_d = leanvec_dims == 0 ? d / 2 : leanvec_dims;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
IndexSVSIVFLeanVec::~IndexSVSIVFLeanVec() {
|
|
54
|
+
if (training_data) {
|
|
55
|
+
auto status = svs_runtime::LeanVecTrainingData::destroy(training_data);
|
|
56
|
+
FAISS_ASSERT(status.ok());
|
|
57
|
+
training_data = nullptr;
|
|
58
|
+
}
|
|
59
|
+
// Base class destructor handles impl cleanup
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
void IndexSVSIVFLeanVec::train(idx_t n, const float* x) {
|
|
63
|
+
train_with_queries(n, x, 0, nullptr);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
void IndexSVSIVFLeanVec::train_with_queries(
|
|
67
|
+
idx_t n,
|
|
68
|
+
const float* x,
|
|
69
|
+
idx_t n_train_q,
|
|
70
|
+
const float* xq_train) {
|
|
71
|
+
FAISS_THROW_IF_MSG(
|
|
72
|
+
training_data || impl, "Index already trained or contains data.");
|
|
73
|
+
|
|
74
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
75
|
+
IndexSVSIVF::is_lvq_leanvec_enabled(),
|
|
76
|
+
"LVQ/LeanVec support not available on this platform or build");
|
|
77
|
+
|
|
78
|
+
// Build LeanVec training data
|
|
79
|
+
auto status = svs_runtime::LeanVecTrainingData::build(
|
|
80
|
+
&training_data, d, n, x, n_train_q, xq_train, leanvec_d);
|
|
81
|
+
if (!status.ok()) {
|
|
82
|
+
FAISS_THROW_MSG(status.message());
|
|
83
|
+
}
|
|
84
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
85
|
+
training_data, "Failed to build leanvec training info.");
|
|
86
|
+
|
|
87
|
+
// Now build the IVF index with the training data
|
|
88
|
+
create_impl(n, x);
|
|
89
|
+
is_trained = true;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
void IndexSVSIVFLeanVec::reset() {
|
|
93
|
+
if (training_data) {
|
|
94
|
+
auto status = svs_runtime::LeanVecTrainingData::destroy(training_data);
|
|
95
|
+
FAISS_ASSERT(status.ok());
|
|
96
|
+
training_data = nullptr;
|
|
97
|
+
}
|
|
98
|
+
IndexSVSIVF::reset();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
void IndexSVSIVFLeanVec::serialize_training_data(std::ostream& out) const {
|
|
102
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
103
|
+
training_data, "Cannot serialize: Training data not initialized.");
|
|
104
|
+
|
|
105
|
+
auto status = training_data->save(out);
|
|
106
|
+
if (!status.ok()) {
|
|
107
|
+
FAISS_THROW_MSG(status.message());
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
void IndexSVSIVFLeanVec::deserialize_training_data(std::istream& in) {
|
|
112
|
+
svs_runtime::LeanVecTrainingData* tdata = nullptr;
|
|
113
|
+
auto status = svs_runtime::LeanVecTrainingData::load(&tdata, in);
|
|
114
|
+
if (!status.ok()) {
|
|
115
|
+
FAISS_THROW_MSG(status.message());
|
|
116
|
+
}
|
|
117
|
+
FAISS_THROW_IF_NOT_MSG(tdata, "Failed to load leanvec training data.");
|
|
118
|
+
training_data = tdata;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
void IndexSVSIVFLeanVec::create_impl(idx_t n, const float* x) {
|
|
122
|
+
FAISS_THROW_IF_NOT(!impl);
|
|
123
|
+
ntotal = 0;
|
|
124
|
+
auto svs_metric = to_svs_metric(metric_type);
|
|
125
|
+
auto svs_storage_kind = to_svs_storage_kind(storage_kind);
|
|
126
|
+
auto build_params = svs_runtime::IVFIndex::BuildParams{
|
|
127
|
+
.num_centroids = num_centroids,
|
|
128
|
+
.minibatch_size = minibatch_size,
|
|
129
|
+
.num_iterations = num_iterations,
|
|
130
|
+
.is_hierarchical = is_hierarchical,
|
|
131
|
+
.training_fraction = training_fraction,
|
|
132
|
+
.hierarchical_level1_clusters = hierarchical_level1_clusters,
|
|
133
|
+
.seed = seed,
|
|
134
|
+
};
|
|
135
|
+
auto search_params = svs_runtime::IVFIndex::SearchParams{
|
|
136
|
+
.n_probes = n_probes,
|
|
137
|
+
.k_reorder = k_reorder,
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
auto status = svs_runtime::Status_Ok;
|
|
141
|
+
if (is_static) {
|
|
142
|
+
if (training_data) {
|
|
143
|
+
status = svs_runtime::IVFIndexLeanVec::build(
|
|
144
|
+
&impl,
|
|
145
|
+
d,
|
|
146
|
+
svs_metric,
|
|
147
|
+
svs_storage_kind,
|
|
148
|
+
static_cast<size_t>(n),
|
|
149
|
+
x,
|
|
150
|
+
training_data,
|
|
151
|
+
build_params,
|
|
152
|
+
search_params,
|
|
153
|
+
num_threads,
|
|
154
|
+
intra_query_threads);
|
|
155
|
+
} else {
|
|
156
|
+
status = svs_runtime::IVFIndexLeanVec::build(
|
|
157
|
+
&impl,
|
|
158
|
+
d,
|
|
159
|
+
svs_metric,
|
|
160
|
+
svs_storage_kind,
|
|
161
|
+
static_cast<size_t>(n),
|
|
162
|
+
x,
|
|
163
|
+
leanvec_d,
|
|
164
|
+
build_params,
|
|
165
|
+
search_params,
|
|
166
|
+
num_threads,
|
|
167
|
+
intra_query_threads);
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
std::vector<size_t> labels(n);
|
|
171
|
+
std::iota(labels.begin(), labels.end(), 0);
|
|
172
|
+
|
|
173
|
+
svs_runtime::DynamicIVFIndex* dyn_impl = nullptr;
|
|
174
|
+
if (training_data) {
|
|
175
|
+
status = svs_runtime::DynamicIVFIndexLeanVec::build(
|
|
176
|
+
&dyn_impl,
|
|
177
|
+
d,
|
|
178
|
+
svs_metric,
|
|
179
|
+
svs_storage_kind,
|
|
180
|
+
static_cast<size_t>(n),
|
|
181
|
+
x,
|
|
182
|
+
labels.data(),
|
|
183
|
+
training_data,
|
|
184
|
+
build_params,
|
|
185
|
+
search_params,
|
|
186
|
+
num_threads,
|
|
187
|
+
intra_query_threads);
|
|
188
|
+
} else {
|
|
189
|
+
status = svs_runtime::DynamicIVFIndexLeanVec::build(
|
|
190
|
+
&dyn_impl,
|
|
191
|
+
d,
|
|
192
|
+
svs_metric,
|
|
193
|
+
svs_storage_kind,
|
|
194
|
+
static_cast<size_t>(n),
|
|
195
|
+
x,
|
|
196
|
+
labels.data(),
|
|
197
|
+
leanvec_d,
|
|
198
|
+
build_params,
|
|
199
|
+
search_params,
|
|
200
|
+
num_threads,
|
|
201
|
+
intra_query_threads);
|
|
202
|
+
}
|
|
203
|
+
impl = dyn_impl;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (!status.ok()) {
|
|
207
|
+
FAISS_THROW_MSG(status.message());
|
|
208
|
+
}
|
|
209
|
+
FAISS_THROW_IF_NOT(impl);
|
|
210
|
+
|
|
211
|
+
// Force reinitialization of SVS search infrastructure after build.
|
|
212
|
+
// Same workaround as in IndexSVSIVF::create_impl — the move chain through
|
|
213
|
+
// the orchestrator wrappers can leave matmul_results_ inconsistent
|
|
214
|
+
// when threads > centroids.
|
|
215
|
+
size_t current_threads = 0;
|
|
216
|
+
impl->get_num_threads(¤t_threads);
|
|
217
|
+
auto st = impl->set_num_threads(current_threads);
|
|
218
|
+
if (!st.ok()) {
|
|
219
|
+
FAISS_THROW_MSG(st.message());
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
ntotal = n;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
} // namespace faiss
|
|
@@ -0,0 +1,71 @@
|
|
|
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 IndexSVSIVFLeanVec : IndexSVSIVF {
|
|
31
|
+
IndexSVSIVFLeanVec();
|
|
32
|
+
|
|
33
|
+
IndexSVSIVFLeanVec(
|
|
34
|
+
idx_t d,
|
|
35
|
+
size_t nlist,
|
|
36
|
+
MetricType metric = METRIC_L2,
|
|
37
|
+
size_t leanvec_dims = 0,
|
|
38
|
+
SVSStorageKind storage = SVSStorageKind::SVS_LeanVec4x4,
|
|
39
|
+
bool is_static = false);
|
|
40
|
+
|
|
41
|
+
~IndexSVSIVFLeanVec() override;
|
|
42
|
+
|
|
43
|
+
/* Default train assumes in-distribution data */
|
|
44
|
+
void train(idx_t n, const float* x) override;
|
|
45
|
+
|
|
46
|
+
/* Generic train with out-of-distribution parameters.
|
|
47
|
+
* Out-of-distribution (OOD) means database vectors and queries _can_ be
|
|
48
|
+
* sampled from different distributions (e.g., cross-modal). More details in
|
|
49
|
+
* the original publication, arXiv:2312.16335.
|
|
50
|
+
*/
|
|
51
|
+
void train_with_queries(
|
|
52
|
+
idx_t n,
|
|
53
|
+
const float* x,
|
|
54
|
+
idx_t n_train_q,
|
|
55
|
+
const float* xq_train) override;
|
|
56
|
+
|
|
57
|
+
void reset() override;
|
|
58
|
+
|
|
59
|
+
void serialize_training_data(std::ostream& out) const;
|
|
60
|
+
void deserialize_training_data(std::istream& in);
|
|
61
|
+
|
|
62
|
+
size_t leanvec_d = 0;
|
|
63
|
+
|
|
64
|
+
/* Training information */
|
|
65
|
+
svs_runtime::LeanVecTrainingData* training_data{nullptr};
|
|
66
|
+
|
|
67
|
+
protected:
|
|
68
|
+
void create_impl(idx_t n, const float* x) override;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
} // namespace faiss
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
#include <svs/runtime/vamana_index.h>
|
|
32
32
|
|
|
33
33
|
#include <cstddef>
|
|
34
|
+
#include <cstring>
|
|
34
35
|
#include <numeric>
|
|
35
36
|
#include <span>
|
|
36
37
|
#include <type_traits>
|
|
@@ -114,13 +115,32 @@ void IndexSVSVamana::add(idx_t n, const float* x) {
|
|
|
114
115
|
if (!status.ok()) {
|
|
115
116
|
FAISS_THROW_MSG(status.message());
|
|
116
117
|
}
|
|
118
|
+
|
|
119
|
+
if (stored_vectors_valid) {
|
|
120
|
+
size_t prev = static_cast<size_t>(ntotal) * d;
|
|
121
|
+
stored_vectors.resize(prev + static_cast<size_t>(n) * d);
|
|
122
|
+
std::memcpy(stored_vectors.data() + prev, x, sizeof(float) * n * d);
|
|
123
|
+
}
|
|
117
124
|
ntotal += n;
|
|
118
125
|
}
|
|
119
126
|
|
|
127
|
+
void IndexSVSVamana::reconstruct(idx_t key, float* recons) const {
|
|
128
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
129
|
+
key >= 0 && key < ntotal,
|
|
130
|
+
"IndexSVSVamana::reconstruct: key out of range");
|
|
131
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
132
|
+
stored_vectors_valid && !stored_vectors.empty(),
|
|
133
|
+
"IndexSVSVamana::reconstruct: stored_vectors unavailable "
|
|
134
|
+
"(invalidated by remove_ids or not restored after deserialization)");
|
|
135
|
+
std::memcpy(recons, stored_vectors.data() + key * d, sizeof(float) * d);
|
|
136
|
+
}
|
|
137
|
+
|
|
120
138
|
void IndexSVSVamana::reset() {
|
|
121
139
|
if (impl) {
|
|
122
140
|
impl->reset();
|
|
123
141
|
}
|
|
142
|
+
stored_vectors.clear();
|
|
143
|
+
stored_vectors_valid = true;
|
|
124
144
|
is_trained = false;
|
|
125
145
|
ntotal = 0;
|
|
126
146
|
}
|
|
@@ -189,6 +209,8 @@ size_t IndexSVSVamana::remove_ids(const IDSelector& sel) {
|
|
|
189
209
|
size_t removed = 0;
|
|
190
210
|
auto Status = impl->remove_selected(&removed, id_filter);
|
|
191
211
|
ntotal -= removed;
|
|
212
|
+
stored_vectors.clear();
|
|
213
|
+
stored_vectors_valid = false;
|
|
192
214
|
return removed;
|
|
193
215
|
}
|
|
194
216
|
|
|
@@ -236,10 +258,12 @@ void IndexSVSVamana::deserialize_impl(std::istream& in) {
|
|
|
236
258
|
FAISS_THROW_IF_MSG(impl, "Cannot deserialize: SVS index already loaded.");
|
|
237
259
|
auto svs_metric = to_svs_metric(metric_type);
|
|
238
260
|
auto svs_storage_kind = to_svs_storage_kind(storage_kind);
|
|
239
|
-
auto status =
|
|
261
|
+
auto status = svs_runtime::DynamicVamanaIndex::load(
|
|
262
|
+
&impl, in, svs_metric, svs_storage_kind);
|
|
240
263
|
if (!status.ok()) {
|
|
241
264
|
FAISS_THROW_MSG(status.message());
|
|
242
265
|
}
|
|
266
|
+
FAISS_THROW_IF_NOT_MSG(impl, "Failed to load SVS Vamana index.");
|
|
243
267
|
}
|
|
244
268
|
|
|
245
269
|
} // namespace faiss
|
|
@@ -27,8 +27,11 @@
|
|
|
27
27
|
#include <faiss/svs/IndexSVSFaissUtils.h>
|
|
28
28
|
|
|
29
29
|
#include <svs/runtime/api_defs.h>
|
|
30
|
+
#include <svs/runtime/dynamic_vamana_index.h>
|
|
30
31
|
|
|
31
32
|
#include <iostream>
|
|
33
|
+
#include <type_traits>
|
|
34
|
+
#include <vector>
|
|
32
35
|
|
|
33
36
|
namespace faiss {
|
|
34
37
|
|
|
@@ -45,9 +48,11 @@ enum SVSStorageKind {
|
|
|
45
48
|
SVS_LVQ4x0,
|
|
46
49
|
SVS_LVQ4x4,
|
|
47
50
|
SVS_LVQ4x8,
|
|
51
|
+
SVS_LVQ8x0,
|
|
48
52
|
SVS_LeanVec4x4,
|
|
49
53
|
SVS_LeanVec4x8,
|
|
50
54
|
SVS_LeanVec8x8,
|
|
55
|
+
SVS_count,
|
|
51
56
|
};
|
|
52
57
|
|
|
53
58
|
inline svs_runtime::StorageKind to_svs_storage_kind(SVSStorageKind kind) {
|
|
@@ -64,6 +69,8 @@ inline svs_runtime::StorageKind to_svs_storage_kind(SVSStorageKind kind) {
|
|
|
64
69
|
return svs_runtime::StorageKind::LVQ4x4;
|
|
65
70
|
case SVS_LVQ4x8:
|
|
66
71
|
return svs_runtime::StorageKind::LVQ4x8;
|
|
72
|
+
case SVS_LVQ8x0:
|
|
73
|
+
return svs_runtime::StorageKind::LVQ8x0;
|
|
67
74
|
case SVS_LeanVec4x4:
|
|
68
75
|
return svs_runtime::StorageKind::LeanVec4x4;
|
|
69
76
|
case SVS_LeanVec4x8:
|
|
@@ -71,7 +78,9 @@ inline svs_runtime::StorageKind to_svs_storage_kind(SVSStorageKind kind) {
|
|
|
71
78
|
case SVS_LeanVec8x8:
|
|
72
79
|
return svs_runtime::StorageKind::LeanVec8x8;
|
|
73
80
|
default:
|
|
74
|
-
|
|
81
|
+
FAISS_THROW_FMT(
|
|
82
|
+
"SVSStorageKind (%d) not supported",
|
|
83
|
+
static_cast<std::underlying_type_t<SVSStorageKind>>(kind));
|
|
75
84
|
}
|
|
76
85
|
}
|
|
77
86
|
|
|
@@ -85,7 +94,7 @@ struct IndexSVSVamana : Index {
|
|
|
85
94
|
size_t max_candidate_pool_size = 200;
|
|
86
95
|
bool use_full_search_history = true;
|
|
87
96
|
|
|
88
|
-
SVSStorageKind storage_kind;
|
|
97
|
+
SVSStorageKind storage_kind = SVS_FP32;
|
|
89
98
|
|
|
90
99
|
IndexSVSVamana();
|
|
91
100
|
|
|
@@ -103,6 +112,8 @@ struct IndexSVSVamana : Index {
|
|
|
103
112
|
|
|
104
113
|
void add(idx_t n, const float* x) override;
|
|
105
114
|
|
|
115
|
+
void reconstruct(idx_t key, float* recons) const override;
|
|
116
|
+
|
|
106
117
|
void search(
|
|
107
118
|
idx_t n,
|
|
108
119
|
const float* x,
|
|
@@ -129,6 +140,12 @@ struct IndexSVSVamana : Index {
|
|
|
129
140
|
/* The actual SVS implementation */
|
|
130
141
|
svs_runtime::DynamicVamanaIndex* impl{nullptr};
|
|
131
142
|
|
|
143
|
+
// The SVS runtime API does not expose vector retrieval, so we keep a copy
|
|
144
|
+
// of added vectors to support reconstruct(). When used as a coarse
|
|
145
|
+
// quantizer this holds only nlist centroids.
|
|
146
|
+
std::vector<float> stored_vectors;
|
|
147
|
+
bool stored_vectors_valid{true};
|
|
148
|
+
|
|
132
149
|
protected:
|
|
133
150
|
/* Initializes the implementation*/
|
|
134
151
|
virtual void create_impl();
|
|
@@ -34,7 +34,7 @@ struct IndexSVSVamanaLVQ : IndexSVSVamana {
|
|
|
34
34
|
idx_t d,
|
|
35
35
|
size_t degree,
|
|
36
36
|
MetricType metric = METRIC_L2,
|
|
37
|
-
SVSStorageKind storage = SVSStorageKind::
|
|
37
|
+
SVSStorageKind storage = SVSStorageKind::SVS_LVQ4x0);
|
|
38
38
|
|
|
39
39
|
~IndexSVSVamanaLVQ() override = default;
|
|
40
40
|
};
|
|
@@ -56,7 +56,7 @@ IndexSVSVamanaLeanVec::~IndexSVSVamanaLeanVec() {
|
|
|
56
56
|
FAISS_ASSERT(status.ok());
|
|
57
57
|
training_data = nullptr;
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
// Base class destructor handles impl cleanup
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
void IndexSVSVamanaLeanVec::add(idx_t n, const float* x) {
|
|
@@ -66,6 +66,14 @@ void IndexSVSVamanaLeanVec::add(idx_t n, const float* x) {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
void IndexSVSVamanaLeanVec::train(idx_t n, const float* x) {
|
|
69
|
+
train_with_queries(n, x, 0, nullptr);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
void IndexSVSVamanaLeanVec::train_with_queries(
|
|
73
|
+
idx_t n,
|
|
74
|
+
const float* x,
|
|
75
|
+
idx_t n_train_q,
|
|
76
|
+
const float* queries) {
|
|
69
77
|
FAISS_THROW_IF_MSG(
|
|
70
78
|
training_data || impl, "Index already trained or contains data.");
|
|
71
79
|
|
|
@@ -74,7 +82,7 @@ void IndexSVSVamanaLeanVec::train(idx_t n, const float* x) {
|
|
|
74
82
|
"LVQ/LeanVec support not available on this platform or build");
|
|
75
83
|
|
|
76
84
|
auto status = svs_runtime::LeanVecTrainingData::build(
|
|
77
|
-
&training_data, d, n, x, leanvec_d);
|
|
85
|
+
&training_data, d, n, x, n_train_q, queries, leanvec_d);
|
|
78
86
|
if (!status.ok()) {
|
|
79
87
|
FAISS_THROW_MSG(status.message());
|
|
80
88
|
}
|
|
@@ -83,6 +91,15 @@ void IndexSVSVamanaLeanVec::train(idx_t n, const float* x) {
|
|
|
83
91
|
is_trained = true;
|
|
84
92
|
}
|
|
85
93
|
|
|
94
|
+
void IndexSVSVamanaLeanVec::reset() {
|
|
95
|
+
if (training_data) {
|
|
96
|
+
auto status = svs_runtime::LeanVecTrainingData::destroy(training_data);
|
|
97
|
+
FAISS_ASSERT(status.ok());
|
|
98
|
+
training_data = nullptr;
|
|
99
|
+
}
|
|
100
|
+
IndexSVSVamana::reset();
|
|
101
|
+
}
|
|
102
|
+
|
|
86
103
|
void IndexSVSVamanaLeanVec::serialize_training_data(std::ostream& out) const {
|
|
87
104
|
FAISS_THROW_IF_NOT_MSG(
|
|
88
105
|
training_data, "Cannot serialize: Training data not initialized.");
|
|
@@ -41,8 +41,22 @@ struct IndexSVSVamanaLeanVec : IndexSVSVamana {
|
|
|
41
41
|
|
|
42
42
|
void add(idx_t n, const float* x) override;
|
|
43
43
|
|
|
44
|
+
/* Default train assumes in-distribution data */
|
|
44
45
|
void train(idx_t n, const float* x) override;
|
|
45
46
|
|
|
47
|
+
/* Generic train with out-of-distribution parameters.
|
|
48
|
+
* Out-of-distribution (OOD) means database vectors and queries _can_ be
|
|
49
|
+
* sampled from different distributions (e.g., cross-modal). More details in
|
|
50
|
+
* the original publication, arXiv:2312.16335.
|
|
51
|
+
*/
|
|
52
|
+
void train_with_queries(
|
|
53
|
+
idx_t n,
|
|
54
|
+
const float* x,
|
|
55
|
+
idx_t n_train_q,
|
|
56
|
+
const float* xq_train) override;
|
|
57
|
+
|
|
58
|
+
void reset() override;
|
|
59
|
+
|
|
46
60
|
void serialize_training_data(std::ostream& out) const;
|
|
47
61
|
void deserialize_training_data(std::istream& in);
|
|
48
62
|
|
|
@@ -17,7 +17,7 @@ namespace faiss {
|
|
|
17
17
|
template <typename C>
|
|
18
18
|
void HeapArray<C>::heapify() {
|
|
19
19
|
#pragma omp parallel for
|
|
20
|
-
for (int64_t j = 0; j < nh; j++) {
|
|
20
|
+
for (int64_t j = 0; j < static_cast<int64_t>(nh); j++) {
|
|
21
21
|
heap_heapify<C>(k, val + j * k, ids + j * k);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -25,7 +25,7 @@ void HeapArray<C>::heapify() {
|
|
|
25
25
|
template <typename C>
|
|
26
26
|
void HeapArray<C>::reorder() {
|
|
27
27
|
#pragma omp parallel for
|
|
28
|
-
for (int64_t j = 0; j < nh; j++) {
|
|
28
|
+
for (int64_t j = 0; j < static_cast<int64_t>(nh); j++) {
|
|
29
29
|
heap_reorder<C>(k, val + j * k, ids + j * k);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -37,7 +37,7 @@ void HeapArray<C>::addn(size_t nj, const T* vin, TI j0, size_t i0, int64_t ni) {
|
|
|
37
37
|
}
|
|
38
38
|
assert(i0 >= 0 && i0 + ni <= nh);
|
|
39
39
|
#pragma omp parallel for if (ni * nj > 100000)
|
|
40
|
-
for (int64_t i = i0; i < i0 + ni; i++) {
|
|
40
|
+
for (int64_t i = i0; i < static_cast<int64_t>(i0) + ni; i++) {
|
|
41
41
|
T* __restrict simi = get_val(i);
|
|
42
42
|
TI* __restrict idxi = get_ids(i);
|
|
43
43
|
const T* ip_line = vin + (i - i0) * nj;
|
|
@@ -68,7 +68,7 @@ void HeapArray<C>::addn_with_ids(
|
|
|
68
68
|
}
|
|
69
69
|
assert(i0 >= 0 && i0 + ni <= nh);
|
|
70
70
|
#pragma omp parallel for if (ni * nj > 100000)
|
|
71
|
-
for (int64_t i = i0; i < i0 + ni; i++) {
|
|
71
|
+
for (int64_t i = i0; i < static_cast<int64_t>(i0) + ni; i++) {
|
|
72
72
|
T* __restrict simi = get_val(i);
|
|
73
73
|
TI* __restrict idxi = get_ids(i);
|
|
74
74
|
const T* ip_line = vin + (i - i0) * nj;
|
|
@@ -96,7 +96,7 @@ void HeapArray<C>::addn_query_subset_with_ids(
|
|
|
96
96
|
id_stride = nj;
|
|
97
97
|
}
|
|
98
98
|
#pragma omp parallel for if (nsubset * nj > 100000)
|
|
99
|
-
for (int64_t si = 0; si < nsubset; si++) {
|
|
99
|
+
for (int64_t si = 0; si < static_cast<int64_t>(nsubset); si++) {
|
|
100
100
|
TI i = subset[si];
|
|
101
101
|
T* __restrict simi = get_val(i);
|
|
102
102
|
TI* __restrict idxi = get_ids(i);
|
|
@@ -115,7 +115,7 @@ void HeapArray<C>::addn_query_subset_with_ids(
|
|
|
115
115
|
template <typename C>
|
|
116
116
|
void HeapArray<C>::per_line_extrema(T* out_val, TI* out_ids) const {
|
|
117
117
|
#pragma omp parallel for if (nh * k > 100000)
|
|
118
|
-
for (int64_t j = 0; j < nh; j++) {
|
|
118
|
+
for (int64_t j = 0; j < static_cast<int64_t>(nh); j++) {
|
|
119
119
|
int64_t imin = -1;
|
|
120
120
|
typename C::T xval = C::Crev::neutral();
|
|
121
121
|
const typename C::T* x_ = val + j * k;
|
|
@@ -187,7 +187,7 @@ void merge_knn_results(
|
|
|
187
187
|
std::vector<distance_t> buf2(nshard);
|
|
188
188
|
distance_t* heap_vals = buf2.data();
|
|
189
189
|
#pragma omp for
|
|
190
|
-
for (long i = 0; i < n; i++) {
|
|
190
|
+
for (long i = 0; i < static_cast<long>(n); i++) {
|
|
191
191
|
// the heap maps values to the shard where they are
|
|
192
192
|
// produced.
|
|
193
193
|
const distance_t* D_in = all_distances + i * k;
|
|
@@ -195,7 +195,7 @@ void merge_knn_results(
|
|
|
195
195
|
int heap_size = 0;
|
|
196
196
|
|
|
197
197
|
// push the first element of each shard (if not -1)
|
|
198
|
-
for (long s = 0; s < nshard; s++) {
|
|
198
|
+
for (long s = 0; s < static_cast<long>(nshard); s++) {
|
|
199
199
|
pointer[s] = 0;
|
|
200
200
|
if (I_in[stride * s] >= 0) {
|
|
201
201
|
heap_push<C>(
|
|
@@ -210,7 +210,7 @@ void merge_knn_results(
|
|
|
210
210
|
distance_t* D = distances + i * k;
|
|
211
211
|
idx_t* I = labels + i * k;
|
|
212
212
|
|
|
213
|
-
|
|
213
|
+
size_t j;
|
|
214
214
|
for (j = 0; j < k && heap_size > 0; j++) {
|
|
215
215
|
// pop element from best shard
|
|
216
216
|
int s = shard_ids[0]; // top of heap
|
|
@@ -221,7 +221,7 @@ void merge_knn_results(
|
|
|
221
221
|
// pop from shard, advance pointer for this shard
|
|
222
222
|
heap_pop<C>(heap_size--, heap_vals, shard_ids);
|
|
223
223
|
p++;
|
|
224
|
-
if (p < k && I_in[stride * s + p] >= 0) {
|
|
224
|
+
if (static_cast<size_t>(p) < k && I_in[stride * s + p] >= 0) {
|
|
225
225
|
heap_push<C>(
|
|
226
226
|
++heap_size,
|
|
227
227
|
heap_vals,
|
|
@@ -254,4 +254,50 @@ INSTANTIATE(CMax, float);
|
|
|
254
254
|
INSTANTIATE(CMin, int32_t);
|
|
255
255
|
INSTANTIATE(CMax, int32_t);
|
|
256
256
|
|
|
257
|
+
/**********************************************************
|
|
258
|
+
* reorder_2_heaps
|
|
259
|
+
**********************************************************/
|
|
260
|
+
|
|
261
|
+
template <class C>
|
|
262
|
+
void reorder_2_heaps(
|
|
263
|
+
int64_t n,
|
|
264
|
+
int64_t k,
|
|
265
|
+
typename C::TI* __restrict labels,
|
|
266
|
+
float* __restrict distances,
|
|
267
|
+
int64_t k_base,
|
|
268
|
+
const typename C::TI* __restrict base_labels,
|
|
269
|
+
const float* __restrict base_distances) {
|
|
270
|
+
#pragma omp parallel for if (n > 1)
|
|
271
|
+
for (int64_t i = 0; i < n; i++) {
|
|
272
|
+
typename C::TI* idxo = labels + i * k;
|
|
273
|
+
float* diso = distances + i * k;
|
|
274
|
+
const typename C::TI* idxi = base_labels + i * k_base;
|
|
275
|
+
const float* disi = base_distances + i * k_base;
|
|
276
|
+
|
|
277
|
+
heap_heapify<C>(k, diso, idxo, disi, idxi, k);
|
|
278
|
+
if (k_base != k) { // add remaining elements
|
|
279
|
+
heap_addn<C>(k, diso, idxo, disi + k, idxi + k, k_base - k);
|
|
280
|
+
}
|
|
281
|
+
heap_reorder<C>(k, diso, idxo);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
template void reorder_2_heaps<CMax<float, int64_t>>(
|
|
286
|
+
int64_t n,
|
|
287
|
+
int64_t k,
|
|
288
|
+
int64_t* __restrict labels,
|
|
289
|
+
float* __restrict distances,
|
|
290
|
+
int64_t k_base,
|
|
291
|
+
const int64_t* __restrict base_labels,
|
|
292
|
+
const float* __restrict base_distances);
|
|
293
|
+
|
|
294
|
+
template void reorder_2_heaps<CMin<float, int64_t>>(
|
|
295
|
+
int64_t n,
|
|
296
|
+
int64_t k,
|
|
297
|
+
int64_t* __restrict labels,
|
|
298
|
+
float* __restrict distances,
|
|
299
|
+
int64_t k_base,
|
|
300
|
+
const int64_t* __restrict base_labels,
|
|
301
|
+
const float* __restrict base_distances);
|
|
302
|
+
|
|
257
303
|
} // namespace faiss
|
|
@@ -642,6 +642,27 @@ void merge_knn_results(
|
|
|
642
642
|
typename C::T* distances,
|
|
643
643
|
idx_t* labels);
|
|
644
644
|
|
|
645
|
+
/** Reduces k_base pairs (base_labels, base_distances) into k pairs
|
|
646
|
+
* (labels, distances). The function is used for the refining process.
|
|
647
|
+
*
|
|
648
|
+
* @param n number of vectors to process
|
|
649
|
+
* @param k number of output nearest neighbors per vector
|
|
650
|
+
* @param labels output labels, size (n, k)
|
|
651
|
+
* @param distances output distances, size (n, k)
|
|
652
|
+
* @param k_base number of input nearest neighbors per vector
|
|
653
|
+
* @param base_labels input labels, size (n, k_base)
|
|
654
|
+
* @param base_distances input distances, size (n, k_base)
|
|
655
|
+
*/
|
|
656
|
+
template <class C>
|
|
657
|
+
void reorder_2_heaps(
|
|
658
|
+
int64_t n,
|
|
659
|
+
int64_t k,
|
|
660
|
+
typename C::TI* __restrict labels,
|
|
661
|
+
float* __restrict distances,
|
|
662
|
+
int64_t k_base,
|
|
663
|
+
const typename C::TI* __restrict base_labels,
|
|
664
|
+
const float* __restrict base_distances);
|
|
665
|
+
|
|
645
666
|
} // namespace faiss
|
|
646
667
|
|
|
647
668
|
#endif /* FAISS_Heap_h */
|