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
|
@@ -46,13 +46,41 @@ struct Level1Quantizer {
|
|
|
46
46
|
/// to override index used during clustering
|
|
47
47
|
Index* clustering_index = nullptr;
|
|
48
48
|
|
|
49
|
-
/// Trains the quantizer
|
|
49
|
+
/// Trains the level-1 quantizer from fp32 vectors.
|
|
50
50
|
void train_q1(
|
|
51
51
|
size_t n,
|
|
52
52
|
const float* x,
|
|
53
53
|
bool verbose,
|
|
54
54
|
MetricType metric_type);
|
|
55
55
|
|
|
56
|
+
/** Trains the level-1 quantizer from Float32 or packed Float16 vectors.
|
|
57
|
+
*
|
|
58
|
+
* Float16 runs k-means natively on the fp16 rows (see
|
|
59
|
+
* Clustering::train_ex). With quantizer_trains_alone == 1 the data is
|
|
60
|
+
* passed on to quantizer->train_ex(). SuperKMeans supports raw Float32
|
|
61
|
+
* and Float16 input, but not vectors decoded through a codec.
|
|
62
|
+
*/
|
|
63
|
+
void train_q1_ex(
|
|
64
|
+
size_t n,
|
|
65
|
+
const void* x,
|
|
66
|
+
NumericType numeric_type,
|
|
67
|
+
bool verbose,
|
|
68
|
+
MetricType metric_type);
|
|
69
|
+
|
|
70
|
+
/** Trains the level-1 quantizer from vectors encoded by `codec`.
|
|
71
|
+
*
|
|
72
|
+
* The codec must remain alive for the duration of this call and decode
|
|
73
|
+
* each input row to `quantizer->d` floats. Encoded training is supported
|
|
74
|
+
* when clustering trains the quantizer (quantizer_trains_alone 0 or 2)
|
|
75
|
+
* without SuperKMeans.
|
|
76
|
+
*/
|
|
77
|
+
void train_q1_encoded(
|
|
78
|
+
size_t n,
|
|
79
|
+
const uint8_t* x,
|
|
80
|
+
const Index* codec,
|
|
81
|
+
bool verbose,
|
|
82
|
+
MetricType metric_type);
|
|
83
|
+
|
|
56
84
|
/// compute the number of bytes required to store list ids
|
|
57
85
|
size_t coarse_code_size() const;
|
|
58
86
|
void encode_listno(idx_t list_no, uint8_t* code) const;
|
|
@@ -87,6 +115,20 @@ struct SearchParametersIVF : SearchParameters {
|
|
|
87
115
|
/// uses implementation 10 for this option.
|
|
88
116
|
size_t max_empty_result_buckets = 0;
|
|
89
117
|
|
|
118
|
+
/// k-NN only: test the IDSelector only on codes whose distance would enter
|
|
119
|
+
/// the result heap. Faster when the selector costs more than a distance
|
|
120
|
+
/// and accepts most codes; slower when it rejects most codes.
|
|
121
|
+
///
|
|
122
|
+
/// is_member must return the same answer for an id during the whole
|
|
123
|
+
/// search. Then the results are the same with or without this option, so
|
|
124
|
+
/// a scan that does not implement it ignores it. With it,
|
|
125
|
+
/// IndexIVFStats::ndis counts every scanned code.
|
|
126
|
+
///
|
|
127
|
+
/// Only the batched IVF-SQ scan implements it, and only with unlimited
|
|
128
|
+
/// max_codes. The uniform, TurboQuant and 0-bit SQ types and the other
|
|
129
|
+
/// IVF indexes test the selector first.
|
|
130
|
+
bool sel_after_distance = false;
|
|
131
|
+
|
|
90
132
|
SearchParameters* quantizer_params = nullptr;
|
|
91
133
|
/// context object to pass to InvertedLists
|
|
92
134
|
void* inverted_list_context = nullptr;
|
|
@@ -236,6 +278,23 @@ struct IndexIVF : Index, IndexIVFInterface {
|
|
|
236
278
|
/// Trains the quantizer and calls train_encoder to train sub-quantizers
|
|
237
279
|
void train(idx_t n, const float* x) override;
|
|
238
280
|
|
|
281
|
+
/** Train from vectors decoded on demand by `codec`.
|
|
282
|
+
*
|
|
283
|
+
* Coarse quantizer training decodes in bounded batches. Subclasses with a
|
|
284
|
+
* trainable encoder decode at most train_encoder_num_vectors() rows into
|
|
285
|
+
* fp32; IndexIVFFlat overrides this method and needs no fp32 corpus buffer.
|
|
286
|
+
*/
|
|
287
|
+
virtual void train_encoded(idx_t n, const uint8_t* x, const Index* codec);
|
|
288
|
+
|
|
289
|
+
/** Supports Float32 and packed IEEE binary16 (Float16) inputs.
|
|
290
|
+
*
|
|
291
|
+
* Float16 trains natively without a codec: the coarse quantizer runs
|
|
292
|
+
* fp16 k-means (Clustering::train_ex) and only the
|
|
293
|
+
* train_encoder_num_vectors() rows sampled for the encoder are widened
|
|
294
|
+
* to fp32. IndexIVFFlat overrides this and widens no rows at all.
|
|
295
|
+
*/
|
|
296
|
+
void train_ex(idx_t n, const void* x, NumericType numeric_type) override;
|
|
297
|
+
|
|
239
298
|
/// Calls add_with_ids with NULL ids
|
|
240
299
|
void add(idx_t n, const float* x) override;
|
|
241
300
|
|
|
@@ -411,7 +470,7 @@ struct IndexIVF : Index, IndexIVFInterface {
|
|
|
411
470
|
* include the list ids in the code (in this case add
|
|
412
471
|
* ceil(log8(nlist)) to the code size)
|
|
413
472
|
*/
|
|
414
|
-
void search_and_return_codes(
|
|
473
|
+
virtual void search_and_return_codes(
|
|
415
474
|
idx_t n,
|
|
416
475
|
const float* x,
|
|
417
476
|
idx_t k,
|
|
@@ -504,6 +563,9 @@ struct InvertedListScanner {
|
|
|
504
563
|
/// search in this subset of ids
|
|
505
564
|
const IDSelector* sel;
|
|
506
565
|
|
|
566
|
+
/// see SearchParametersIVF::sel_after_distance
|
|
567
|
+
bool sel_after_distance = false;
|
|
568
|
+
|
|
507
569
|
InvertedListScanner(
|
|
508
570
|
bool store_pairs_in = false,
|
|
509
571
|
const IDSelector* sel_in = nullptr)
|
|
@@ -521,6 +583,13 @@ struct InvertedListScanner {
|
|
|
521
583
|
/// compute a single query-to-code distance
|
|
522
584
|
virtual float distance_to_code(const uint8_t* code) const = 0;
|
|
523
585
|
|
|
586
|
+
/** compute the distances to n consecutive codes of code_size bytes. A
|
|
587
|
+
* distance can differ in the last bits from distance_to_code. */
|
|
588
|
+
virtual void distances_to_codes(
|
|
589
|
+
size_t n,
|
|
590
|
+
const uint8_t* codes,
|
|
591
|
+
float* distances) const;
|
|
592
|
+
|
|
524
593
|
/** scan a set of codes, compute distances to current query, and
|
|
525
594
|
* update heap of results if necessary. Default implementation
|
|
526
595
|
* calls distance_to_code.
|
|
@@ -592,12 +661,31 @@ struct IndexIVFStats {
|
|
|
592
661
|
reset();
|
|
593
662
|
}
|
|
594
663
|
void reset();
|
|
664
|
+
/** Adds the counters of other to this one. The adds are atomic, so
|
|
665
|
+
* several threads can add to the same IndexIVFStats at once. This is
|
|
666
|
+
* what makes concurrent searches safe on the global indexIVF_stats. */
|
|
595
667
|
void add(const IndexIVFStats& other);
|
|
596
668
|
};
|
|
597
669
|
|
|
598
670
|
// global var that collects them all
|
|
599
671
|
FAISS_API extern IndexIVFStats indexIVF_stats;
|
|
600
672
|
|
|
673
|
+
/** Adds the counters of one search call to stats, or to indexIVF_stats if
|
|
674
|
+
* stats is null. The adds are atomic, as in IndexIVFStats::add. */
|
|
675
|
+
void add_search_stats(
|
|
676
|
+
size_t nq,
|
|
677
|
+
size_t nlist,
|
|
678
|
+
size_t ndis,
|
|
679
|
+
size_t nheap_updates = 0,
|
|
680
|
+
IndexIVFStats* stats = nullptr);
|
|
681
|
+
|
|
682
|
+
/** Adds the times of one search call to stats, or to indexIVF_stats if
|
|
683
|
+
* stats is null. The adds are atomic, as in IndexIVFStats::add. */
|
|
684
|
+
void add_search_times(
|
|
685
|
+
double quantization_time,
|
|
686
|
+
double search_time,
|
|
687
|
+
IndexIVFStats* stats = nullptr);
|
|
688
|
+
|
|
601
689
|
} // namespace faiss
|
|
602
690
|
|
|
603
691
|
#endif
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
#include <faiss/impl/fast_scan/FastScanDistancePostProcessing.h>
|
|
22
22
|
#include <faiss/impl/fast_scan/fast_scan.h>
|
|
23
23
|
#include <faiss/impl/fast_scan/simd_result_handlers.h>
|
|
24
|
+
#include <faiss/impl/platform_macros.h>
|
|
24
25
|
#include <faiss/invlists/BlockInvertedLists.h>
|
|
25
26
|
#include <faiss/utils/hamming.h>
|
|
26
27
|
#include <faiss/utils/quantize_lut.h>
|
|
@@ -646,8 +647,23 @@ void IndexIVFFastScan::search_dispatch_implem(
|
|
|
646
647
|
search_implem_14(
|
|
647
648
|
n, x, k, distances, labels, cq, impl, context, params);
|
|
648
649
|
} else {
|
|
650
|
+
// Size each thread's LUT here, on the calling thread: a
|
|
651
|
+
// heap-profiler sample taken on an OpenMP worker unwinds
|
|
652
|
+
// through libomp, which is very slow on aarch64. The tables
|
|
653
|
+
// keep their capacity, so smaller slices do not reallocate.
|
|
654
|
+
std::vector<AlignedTable<uint8_t>> thread_dis_tables(
|
|
655
|
+
omp_get_max_threads());
|
|
656
|
+
const size_t max_slice_n = (n + nslice - 1) / nslice;
|
|
657
|
+
const size_t lut_per_query =
|
|
658
|
+
ksub * M2 * (lookup_table_is_3d() ? cur_nprobe : 1);
|
|
659
|
+
for (auto& t : thread_dis_tables) {
|
|
660
|
+
t.keep_capacity = true;
|
|
661
|
+
t.resize(max_slice_n * lut_per_query);
|
|
662
|
+
}
|
|
649
663
|
#pragma omp parallel for reduction(+ : ndis, nlist_visited)
|
|
650
664
|
for (int slice = 0; slice < nslice; slice++) {
|
|
665
|
+
AlignedTable<uint8_t>* dis_tables_buf =
|
|
666
|
+
&thread_dis_tables.at(omp_get_thread_num());
|
|
651
667
|
idx_t i0 = n * slice / nslice;
|
|
652
668
|
idx_t i1 = n * (slice + 1) / nslice;
|
|
653
669
|
float* dis_i = distances + i0 * k;
|
|
@@ -663,6 +679,9 @@ void IndexIVFFastScan::search_dispatch_implem(
|
|
|
663
679
|
if (thread_context.query_factors != nullptr) {
|
|
664
680
|
thread_context.query_factors += i0 * cur_nprobe;
|
|
665
681
|
}
|
|
682
|
+
if (thread_context.rotated_q != nullptr) {
|
|
683
|
+
thread_context.rotated_q += i0 * cur_nprobe * d;
|
|
684
|
+
}
|
|
666
685
|
|
|
667
686
|
auto scanner = make_knn_scanner(
|
|
668
687
|
is_max,
|
|
@@ -684,7 +703,8 @@ void IndexIVFFastScan::search_dispatch_implem(
|
|
|
684
703
|
&nlist_visited,
|
|
685
704
|
thread_context,
|
|
686
705
|
params,
|
|
687
|
-
*scanner
|
|
706
|
+
*scanner,
|
|
707
|
+
dis_tables_buf);
|
|
688
708
|
} else {
|
|
689
709
|
search_implem_10(
|
|
690
710
|
i1 - i0,
|
|
@@ -696,14 +716,13 @@ void IndexIVFFastScan::search_dispatch_implem(
|
|
|
696
716
|
&nlist_visited,
|
|
697
717
|
thread_context,
|
|
698
718
|
params,
|
|
699
|
-
*scanner
|
|
719
|
+
*scanner,
|
|
720
|
+
dis_tables_buf);
|
|
700
721
|
}
|
|
701
722
|
}
|
|
702
723
|
}
|
|
703
724
|
}
|
|
704
|
-
|
|
705
|
-
indexIVF_stats.ndis += ndis;
|
|
706
|
-
indexIVF_stats.nlist += nlist_visited;
|
|
725
|
+
add_search_stats(n, nlist_visited, ndis);
|
|
707
726
|
} else {
|
|
708
727
|
FAISS_THROW_FMT("implem %d does not exist", implem);
|
|
709
728
|
}
|
|
@@ -848,9 +867,7 @@ void IndexIVFFastScan::range_search_dispatch_implem(
|
|
|
848
867
|
}
|
|
849
868
|
}
|
|
850
869
|
|
|
851
|
-
|
|
852
|
-
indexIVF_stats.ndis += ndis;
|
|
853
|
-
indexIVF_stats.nlist += nlist_visited;
|
|
870
|
+
add_search_stats(n, nlist_visited, ndis);
|
|
854
871
|
}
|
|
855
872
|
|
|
856
873
|
template <class C>
|
|
@@ -919,9 +936,7 @@ void IndexIVFFastScan::search_implem_1(
|
|
|
919
936
|
}
|
|
920
937
|
heap_reorder<C>(k, heap_dis, heap_ids);
|
|
921
938
|
}
|
|
922
|
-
|
|
923
|
-
indexIVF_stats.ndis += ndis;
|
|
924
|
-
indexIVF_stats.nlist += nlist_visited;
|
|
939
|
+
add_search_stats(n, nlist_visited, ndis);
|
|
925
940
|
}
|
|
926
941
|
|
|
927
942
|
template <class C>
|
|
@@ -1005,9 +1020,7 @@ void IndexIVFFastScan::search_implem_2(
|
|
|
1005
1020
|
}
|
|
1006
1021
|
}
|
|
1007
1022
|
}
|
|
1008
|
-
|
|
1009
|
-
indexIVF_stats.ndis += ndis;
|
|
1010
|
-
indexIVF_stats.nlist += nlist_visited;
|
|
1023
|
+
add_search_stats(n, nlist_visited, ndis);
|
|
1011
1024
|
}
|
|
1012
1025
|
|
|
1013
1026
|
void IndexIVFFastScan::search_implem_10(
|
|
@@ -1020,9 +1033,12 @@ void IndexIVFFastScan::search_implem_10(
|
|
|
1020
1033
|
size_t* nlist_out,
|
|
1021
1034
|
const FastScanDistancePostProcessing& context,
|
|
1022
1035
|
const IVFSearchParameters* params,
|
|
1023
|
-
FastScanCodeScanner& scanner
|
|
1036
|
+
FastScanCodeScanner& scanner,
|
|
1037
|
+
AlignedTable<uint8_t>* dis_tables_buf) const {
|
|
1024
1038
|
size_t dim12 = ksub * M2;
|
|
1025
|
-
AlignedTable<uint8_t>
|
|
1039
|
+
AlignedTable<uint8_t> local_dis_tables;
|
|
1040
|
+
AlignedTable<uint8_t>& dis_tables =
|
|
1041
|
+
dis_tables_buf ? *dis_tables_buf : local_dis_tables;
|
|
1026
1042
|
AlignedTable<uint16_t> biases;
|
|
1027
1043
|
std::unique_ptr<float[]> normalizers(new float[2 * n]);
|
|
1028
1044
|
|
|
@@ -1060,6 +1076,7 @@ void IndexIVFFastScan::search_implem_10(
|
|
|
1060
1076
|
// Allocate probe_map once and reuse it
|
|
1061
1077
|
std::vector<int> probe_map;
|
|
1062
1078
|
probe_map.reserve(1);
|
|
1079
|
+
const size_t block_stride = get_block_stride();
|
|
1063
1080
|
|
|
1064
1081
|
for (idx_t i = 0; i < n; i++) {
|
|
1065
1082
|
const uint8_t* LUT = nullptr;
|
|
@@ -1134,7 +1151,7 @@ void IndexIVFFastScan::search_implem_10(
|
|
|
1134
1151
|
codes.get(),
|
|
1135
1152
|
LUT,
|
|
1136
1153
|
context.pq2x4_scale,
|
|
1137
|
-
|
|
1154
|
+
block_stride);
|
|
1138
1155
|
|
|
1139
1156
|
ndis += ls;
|
|
1140
1157
|
nlist_visited++;
|
|
@@ -1172,14 +1189,17 @@ void IndexIVFFastScan::search_implem_12(
|
|
|
1172
1189
|
size_t* nlist_out,
|
|
1173
1190
|
const FastScanDistancePostProcessing& context,
|
|
1174
1191
|
const IVFSearchParameters* /* params */,
|
|
1175
|
-
FastScanCodeScanner& scanner
|
|
1192
|
+
FastScanCodeScanner& scanner,
|
|
1193
|
+
AlignedTable<uint8_t>* dis_tables_buf) const {
|
|
1176
1194
|
if (n == 0) { // does not work well with reservoir
|
|
1177
1195
|
return;
|
|
1178
1196
|
}
|
|
1179
1197
|
FAISS_THROW_IF_NOT(bbs == 32);
|
|
1180
1198
|
|
|
1181
1199
|
size_t dim12 = ksub * M2;
|
|
1182
|
-
AlignedTable<uint8_t>
|
|
1200
|
+
AlignedTable<uint8_t> local_dis_tables;
|
|
1201
|
+
AlignedTable<uint8_t>& dis_tables =
|
|
1202
|
+
dis_tables_buf ? *dis_tables_buf : local_dis_tables;
|
|
1183
1203
|
AlignedTable<uint16_t> biases;
|
|
1184
1204
|
std::unique_ptr<float[]> normalizers(new float[2 * n]);
|
|
1185
1205
|
|
|
@@ -1196,6 +1216,7 @@ void IndexIVFFastScan::search_implem_12(
|
|
|
1196
1216
|
size_t cur_nprobe = cq.nprobe;
|
|
1197
1217
|
|
|
1198
1218
|
std::vector<QC> qcs;
|
|
1219
|
+
qcs.reserve(n * cur_nprobe);
|
|
1199
1220
|
{
|
|
1200
1221
|
size_t ij = 0;
|
|
1201
1222
|
for (idx_t i = 0; i < n; i++) {
|
|
@@ -1226,6 +1247,9 @@ void IndexIVFFastScan::search_implem_12(
|
|
|
1226
1247
|
// Allocate vectors once and reuse them
|
|
1227
1248
|
std::vector<int> probe_map;
|
|
1228
1249
|
probe_map.reserve(actual_qbs2);
|
|
1250
|
+
std::vector<int> q_map(actual_qbs2), lut_entries(actual_qbs2);
|
|
1251
|
+
AlignedTable<uint8_t> LUT(actual_qbs2 * dim12);
|
|
1252
|
+
const size_t block_stride = get_block_stride();
|
|
1229
1253
|
|
|
1230
1254
|
size_t i0 = 0;
|
|
1231
1255
|
uint64_t t_copy_pack = 0, t_scan = 0;
|
|
@@ -1252,8 +1276,6 @@ void IndexIVFFastScan::search_implem_12(
|
|
|
1252
1276
|
// re-organize LUTs and biases into the right order
|
|
1253
1277
|
int nc = static_cast<int>(i1 - i0);
|
|
1254
1278
|
|
|
1255
|
-
std::vector<int> q_map(nc), lut_entries(nc);
|
|
1256
|
-
AlignedTable<uint8_t> LUT(nc * dim12);
|
|
1257
1279
|
memset(LUT.get(), -1, nc * dim12);
|
|
1258
1280
|
int qbs_for_list = pq4_preferred_qbs(nc);
|
|
1259
1281
|
|
|
@@ -1303,7 +1325,7 @@ void IndexIVFFastScan::search_implem_12(
|
|
|
1303
1325
|
codes.get(),
|
|
1304
1326
|
LUT.get(),
|
|
1305
1327
|
context.pq2x4_scale,
|
|
1306
|
-
|
|
1328
|
+
block_stride);
|
|
1307
1329
|
// prepare for next loop
|
|
1308
1330
|
i0 = i1;
|
|
1309
1331
|
}
|
|
@@ -1351,6 +1373,7 @@ void IndexIVFFastScan::search_implem_14(
|
|
|
1351
1373
|
size_t cur_nprobe = cq.nprobe;
|
|
1352
1374
|
|
|
1353
1375
|
std::vector<QC> qcs;
|
|
1376
|
+
qcs.reserve(n * cur_nprobe);
|
|
1354
1377
|
{
|
|
1355
1378
|
size_t ij = 0;
|
|
1356
1379
|
for (idx_t i = 0; i < n; i++) {
|
|
@@ -1461,8 +1484,11 @@ void IndexIVFFastScan::search_implem_14(
|
|
|
1461
1484
|
// Allocate probe_map once per thread and reuse it
|
|
1462
1485
|
std::vector<int> probe_map;
|
|
1463
1486
|
probe_map.reserve(actual_qbs2);
|
|
1487
|
+
std::vector<int> q_map(actual_qbs2), lut_entries(actual_qbs2);
|
|
1488
|
+
AlignedTable<uint8_t> LUT(actual_qbs2 * dim12);
|
|
1489
|
+
const size_t block_stride = get_block_stride();
|
|
1464
1490
|
|
|
1465
|
-
#pragma omp for schedule(
|
|
1491
|
+
#pragma omp for schedule(FAISS_OMP_DYNAMIC)
|
|
1466
1492
|
for (idx_t cluster = 0; cluster < static_cast<idx_t>(ses.size());
|
|
1467
1493
|
cluster++) {
|
|
1468
1494
|
size_t i0 = ses[cluster].start;
|
|
@@ -1474,8 +1500,6 @@ void IndexIVFFastScan::search_implem_14(
|
|
|
1474
1500
|
// re-organize LUTs and biases into the right order
|
|
1475
1501
|
int nc = static_cast<int>(i1 - i0);
|
|
1476
1502
|
|
|
1477
|
-
std::vector<int> q_map(nc), lut_entries(nc);
|
|
1478
|
-
AlignedTable<uint8_t> LUT(nc * dim12);
|
|
1479
1503
|
memset(LUT.get(), -1, nc * dim12);
|
|
1480
1504
|
int qbs_for_list = pq4_preferred_qbs(nc);
|
|
1481
1505
|
|
|
@@ -1526,7 +1550,7 @@ void IndexIVFFastScan::search_implem_14(
|
|
|
1526
1550
|
codes.get(),
|
|
1527
1551
|
LUT.get(),
|
|
1528
1552
|
context.pq2x4_scale,
|
|
1529
|
-
|
|
1553
|
+
block_stride);
|
|
1530
1554
|
}
|
|
1531
1555
|
|
|
1532
1556
|
// labels is in-place for HeapHC
|
|
@@ -1565,9 +1589,7 @@ void IndexIVFFastScan::search_implem_14(
|
|
|
1565
1589
|
}
|
|
1566
1590
|
}
|
|
1567
1591
|
|
|
1568
|
-
|
|
1569
|
-
indexIVF_stats.ndis += ndis;
|
|
1570
|
-
indexIVF_stats.nlist += nlist_visited;
|
|
1592
|
+
add_search_stats(n, nlist_visited, ndis);
|
|
1571
1593
|
}
|
|
1572
1594
|
|
|
1573
1595
|
void IndexIVFFastScan::reconstruct_from_offset(
|
|
@@ -303,7 +303,8 @@ struct IndexIVFFastScan : IndexIVF {
|
|
|
303
303
|
size_t* nlist_out,
|
|
304
304
|
const FastScanDistancePostProcessing& context,
|
|
305
305
|
const IVFSearchParameters* params,
|
|
306
|
-
FastScanCodeScanner& scanner
|
|
306
|
+
FastScanCodeScanner& scanner,
|
|
307
|
+
AlignedTable<uint8_t>* dis_tables_buf = nullptr) const;
|
|
307
308
|
|
|
308
309
|
void search_implem_12(
|
|
309
310
|
idx_t n,
|
|
@@ -314,7 +315,8 @@ struct IndexIVFFastScan : IndexIVF {
|
|
|
314
315
|
size_t* nlist_out,
|
|
315
316
|
const FastScanDistancePostProcessing& context,
|
|
316
317
|
const IVFSearchParameters* params,
|
|
317
|
-
FastScanCodeScanner& scanner
|
|
318
|
+
FastScanCodeScanner& scanner,
|
|
319
|
+
AlignedTable<uint8_t>* dis_tables_buf = nullptr) const;
|
|
318
320
|
|
|
319
321
|
// implem 14 is multithreaded internally across nprobes and queries
|
|
320
322
|
void search_implem_14(
|
|
@@ -57,6 +57,25 @@ IndexIVFFlat::IndexIVFFlat() {
|
|
|
57
57
|
by_residual = false;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
void IndexIVFFlat::train_encoded(
|
|
61
|
+
idx_t n,
|
|
62
|
+
const uint8_t* x,
|
|
63
|
+
const Index* codec) {
|
|
64
|
+
FAISS_THROW_IF_NOT_MSG(codec, "encoded training requires a codec");
|
|
65
|
+
train_q1_encoded(n, x, codec, verbose, metric_type);
|
|
66
|
+
is_trained = true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
void IndexIVFFlat::train_ex(idx_t n, const void* x, NumericType numeric_type) {
|
|
70
|
+
if (numeric_type != NumericType::Float16) {
|
|
71
|
+
IndexIVF::train_ex(n, x, numeric_type);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
FAISS_THROW_IF_NOT_MSG(x, "training data must not be null");
|
|
75
|
+
train_q1_ex(n, x, numeric_type, verbose, metric_type);
|
|
76
|
+
is_trained = true;
|
|
77
|
+
}
|
|
78
|
+
|
|
60
79
|
void IndexIVFFlat::add_core(
|
|
61
80
|
idx_t n,
|
|
62
81
|
const float* x,
|
|
@@ -186,6 +205,20 @@ IndexIVFFlatDedup::IndexIVFFlatDedup(
|
|
|
186
205
|
metric_type_in,
|
|
187
206
|
own_invlists_in) {}
|
|
188
207
|
|
|
208
|
+
void IndexIVFFlatDedup::train_encoded(idx_t, const uint8_t*, const Index*) {
|
|
209
|
+
FAISS_THROW_MSG("encoded training is not supported by IndexIVFFlatDedup");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
void IndexIVFFlatDedup::train_ex(
|
|
213
|
+
idx_t n,
|
|
214
|
+
const void* x,
|
|
215
|
+
NumericType numeric_type) {
|
|
216
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
217
|
+
numeric_type == NumericType::Float32,
|
|
218
|
+
"only fp32 training is supported by IndexIVFFlatDedup");
|
|
219
|
+
train(n, static_cast<const float*>(x));
|
|
220
|
+
}
|
|
221
|
+
|
|
189
222
|
void IndexIVFFlatDedup::train(idx_t n, const float* x) {
|
|
190
223
|
std::unordered_map<uint64_t, idx_t> map;
|
|
191
224
|
std::unique_ptr<float[]> x2(new float[n * d]);
|
|
@@ -29,6 +29,16 @@ struct IndexIVFFlat : IndexIVF {
|
|
|
29
29
|
MetricType = METRIC_L2,
|
|
30
30
|
bool own_invlists = true);
|
|
31
31
|
|
|
32
|
+
/** Train the coarse quantizer from vectors decoded on demand by `codec`.
|
|
33
|
+
*
|
|
34
|
+
* IndexIVFFlat has no trainable residual encoder, so this avoids a
|
|
35
|
+
* corpus-sized decoded buffer. The codec must remain alive for this call.
|
|
36
|
+
*/
|
|
37
|
+
void train_encoded(idx_t n, const uint8_t* x, const Index* codec) override;
|
|
38
|
+
|
|
39
|
+
/// Float16 trains only the coarse quantizer, natively on the fp16 rows.
|
|
40
|
+
void train_ex(idx_t n, const void* x, NumericType numeric_type) override;
|
|
41
|
+
|
|
32
42
|
void add_core(
|
|
33
43
|
idx_t n,
|
|
34
44
|
const float* x,
|
|
@@ -68,10 +78,10 @@ struct IVFFlatScanner : InvertedListScanner {
|
|
|
68
78
|
using C = typename VectorDistance::C;
|
|
69
79
|
|
|
70
80
|
IVFFlatScanner(
|
|
71
|
-
const VectorDistance&
|
|
72
|
-
bool
|
|
73
|
-
const IDSelector*
|
|
74
|
-
: InvertedListScanner(
|
|
81
|
+
const VectorDistance& vd_in,
|
|
82
|
+
bool store_pairs_in,
|
|
83
|
+
const IDSelector* sel_in)
|
|
84
|
+
: InvertedListScanner(store_pairs_in, sel_in), vd(vd_in) {
|
|
75
85
|
keep_max = vd.is_similarity;
|
|
76
86
|
code_size = vd.d * sizeof(float);
|
|
77
87
|
}
|
|
@@ -81,8 +91,8 @@ struct IVFFlatScanner : InvertedListScanner {
|
|
|
81
91
|
this->xi = query;
|
|
82
92
|
}
|
|
83
93
|
|
|
84
|
-
void set_list(idx_t
|
|
85
|
-
|
|
94
|
+
void set_list(idx_t list_no_in, float /* coarse_dis */) override {
|
|
95
|
+
list_no = list_no_in;
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
float distance_to_code(const uint8_t* code) const final;
|
|
@@ -110,6 +120,12 @@ struct IndexIVFFlatDedup : IndexIVFFlat {
|
|
|
110
120
|
/// also dedups the training set
|
|
111
121
|
void train(idx_t n, const float* x) override;
|
|
112
122
|
|
|
123
|
+
/// Encoded training cannot preserve the byte-exact deduplication contract.
|
|
124
|
+
void train_encoded(idx_t n, const uint8_t* x, const Index* codec) override;
|
|
125
|
+
|
|
126
|
+
/// Non-fp32 input is rejected for the same reason as train_encoded.
|
|
127
|
+
void train_ex(idx_t n, const void* x, NumericType numeric_type) override;
|
|
128
|
+
|
|
113
129
|
/// implemented for all IndexIVF* classes
|
|
114
130
|
void add_with_ids(idx_t n, const float* x, const idx_t* xids) override;
|
|
115
131
|
|
|
@@ -334,6 +334,7 @@ struct IVFPQFastScanScanner : InvertedListScanner {
|
|
|
334
334
|
const IDSelector* sel_in)
|
|
335
335
|
: InvertedListScanner(store_pairs_in, sel_in), index(index_in) {
|
|
336
336
|
this->keep_max = is_similarity_metric(index_in.metric_type);
|
|
337
|
+
this->code_size = index_in.code_size;
|
|
337
338
|
residual.resize(index_in.d);
|
|
338
339
|
}
|
|
339
340
|
|
|
@@ -367,7 +368,7 @@ struct IVFPQFastScanScanner : InvertedListScanner {
|
|
|
367
368
|
// implemented for all vector distances, although only L2 and IP are
|
|
368
369
|
// supported by FastScan
|
|
369
370
|
with_VectorDistance(pq.dsub, index.metric_type, 0.0, [&](auto vd) {
|
|
370
|
-
|
|
371
|
+
size_t m;
|
|
371
372
|
for (m = 0; m + 1 < pq.M; m += 2) {
|
|
372
373
|
const float* cent;
|
|
373
374
|
uint8_t c = *code++;
|
|
@@ -162,8 +162,7 @@ struct RaBitInvertedListScanner : InvertedListScanner {
|
|
|
162
162
|
std::vector<float> query_vector;
|
|
163
163
|
|
|
164
164
|
std::unique_ptr<FlatCodesDistanceComputer> dc;
|
|
165
|
-
RaBitQDistanceComputer* rabitq_dc =
|
|
166
|
-
nullptr; // For multi-bit adaptive filtering
|
|
165
|
+
RaBitQDistanceComputer* rabitq_dc = nullptr;
|
|
167
166
|
|
|
168
167
|
uint8_t qb = 0;
|
|
169
168
|
bool centered = false;
|
|
@@ -205,30 +204,15 @@ struct RaBitInvertedListScanner : InvertedListScanner {
|
|
|
205
204
|
return dc->distance_to_code(code);
|
|
206
205
|
}
|
|
207
206
|
|
|
208
|
-
// redefiniing the scan_codes allows to inline the distance_to_code
|
|
209
|
-
// (this is unlikely to matter because it contains a virtual function call)
|
|
210
|
-
size_t scan_codes_1bit(
|
|
211
|
-
size_t list_size,
|
|
212
|
-
const uint8_t* codes,
|
|
213
|
-
const idx_t* ids,
|
|
214
|
-
ResultHandler& handler) const {
|
|
215
|
-
return run_scan_codes(*this, list_size, codes, ids, handler);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/// Override scan_codes to implement adaptive filtering for multi-bit codes
|
|
219
207
|
size_t scan_codes(
|
|
220
208
|
size_t list_size,
|
|
221
209
|
const uint8_t* codes,
|
|
222
210
|
const idx_t* ids,
|
|
223
211
|
ResultHandler& handler) const override {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
// For 1-bit codes, use default implementation
|
|
227
|
-
if (ex_bits == 0 || rabitq_dc == nullptr) {
|
|
228
|
-
return scan_codes_1bit(list_size, codes, ids, handler);
|
|
212
|
+
if (qb == 0 && ivf_rabitq.rabitq.nb_bits == 1) {
|
|
213
|
+
return run_scan_codes(*this, list_size, codes, ids, handler);
|
|
229
214
|
}
|
|
230
215
|
|
|
231
|
-
// Multi-bit: Two-stage search with adaptive filtering
|
|
232
216
|
return rabitq_dc->scan_codes_multibit(
|
|
233
217
|
list_size,
|
|
234
218
|
codes,
|
|
@@ -247,7 +231,6 @@ struct RaBitInvertedListScanner : InvertedListScanner {
|
|
|
247
231
|
if (!dc) {
|
|
248
232
|
dc.reset(ivf_rabitq.rabitq.get_distance_computer(
|
|
249
233
|
qb, nullptr, centered));
|
|
250
|
-
// Try to cast to RaBitQDistanceComputer for multi-bit support
|
|
251
234
|
rabitq_dc = dynamic_cast<RaBitQDistanceComputer*>(dc.get());
|
|
252
235
|
FAISS_THROW_IF_NOT(rabitq_dc);
|
|
253
236
|
}
|