faiss 0.6.4 → 0.6.6
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 +9 -0
- data/ext/faiss/extconf.rb +2 -1
- data/ext/faiss/index.cpp +42 -0
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +175 -0
- data/vendor/faiss/faiss/Clustering.cpp +150 -60
- data/vendor/faiss/faiss/Clustering.h +29 -0
- data/vendor/faiss/faiss/IVFlib.cpp +147 -51
- data/vendor/faiss/faiss/IVFlib.h +21 -2
- data/vendor/faiss/faiss/Index.cpp +44 -0
- data/vendor/faiss/faiss/Index.h +18 -13
- data/vendor/faiss/faiss/IndexBinary.cpp +8 -0
- data/vendor/faiss/faiss/IndexBinary.h +8 -0
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +1 -0
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +85 -4
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +19 -0
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +40 -11
- data/vendor/faiss/faiss/IndexFastScan.cpp +34 -18
- data/vendor/faiss/faiss/IndexFastScan.h +6 -3
- data/vendor/faiss/faiss/IndexFlat.cpp +57 -1
- data/vendor/faiss/faiss/IndexFlat.h +31 -0
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +6 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +461 -13
- data/vendor/faiss/faiss/IndexHNSW.h +40 -5
- data/vendor/faiss/faiss/IndexIDMap.cpp +45 -0
- data/vendor/faiss/faiss/IndexIDMap.h +15 -3
- data/vendor/faiss/faiss/IndexIVF.cpp +349 -68
- data/vendor/faiss/faiss/IndexIVF.h +90 -2
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +51 -29
- data/vendor/faiss/faiss/IndexIVFFastScan.h +4 -2
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +33 -0
- data/vendor/faiss/faiss/IndexIVFFlat.h +22 -6
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +2 -1
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +3 -20
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +78 -58
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +7 -13
- data/vendor/faiss/faiss/IndexIVFRaBitQSSD.cpp +1694 -0
- data/vendor/faiss/faiss/IndexIVFRaBitQSSD.h +288 -0
- data/vendor/faiss/faiss/IndexIVFSQFastScan.cpp +860 -0
- data/vendor/faiss/faiss/IndexIVFSQFastScan.h +145 -0
- data/vendor/faiss/faiss/IndexNNDescent.cpp +21 -3
- data/vendor/faiss/faiss/IndexPiPNN.cpp +201 -0
- data/vendor/faiss/faiss/IndexPiPNN.h +83 -0
- data/vendor/faiss/faiss/IndexRaBitQ.cpp +189 -41
- data/vendor/faiss/faiss/IndexRaBitQ.h +5 -0
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +7 -4
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +12 -6
- data/vendor/faiss/faiss/IndexReplicas.cpp +20 -0
- data/vendor/faiss/faiss/IndexReplicas.h +9 -0
- data/vendor/faiss/faiss/IndexSQFastScan.cpp +648 -0
- data/vendor/faiss/faiss/IndexSQFastScan.h +129 -0
- data/vendor/faiss/faiss/IndexShards.cpp +10 -0
- data/vendor/faiss/faiss/IndexShards.h +5 -0
- data/vendor/faiss/faiss/SuperKMeans.cpp +59 -17
- data/vendor/faiss/faiss/SuperKMeans.h +9 -4
- data/vendor/faiss/faiss/VectorTransform.cpp +159 -11
- data/vendor/faiss/faiss/VectorTransform.h +24 -1
- data/vendor/faiss/faiss/clone_index.cpp +24 -0
- data/vendor/faiss/faiss/factory_tools.cpp +19 -1
- data/vendor/faiss/faiss/gpu/Dataset.h +164 -0
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +16 -13
- data/vendor/faiss/faiss/gpu/GpuCloner.h +4 -0
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +3 -0
- data/vendor/faiss/faiss/gpu/GpuIndex.h +4 -13
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryCagra.h +32 -13
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +51 -22
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +11 -0
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +6 -0
- data/vendor/faiss/faiss/gpu/impl/optimal_kmeans/GpuOptimalKMeans.h +184 -0
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +12 -4
- data/vendor/faiss/faiss/gpu/test/TestGpuDatasetHeader.cpp +18 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +215 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +98 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +6 -5
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +11 -0
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +1 -1
- data/vendor/faiss/faiss/gpu_metal/GpuIndexFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +12 -1
- data/vendor/faiss/faiss/gpu_metal/MetalDistance.h +93 -1
- data/vendor/faiss/faiss/gpu_metal/MetalFlatKernels.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +5 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexBinaryFlat.h +69 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndexFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFPQ.h +39 -1
- data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +107 -1
- data/vendor/faiss/faiss/gpu_metal/MetalPythonBridge.h +11 -1
- data/vendor/faiss/faiss/gpu_metal/MetalResources.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/StandardMetalResources.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFPQ.h +1 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +3 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +1 -6
- data/vendor/faiss/faiss/impl/ClusteringHelpers.cpp +134 -45
- data/vendor/faiss/faiss/impl/ClusteringHelpers.h +36 -0
- data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +267 -136
- data/vendor/faiss/faiss/impl/ClusteringInitialization.h +0 -15
- data/vendor/faiss/faiss/impl/CodePacker.cpp +2 -2
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +2 -2
- data/vendor/faiss/faiss/impl/DeterministicNNDescent.cpp +2167 -0
- data/vendor/faiss/faiss/impl/DeterministicNNDescent.h +301 -0
- data/vendor/faiss/faiss/impl/DistanceComputer.cpp +63 -0
- data/vendor/faiss/faiss/impl/DistanceComputer.h +3 -29
- data/vendor/faiss/faiss/impl/HNSW.cpp +48 -12
- data/vendor/faiss/faiss/impl/HNSW.h +74 -2
- data/vendor/faiss/faiss/impl/IDSelector.h +5 -4
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +6 -19
- data/vendor/faiss/faiss/impl/NNDescent.cpp +2 -1
- data/vendor/faiss/faiss/impl/NNDescent.h +4 -0
- data/vendor/faiss/faiss/impl/NSG.cpp +3 -2
- data/vendor/faiss/faiss/impl/Panorama.h +3 -2
- data/vendor/faiss/faiss/impl/PiPNN.cpp +824 -0
- data/vendor/faiss/faiss/impl/PiPNN.h +122 -0
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +1 -1
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +54 -11
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +0 -2
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +30 -1
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +91 -66
- data/vendor/faiss/faiss/impl/RaBitQuantizer.h +15 -0
- data/vendor/faiss/faiss/impl/ResultHandler.h +116 -0
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +29 -0
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +1 -6
- data/vendor/faiss/faiss/impl/approx_topk/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/approx_topk/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHash_impl.h +5 -2
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryIVF_impl.h +1 -3
- data/vendor/faiss/faiss/impl/binary_hamming/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/rvv.cpp +0 -4
- data/vendor/faiss/faiss/impl/expanded_scanners.h +93 -0
- data/vendor/faiss/faiss/impl/fast_scan/FastScanDistancePostProcessing.h +4 -0
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops.h +61 -64
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops_512.h +13 -14
- data/vendor/faiss/faiss/impl/fast_scan/decompose_qbs.h +17 -129
- data/vendor/faiss/faiss/impl/fast_scan/dispatching.h +25 -19
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.cpp +73 -6
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.h +43 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +15 -4
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +115 -4
- data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +10 -85
- data/vendor/faiss/faiss/impl/fast_scan/impl-riscv.cpp +0 -4
- data/vendor/faiss/faiss/impl/fast_scan/kernels_neon.h +155 -0
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd256.h +106 -1
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd512.h +3 -6
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_result_handler.h +0 -1
- data/vendor/faiss/faiss/impl/fast_scan/simd_result_handlers.h +105 -78
- data/vendor/faiss/faiss/impl/hnsw/LockVector.h +1 -2
- data/vendor/faiss/faiss/impl/hnsw/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/hnsw/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/index_read.cpp +318 -9
- data/vendor/faiss/faiss/impl/index_write.cpp +124 -5
- data/vendor/faiss/faiss/impl/io.cpp +1 -0
- data/vendor/faiss/faiss/impl/io_macros.h +2 -2
- data/vendor/faiss/faiss/impl/mapped_io.cpp +3 -1
- data/vendor/faiss/faiss/impl/maybe_owned_vector.h +78 -41
- data/vendor/faiss/faiss/impl/nndescent/gram-avx2.cpp +121 -0
- data/vendor/faiss/faiss/impl/nndescent/gram-avx512.cpp +124 -0
- data/vendor/faiss/faiss/impl/nndescent/gram-neon.cpp +114 -0
- data/vendor/faiss/faiss/impl/nndescent/gram.h +66 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-avx512.cpp +431 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-inl.h +1157 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.cpp +282 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.h +226 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.cpp +1567 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.h +281 -0
- data/vendor/faiss/faiss/impl/pipnn/HashPrune.cpp +159 -0
- data/vendor/faiss/faiss/impl/pipnn/HashPrune.h +69 -0
- data/vendor/faiss/faiss/impl/pipnn/Partition.cpp +587 -0
- data/vendor/faiss/faiss/impl/pipnn/Partition.h +93 -0
- data/vendor/faiss/faiss/impl/pipnn/kernels.cpp +326 -0
- data/vendor/faiss/faiss/impl/pipnn/kernels.h +92 -0
- data/vendor/faiss/faiss/impl/platform_macros.h +91 -27
- data/vendor/faiss/faiss/impl/polysemous_training/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +84 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.cpp +17 -17
- data/vendor/faiss/faiss/impl/pq_code_distance/PQDistanceComputer_impl.h +6 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx2.h +4 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx512.h +4 -1
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.cpp +19 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.h +6 -6
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-inl.h +131 -6
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-sve.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_rvv_kernel.h +89 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_scan_impl.h +21 -10
- data/vendor/faiss/faiss/impl/pq_code_distance/rvv.cpp +45 -18
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +2 -1
- data/vendor/faiss/faiss/impl/result_handler/ResultHandler.cpp +68 -1
- data/vendor/faiss/faiss/impl/result_handler/avx2.cpp +70 -6
- data/vendor/faiss/faiss/impl/result_handler/avx512.cpp +2 -5
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer-avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer-avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +5 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +28 -52
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +85 -37
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +262 -110
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-impl.h +503 -122
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-spr.cpp +10 -155
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +7 -701
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +66 -57
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +133 -127
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-rvv.cpp +3185 -144
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq8_coefficients.h +48 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq8_rvv_kernel.h +546 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.cpp +2 -2
- data/vendor/faiss/faiss/impl/simd_dispatch.h +7 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx2.h +14 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx512.h +20 -20
- data/vendor/faiss/faiss/impl/simdlib/simdlib_dispatch.h +7 -8
- data/vendor/faiss/faiss/impl/simdlib/simdlib_neon.h +4 -4
- data/vendor/faiss/faiss/impl/sq_fastscan_utils.h +232 -0
- data/vendor/faiss/faiss/impl/zerocopy_io.cpp +2 -1
- data/vendor/faiss/faiss/index_factory.cpp +106 -6
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +1 -1
- data/vendor/faiss/faiss/invlists/DiskIOBackend.cpp +121 -0
- data/vendor/faiss/faiss/invlists/DiskIOBackend.h +71 -0
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +15 -10
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +26 -0
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +5 -0
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +9 -24
- data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.cpp +751 -0
- data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.h +224 -0
- data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +2 -7
- data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSIVF.cpp +2 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +4 -4
- data/vendor/faiss/faiss/svs/IndexSVSVamana.h +3 -2
- data/vendor/faiss/faiss/utils/AlignedTable.h +6 -1
- data/vendor/faiss/faiss/utils/Heap.cpp +4 -3
- data/vendor/faiss/faiss/utils/WorkerThread.h +0 -1
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +16 -5
- data/vendor/faiss/faiss/utils/bf16.h +36 -0
- data/vendor/faiss/faiss/utils/distances.cpp +466 -43
- data/vendor/faiss/faiss/utils/distances.h +179 -2
- data/vendor/faiss/faiss/utils/distances_dispatch.h +6 -4
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +2 -5
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +0 -14
- data/vendor/faiss/faiss/utils/distances_fused/rvv.cpp +25 -0
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +0 -4
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_kernel-inl.h +2 -1
- data/vendor/faiss/faiss/utils/distances_simd.cpp +9 -0
- data/vendor/faiss/faiss/utils/extra_distances.h +2 -1
- data/vendor/faiss/faiss/utils/fp16-fp16c.h +4 -0
- data/vendor/faiss/faiss/utils/fp16-inl.h +26 -52
- data/vendor/faiss/faiss/utils/hamming-inl.h +3 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512_vpopcnt.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512.h +33 -5
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512_vpopcnt.h +15 -30
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-neon.h +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_impl.h +2 -1
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_rvv.cpp +0 -4
- data/vendor/faiss/faiss/utils/partitioning.cpp +2 -2
- data/vendor/faiss/faiss/utils/pq_code_distance.h +8 -4
- data/vendor/faiss/faiss/utils/prefetch.h +1 -26
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +26 -27
- data/vendor/faiss/faiss/utils/quantize_lut.h +11 -0
- data/vendor/faiss/faiss/utils/rabitq_simd.h +171 -22
- data/vendor/faiss/faiss/utils/simd_impl/distances_aarch64.cpp +9 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +81 -9
- data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +7 -3
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +108 -9
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +111 -12
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv.cpp +353 -71
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv_kernel.h +68 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_simdlib256.h +3 -3
- data/vendor/faiss/faiss/utils/simd_impl/exhaustive_L2sqr_blas_cmax.h +106 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels.h +76 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_avx2.cpp +52 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_avx512.cpp +52 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_neon.cpp +48 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum-avx2.h +44 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum-avx512.h +43 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum.h +38 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_simdlib256.h +16 -15
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp +185 -51
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +194 -66
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512_vpopcnt.cpp +51 -14
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_neon.cpp +297 -10
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_rvv.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx512.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_sve.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_levels.cpp +22 -6
- data/vendor/faiss/faiss/utils/simd_levels.h +74 -1
- data/vendor/faiss/faiss/utils/sorting.cpp +6 -5
- data/vendor/faiss/faiss/utils/transpose/transpose-avx2-inl.h +0 -4
- data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +0 -4
- data/vendor/faiss/faiss/utils/utils.cpp +84 -0
- data/vendor/faiss/faiss/utils/utils.h +24 -0
- metadata +52 -1
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 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
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <cstddef>
|
|
11
|
+
#include <cstdint>
|
|
12
|
+
#include <vector>
|
|
13
|
+
|
|
14
|
+
#include <faiss/IndexIVF.h>
|
|
15
|
+
#include <faiss/impl/RaBitQuantizer.h>
|
|
16
|
+
|
|
17
|
+
namespace faiss {
|
|
18
|
+
|
|
19
|
+
struct RaBitQSSDInvertedLists;
|
|
20
|
+
|
|
21
|
+
struct IVFRaBitQSSDSearchParameters : IVFSearchParameters {
|
|
22
|
+
/// overrides IndexIVFRaBitQSSD::use_hacc
|
|
23
|
+
bool use_hacc = true;
|
|
24
|
+
/// overrides IndexIVFRaBitQSSD::drain_alpha
|
|
25
|
+
float drain_alpha = 1.0f;
|
|
26
|
+
/// overrides IndexIVFRaBitQSSD::qd_per_thread
|
|
27
|
+
size_t qd_per_thread = 16;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** IVF index whose RaBitQ codes are split between memory and an SSD
|
|
31
|
+
* (RaBitQ-SSD).
|
|
32
|
+
*
|
|
33
|
+
* Reference: "RaBitQ-SSD: Split Codes and Pipelined I/O for SSD-Resident
|
|
34
|
+
* Vector Search", Yuexuan Xu et al.
|
|
35
|
+
*
|
|
36
|
+
* Vectors are encoded with RaBitQuantizer relative to the center of their
|
|
37
|
+
* list, with nb_bits bits per dimension: a sign bit and nb_bits - 1 extra
|
|
38
|
+
* bits. The sign bits of the first mem_dim dimensions stay in memory; the
|
|
39
|
+
* other sign bits, the extra bits and the vector ids are stored in a file,
|
|
40
|
+
* see RaBitQSSDInvertedLists.
|
|
41
|
+
*
|
|
42
|
+
* The center of a list is its centroid in the coarse quantizer, times
|
|
43
|
+
* centroid_scales[list_no] with METRIC_INNER_PRODUCT. With this metric,
|
|
44
|
+
* IndexIVF trains the quantizer with spherical k-means, so the centroids
|
|
45
|
+
* have norm 1. When the norms of the vectors are far from 1, the residuals
|
|
46
|
+
* to such centroids are large and the error bound is loose. train()
|
|
47
|
+
* therefore sets the scale of each list: its center is the multiple of the
|
|
48
|
+
* centroid closest to the mean of the list's training vectors. The centroids
|
|
49
|
+
* are not rescaled. An inner-product index must be trained even if the
|
|
50
|
+
* caller filled its quantizer.
|
|
51
|
+
*
|
|
52
|
+
* Search. Each search thread takes one query at a time, runs the coarse
|
|
53
|
+
* quantizer on it and scans the probed lists in batches of 32 vectors. For
|
|
54
|
+
* each vector, FastScan over its in-memory bits gives a distance estimate and
|
|
55
|
+
* a lower bound (the RaBitQ error bound). Vectors whose lower bound does not
|
|
56
|
+
* exceed the current k-th distance are grouped by page, and the pages are
|
|
57
|
+
* queued by their smallest lower bound. Between batches, the search re-ranks
|
|
58
|
+
* the pages whose reads completed and submits the most promising queued
|
|
59
|
+
* pages, keeping at most qd_per_thread reads in flight. After the last list,
|
|
60
|
+
* the remaining reads are drained.
|
|
61
|
+
*
|
|
62
|
+
* The distance estimates assume randomly rotated vectors, as for all RaBitQ
|
|
63
|
+
* indexes: use the index inside an IndexPreTransform with
|
|
64
|
+
* HadamardRotation(d, seed, false).
|
|
65
|
+
*
|
|
66
|
+
* The index is created without inverted lists: call attach_file() before
|
|
67
|
+
* adding or searching vectors. index_factory accepts
|
|
68
|
+
* "IVF<nlist>,RaBitQSSD<nb_bits>_<mem_dim>", usually after the rotation:
|
|
69
|
+
* "HRk,IVF<nlist>,RaBitQSSD<nb_bits>_<mem_dim>". Unlike in "RaBitQfs<b>_<n>",
|
|
70
|
+
* the number after the underscore is mem_dim, not a block size.
|
|
71
|
+
*
|
|
72
|
+
* The index works only with RaBitQSSDInvertedLists, whose layout (sign bits
|
|
73
|
+
* in memory, records in pages of a file) is the point of the index. These
|
|
74
|
+
* lists hold no flat codes, so the IVF operations that move codes between
|
|
75
|
+
* inverted lists are not supported: merge_from, copy_subset_to, and the
|
|
76
|
+
* HStack, VStack and Slice inverted-lists wrappers.
|
|
77
|
+
*
|
|
78
|
+
* Not supported either: remove_ids, update_vectors, range search,
|
|
79
|
+
* reconstruction, search_and_return_codes and standalone codes (sa_encode).
|
|
80
|
+
* Search parameters max_codes, max_lists_num, ensure_topk_full and
|
|
81
|
+
* max_empty_result_buckets throw; inverted_list_context is not used.
|
|
82
|
+
* read_index supports IO_FLAG_READ_ONLY and IO_FLAG_ONDISK_SAME_DIR,
|
|
83
|
+
* and rejects IO_FLAG_SKIP_IVF_DATA and IO_FLAG_MMAP.
|
|
84
|
+
*/
|
|
85
|
+
struct IndexIVFRaBitQSSD : IndexIVF {
|
|
86
|
+
/// most SSD reads a search thread can have in flight
|
|
87
|
+
static constexpr size_t kMaxReadsInFlight = 200;
|
|
88
|
+
|
|
89
|
+
/// encodes the vectors; its nb_bits is the total number of bits per
|
|
90
|
+
/// dimension, in [2, 9]
|
|
91
|
+
RaBitQuantizer rabitq;
|
|
92
|
+
|
|
93
|
+
/// dimensions whose sign bits stay in memory: a multiple of 64 in [64, d]
|
|
94
|
+
size_t mem_dim = 0;
|
|
95
|
+
|
|
96
|
+
/// use 16-bit look-up tables for the in-memory scan (accumulate_hacc);
|
|
97
|
+
/// if false, 8-bit tables
|
|
98
|
+
bool use_hacc = true;
|
|
99
|
+
|
|
100
|
+
/// after the last list, pages whose lower bound exceeds the
|
|
101
|
+
/// drain_alpha-quantile of the current results are not read. 1 keeps
|
|
102
|
+
/// the k-th distance as the threshold. Below 1, recall depends on the
|
|
103
|
+
/// load: only the pages still waiting to be read when the last list is
|
|
104
|
+
/// scanned are pruned this way, and more of them wait when the SSD is
|
|
105
|
+
/// saturated, so recall measured at low load overestimates it at high
|
|
106
|
+
/// load.
|
|
107
|
+
float drain_alpha = 1.0f;
|
|
108
|
+
|
|
109
|
+
/// SSD reads in flight per search thread, at most kMaxReadsInFlight
|
|
110
|
+
size_t qd_per_thread = 16;
|
|
111
|
+
|
|
112
|
+
/// squared norms of the centroids, needed to derive <q, c> and |q - c|
|
|
113
|
+
/// from the coarse distances when the index or the quantizer uses the
|
|
114
|
+
/// inner product. Set by train() and add().
|
|
115
|
+
std::vector<float> centroid_norms;
|
|
116
|
+
|
|
117
|
+
/// METRIC_INNER_PRODUCT only, empty otherwise: the codes of list l are
|
|
118
|
+
/// relative to centroid_scales[l] times centroid l of the quantizer. Set
|
|
119
|
+
/// by train() on an empty index. Reset the index and train it again
|
|
120
|
+
/// after changing the centroids.
|
|
121
|
+
std::vector<float> centroid_scales;
|
|
122
|
+
|
|
123
|
+
/** @param quantizer coarse quantizer, which must implement reconstruct.
|
|
124
|
+
* Tested with IndexFlat and IndexHNSWFlat. Raise the
|
|
125
|
+
* efSearch of an IndexHNSWFlat (e.g. to 256) before
|
|
126
|
+
* train() and add(): with the default, some vectors
|
|
127
|
+
* go to lists other than their nearest, which lowers
|
|
128
|
+
* recall at any nprobe short of nlist.
|
|
129
|
+
* @param d dimensionality, a multiple of 64
|
|
130
|
+
* @param nlist number of lists
|
|
131
|
+
* @param mem_dim dimensions whose sign bits stay in memory
|
|
132
|
+
* @param nb_bits bits per dimension, in [2, 9]
|
|
133
|
+
* @param metric METRIC_L2 or METRIC_INNER_PRODUCT
|
|
134
|
+
*/
|
|
135
|
+
IndexIVFRaBitQSSD(
|
|
136
|
+
Index* quantizer,
|
|
137
|
+
size_t d,
|
|
138
|
+
size_t nlist,
|
|
139
|
+
size_t mem_dim,
|
|
140
|
+
uint8_t nb_bits,
|
|
141
|
+
MetricType metric = METRIC_L2);
|
|
142
|
+
|
|
143
|
+
IndexIVFRaBitQSSD();
|
|
144
|
+
|
|
145
|
+
IndexIVFRaBitQSSD(const IndexIVFRaBitQSSD&) = delete;
|
|
146
|
+
IndexIVFRaBitQSSD& operator=(const IndexIVFRaBitQSSD&) = delete;
|
|
147
|
+
|
|
148
|
+
/** Store the disk-resident part in a new file (created or truncated),
|
|
149
|
+
* replacing the inverted lists of an empty index. Its file system must
|
|
150
|
+
* support O_DIRECT.
|
|
151
|
+
*/
|
|
152
|
+
void attach_file(const char* filename);
|
|
153
|
+
|
|
154
|
+
/// the inverted lists, or an exception if they are not of the right type
|
|
155
|
+
RaBitQSSDInvertedLists* get_ssd_invlists() const;
|
|
156
|
+
|
|
157
|
+
/// empty the index, including when inverted lists have not been attached
|
|
158
|
+
void reset() override;
|
|
159
|
+
|
|
160
|
+
/// sets centroid_norms and, for an empty METRIC_INNER_PRODUCT index,
|
|
161
|
+
/// centroid_scales
|
|
162
|
+
void train_encoder(idx_t n, const float* x, const idx_t* assign) override;
|
|
163
|
+
|
|
164
|
+
void add_core(
|
|
165
|
+
idx_t n,
|
|
166
|
+
const float* x,
|
|
167
|
+
const idx_t* xids,
|
|
168
|
+
const idx_t* precomputed_idx,
|
|
169
|
+
void* inverted_list_context = nullptr) override;
|
|
170
|
+
|
|
171
|
+
/// not supported: the codes are not stored as flat codes
|
|
172
|
+
void encode_vectors(
|
|
173
|
+
idx_t n,
|
|
174
|
+
const float* x,
|
|
175
|
+
const idx_t* list_nos,
|
|
176
|
+
uint8_t* codes,
|
|
177
|
+
bool include_listnos = false) const override;
|
|
178
|
+
|
|
179
|
+
/** Unlike IndexIVF::search, which runs the coarse quantizer on all the
|
|
180
|
+
* queries first, each search thread runs it on its own query, so that it
|
|
181
|
+
* overlaps the reads of the other threads. The queries are searched in
|
|
182
|
+
* parallel whatever the parallel_mode.
|
|
183
|
+
*/
|
|
184
|
+
void search(
|
|
185
|
+
idx_t n,
|
|
186
|
+
const float* x,
|
|
187
|
+
idx_t k,
|
|
188
|
+
float* distances,
|
|
189
|
+
idx_t* labels,
|
|
190
|
+
const SearchParameters* params = nullptr) const override;
|
|
191
|
+
|
|
192
|
+
void search_preassigned(
|
|
193
|
+
idx_t n,
|
|
194
|
+
const float* x,
|
|
195
|
+
idx_t k,
|
|
196
|
+
const idx_t* assign,
|
|
197
|
+
const float* centroid_dis,
|
|
198
|
+
float* distances,
|
|
199
|
+
idx_t* labels,
|
|
200
|
+
bool store_pairs,
|
|
201
|
+
const IVFSearchParameters* params = nullptr,
|
|
202
|
+
IndexIVFStats* stats = nullptr) const override;
|
|
203
|
+
|
|
204
|
+
/// not supported
|
|
205
|
+
void range_search(
|
|
206
|
+
idx_t n,
|
|
207
|
+
const float* x,
|
|
208
|
+
float radius,
|
|
209
|
+
RangeSearchResult* result,
|
|
210
|
+
const SearchParameters* params = nullptr) const override;
|
|
211
|
+
|
|
212
|
+
/// not supported
|
|
213
|
+
void range_search_preassigned(
|
|
214
|
+
idx_t nx,
|
|
215
|
+
const float* x,
|
|
216
|
+
float radius,
|
|
217
|
+
const idx_t* keys,
|
|
218
|
+
const float* coarse_dis,
|
|
219
|
+
RangeSearchResult* result,
|
|
220
|
+
bool store_pairs = false,
|
|
221
|
+
const IVFSearchParameters* params = nullptr,
|
|
222
|
+
IndexIVFStats* stats = nullptr) const override;
|
|
223
|
+
|
|
224
|
+
/// not supported: the vectors are not stored, and their codes are
|
|
225
|
+
/// split between memory and the file
|
|
226
|
+
void reconstruct(idx_t key, float* recons) const override;
|
|
227
|
+
|
|
228
|
+
/// not supported, see reconstruct
|
|
229
|
+
void reconstruct_n(idx_t i0, idx_t ni, float* recons) const override;
|
|
230
|
+
|
|
231
|
+
/// not supported, see reconstruct
|
|
232
|
+
void search_and_reconstruct(
|
|
233
|
+
idx_t n,
|
|
234
|
+
const float* x,
|
|
235
|
+
idx_t k,
|
|
236
|
+
float* distances,
|
|
237
|
+
idx_t* labels,
|
|
238
|
+
float* recons,
|
|
239
|
+
const SearchParameters* params = nullptr) const override;
|
|
240
|
+
|
|
241
|
+
/// not supported, see reconstruct
|
|
242
|
+
void search_and_return_codes(
|
|
243
|
+
idx_t n,
|
|
244
|
+
const float* x,
|
|
245
|
+
idx_t k,
|
|
246
|
+
float* distances,
|
|
247
|
+
idx_t* labels,
|
|
248
|
+
uint8_t* recons,
|
|
249
|
+
bool include_listno = false,
|
|
250
|
+
const SearchParameters* params = nullptr) const override;
|
|
251
|
+
|
|
252
|
+
/// not supported, see reconstruct
|
|
253
|
+
void reconstruct_from_offset(int64_t list_no, int64_t offset, float* recons)
|
|
254
|
+
const override;
|
|
255
|
+
|
|
256
|
+
/// not supported
|
|
257
|
+
size_t remove_ids(const IDSelector& sel) override;
|
|
258
|
+
|
|
259
|
+
/// not supported
|
|
260
|
+
void update_vectors(int nv, const idx_t* idx, const float* v) override;
|
|
261
|
+
|
|
262
|
+
/// not supported
|
|
263
|
+
void merge_from(Index& otherIndex, idx_t add_id) override;
|
|
264
|
+
|
|
265
|
+
/// not supported
|
|
266
|
+
void copy_subset_to(
|
|
267
|
+
IndexIVF& other,
|
|
268
|
+
InvertedLists::subset_type_t subset_type,
|
|
269
|
+
idx_t a1,
|
|
270
|
+
idx_t a2) const override;
|
|
271
|
+
|
|
272
|
+
/// recompute centroid_norms from the quantizer
|
|
273
|
+
void update_centroid_norms();
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
/// Counters of IndexIVFRaBitQSSD searches, summed over all searches since
|
|
277
|
+
/// the last reset().
|
|
278
|
+
struct IndexIVFRaBitQSSDStats {
|
|
279
|
+
size_t n_pages_read = 0; ///< pages read from the file
|
|
280
|
+
size_t n_reranked = 0; ///< vectors re-ranked with their full code
|
|
281
|
+
|
|
282
|
+
void reset();
|
|
283
|
+
void add(const IndexIVFRaBitQSSDStats& other);
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
FAISS_API extern IndexIVFRaBitQSSDStats indexIVFRaBitQSSD_stats;
|
|
287
|
+
|
|
288
|
+
} // namespace faiss
|