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
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
#include <faiss/impl/io_macros.h>
|
|
12
12
|
|
|
13
|
+
#include <cerrno>
|
|
13
14
|
#include <cinttypes>
|
|
14
15
|
#include <cmath>
|
|
15
16
|
#include <cstdio>
|
|
@@ -36,6 +37,9 @@
|
|
|
36
37
|
#include <faiss/IndexIVF.h>
|
|
37
38
|
#include <faiss/IndexIVFAdditiveQuantizer.h>
|
|
38
39
|
#include <faiss/IndexIVFAdditiveQuantizerFastScan.h>
|
|
40
|
+
#ifdef FAISS_ENABLE_DISK_IVF
|
|
41
|
+
#include <faiss/IndexIVFRaBitQSSD.h>
|
|
42
|
+
#endif
|
|
39
43
|
#include <faiss/IndexIVFEDEN.h>
|
|
40
44
|
#include <faiss/IndexIVFFlat.h>
|
|
41
45
|
#include <faiss/IndexIVFFlatPanorama.h>
|
|
@@ -45,6 +49,7 @@
|
|
|
45
49
|
#include <faiss/IndexIVFPQR.h>
|
|
46
50
|
#include <faiss/IndexIVFRaBitQ.h>
|
|
47
51
|
#include <faiss/IndexIVFRaBitQFastScan.h>
|
|
52
|
+
#include <faiss/IndexIVFSQFastScan.h>
|
|
48
53
|
#include <faiss/IndexIVFSpectralHash.h>
|
|
49
54
|
#include <faiss/IndexLSH.h>
|
|
50
55
|
#include <faiss/IndexLattice.h>
|
|
@@ -52,11 +57,13 @@
|
|
|
52
57
|
#include <faiss/IndexNSG.h>
|
|
53
58
|
#include <faiss/IndexPQ.h>
|
|
54
59
|
#include <faiss/IndexPQFastScan.h>
|
|
60
|
+
#include <faiss/IndexPiPNN.h>
|
|
55
61
|
#include <faiss/IndexPreTransform.h>
|
|
56
62
|
#include <faiss/IndexRaBitQ.h>
|
|
57
63
|
#include <faiss/IndexRaBitQFastScan.h>
|
|
58
64
|
#include <faiss/IndexRefine.h>
|
|
59
65
|
#include <faiss/IndexRowwiseMinMax.h>
|
|
66
|
+
#include <faiss/IndexSQFastScan.h>
|
|
60
67
|
#ifdef FAISS_ENABLE_SVS
|
|
61
68
|
#include <faiss/impl/svs_io.h>
|
|
62
69
|
#include <faiss/svs/IndexSVSFlat.h>
|
|
@@ -377,8 +384,9 @@ std::unique_ptr<VectorTransform> read_VectorTransform_up(IOReader* f) {
|
|
|
377
384
|
itqt->pca_then_itq = *pi;
|
|
378
385
|
}
|
|
379
386
|
vt = std::move(itqt);
|
|
380
|
-
} else if (h == fourcc("HRot")) {
|
|
387
|
+
} else if (h == fourcc("HRot") || h == fourcc("HR64")) {
|
|
381
388
|
auto hr = std::make_unique<HadamardRotation>();
|
|
389
|
+
hr->pad_to_power_of_2 = h == fourcc("HRot");
|
|
382
390
|
READ1(hr->seed);
|
|
383
391
|
vt = std::move(hr);
|
|
384
392
|
} else {
|
|
@@ -446,6 +454,27 @@ std::unique_ptr<VectorTransform> read_VectorTransform_up(IOReader* f) {
|
|
|
446
454
|
"HadamardRotation d_out exceeds deserialization byte limit");
|
|
447
455
|
hr->init(hr->seed);
|
|
448
456
|
}
|
|
457
|
+
if (h == fourcc("HR64")) {
|
|
458
|
+
auto* hr = dynamic_cast<HadamardRotation*>(vt.get());
|
|
459
|
+
FAISS_THROW_IF_NOT_MSG(hr, "dynamic_cast to HadamardRotation failed");
|
|
460
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
461
|
+
vt->d_in > 0,
|
|
462
|
+
"invalid HadamardRotation d_in=%d (must be > 0)",
|
|
463
|
+
vt->d_in);
|
|
464
|
+
size_t p = (static_cast<size_t>(vt->d_in) + 63) / 64 * 64;
|
|
465
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
466
|
+
static_cast<size_t>(vt->d_out) == p,
|
|
467
|
+
"invalid HadamardRotation d_out %d for d_in %d"
|
|
468
|
+
" (d_out must be the smallest multiple of 64 >= d_in)",
|
|
469
|
+
vt->d_out,
|
|
470
|
+
vt->d_in);
|
|
471
|
+
// Up to four sign-flip vectors of d_out floats.
|
|
472
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
473
|
+
p <= get_deserialization_vector_byte_limit() /
|
|
474
|
+
(4 * sizeof(float)),
|
|
475
|
+
"HadamardRotation d_out exceeds deserialization byte limit");
|
|
476
|
+
hr->init(hr->seed);
|
|
477
|
+
}
|
|
449
478
|
if (h == fourcc("RmDT")) {
|
|
450
479
|
auto* rdt = dynamic_cast<RemapDimensionsTransform*>(vt.get());
|
|
451
480
|
FAISS_THROW_IF_NOT_MSG(
|
|
@@ -765,6 +794,10 @@ void read_ProductQuantizer(ProductQuantizer* pq, IOReader* f) {
|
|
|
765
794
|
pq->d * pq->ksub);
|
|
766
795
|
}
|
|
767
796
|
|
|
797
|
+
static void validate_codebooks_size(
|
|
798
|
+
const AdditiveQuantizer& aq,
|
|
799
|
+
size_t effective_d);
|
|
800
|
+
|
|
768
801
|
static void read_ResidualQuantizer_old(ResidualQuantizer& rq, IOReader* f) {
|
|
769
802
|
READ1(rq.d);
|
|
770
803
|
FAISS_THROW_IF_NOT_FMT(
|
|
@@ -786,6 +819,7 @@ static void read_ResidualQuantizer_old(ResidualQuantizer& rq, IOReader* f) {
|
|
|
786
819
|
READ1(rq.norm_min);
|
|
787
820
|
READ1(rq.norm_max);
|
|
788
821
|
rq.set_derived_values();
|
|
822
|
+
validate_codebooks_size(rq, rq.d);
|
|
789
823
|
}
|
|
790
824
|
|
|
791
825
|
static void read_AdditiveQuantizer(AdditiveQuantizer& aq, IOReader* f) {
|
|
@@ -847,6 +881,9 @@ static void read_AdditiveQuantizer(AdditiveQuantizer& aq, IOReader* f) {
|
|
|
847
881
|
static void validate_codebooks_size(
|
|
848
882
|
const AdditiveQuantizer& aq,
|
|
849
883
|
size_t effective_d) {
|
|
884
|
+
if (!aq.is_trained && aq.codebooks.empty()) {
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
850
887
|
size_t required = mul_no_overflow(
|
|
851
888
|
effective_d, aq.total_codebook_size, "codebooks validation");
|
|
852
889
|
FAISS_THROW_IF_NOT_FMT(
|
|
@@ -1291,8 +1328,8 @@ static void validate_HNSW(const HNSW& hnsw) {
|
|
|
1291
1328
|
static void read_HNSW(HNSW& hnsw, IOReader* f) {
|
|
1292
1329
|
READVECTOR(hnsw.assign_probas);
|
|
1293
1330
|
READVECTOR(hnsw.cum_nneighbor_per_level);
|
|
1294
|
-
|
|
1295
|
-
|
|
1331
|
+
read_vector(hnsw.levels, f);
|
|
1332
|
+
read_vector(hnsw.offsets, f);
|
|
1296
1333
|
read_vector(hnsw.neighbors, f);
|
|
1297
1334
|
|
|
1298
1335
|
READ1(hnsw.entry_point);
|
|
@@ -1359,6 +1396,59 @@ static void read_NSG(NSG& nsg, IOReader* f) {
|
|
|
1359
1396
|
FAISS_CHECK_RANGE(nsg.enterpoint, 0, N);
|
|
1360
1397
|
}
|
|
1361
1398
|
|
|
1399
|
+
static void read_PiPNN(PiPNN& pipnn, idx_t index_ntotal, IOReader* f) {
|
|
1400
|
+
READ1(pipnn.R);
|
|
1401
|
+
READ1(pipnn.leaf_k);
|
|
1402
|
+
READ1(pipnn.hash_bits);
|
|
1403
|
+
READ1(pipnn.reservoir_size);
|
|
1404
|
+
READ1(pipnn.c_max);
|
|
1405
|
+
READ1(pipnn.c_min);
|
|
1406
|
+
READ1(pipnn.leader_cap);
|
|
1407
|
+
// Former replicas field: build metadata that search does not need.
|
|
1408
|
+
int replicas;
|
|
1409
|
+
READ1(replicas);
|
|
1410
|
+
READ1(pipnn.leader_fraction);
|
|
1411
|
+
READ1(pipnn.alpha);
|
|
1412
|
+
READVECTOR(pipnn.fanout);
|
|
1413
|
+
READ1(pipnn.seed);
|
|
1414
|
+
READ1_BOOL(pipnn.ip_partition_by_angle);
|
|
1415
|
+
READ1(pipnn.search_L);
|
|
1416
|
+
pipnn.check_params();
|
|
1417
|
+
READ1(pipnn.ntotal);
|
|
1418
|
+
READ1(pipnn.entry_point);
|
|
1419
|
+
// Checked before the graph is allocated; ntotal == 0 means unbuilt.
|
|
1420
|
+
if (pipnn.ntotal != 0) {
|
|
1421
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
1422
|
+
pipnn.ntotal == index_ntotal,
|
|
1423
|
+
"PiPNN ntotal %" PRId64 " != index ntotal %" PRId64,
|
|
1424
|
+
pipnn.ntotal,
|
|
1425
|
+
index_ntotal);
|
|
1426
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
1427
|
+
pipnn.ntotal <= INT32_MAX,
|
|
1428
|
+
"built PiPNN ntotal %" PRId64 " exceeds INT32_MAX",
|
|
1429
|
+
pipnn.ntotal);
|
|
1430
|
+
FAISS_CHECK_RANGE(pipnn.entry_point, 0, pipnn.ntotal);
|
|
1431
|
+
}
|
|
1432
|
+
const size_t graph_size = mul_no_overflow(
|
|
1433
|
+
(size_t)pipnn.ntotal, (size_t)pipnn.R, "PiPNN graph");
|
|
1434
|
+
// Views (IO_FLAG_MMAP_IFC, zero-copy) skip the scan: it would fault in
|
|
1435
|
+
// the whole graph. Search bounds-checks every neighbour id instead.
|
|
1436
|
+
if (!read_vector_base(pipnn.graph, f, graph_size, std::nullopt)) {
|
|
1437
|
+
FAISS_THROW_IF_NOT(
|
|
1438
|
+
graph_size <
|
|
1439
|
+
get_deserialization_vector_byte_limit() / sizeof(int32_t));
|
|
1440
|
+
pipnn.graph.resize(graph_size);
|
|
1441
|
+
READANDCHECK(pipnn.graph.data(), graph_size);
|
|
1442
|
+
for (int32_t id : pipnn.graph) {
|
|
1443
|
+
FAISS_CHECK_RANGE(id, -1, pipnn.ntotal);
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
read_vector(pipnn.next_copy, f);
|
|
1447
|
+
FAISS_THROW_IF_NOT(
|
|
1448
|
+
pipnn.next_copy.size() == 0 ||
|
|
1449
|
+
pipnn.next_copy.size() == size_t(pipnn.ntotal));
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1362
1452
|
static void read_NNDescent(NNDescent& nnd, IOReader* f) {
|
|
1363
1453
|
READ1(nnd.ntotal);
|
|
1364
1454
|
READ1(nnd.d);
|
|
@@ -1440,6 +1530,11 @@ static void read_RaBitQuantizer(
|
|
|
1440
1530
|
"RaBitQuantizer dimension mismatch: rabitq.d=%zu vs index d=%d",
|
|
1441
1531
|
rabitq.d,
|
|
1442
1532
|
expected_d);
|
|
1533
|
+
|
|
1534
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
1535
|
+
rabitq.nb_bits >= 1 && rabitq.nb_bits <= 9,
|
|
1536
|
+
"RaBitQuantizer nb_bits=%zu out of range [1, 9]",
|
|
1537
|
+
rabitq.nb_bits);
|
|
1443
1538
|
}
|
|
1444
1539
|
|
|
1445
1540
|
static void read_EDENScalarQuantizer(
|
|
@@ -1841,6 +1936,14 @@ std::unique_ptr<Index> read_index_up(IOReader* f, int io_flags) {
|
|
|
1841
1936
|
} else {
|
|
1842
1937
|
read_ResidualQuantizer(idxr->rq, f, io_flags);
|
|
1843
1938
|
}
|
|
1939
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
1940
|
+
idxr->rq.is_trained == idxr->is_trained,
|
|
1941
|
+
"IndexResidualQuantizer is_trained does not match "
|
|
1942
|
+
"ResidualQuantizer is_trained");
|
|
1943
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
1944
|
+
idxr->ntotal == 0 || idxr->rq.is_trained,
|
|
1945
|
+
"IndexResidualQuantizer with ntotal > 0 must have trained "
|
|
1946
|
+
"ResidualQuantizer");
|
|
1844
1947
|
validate_aq_dimension_match(
|
|
1845
1948
|
idxr->rq, idxr->d, "IndexResidualQuantizer");
|
|
1846
1949
|
READ1(idxr->code_size);
|
|
@@ -2480,9 +2583,9 @@ std::unique_ptr<Index> read_index_up(IOReader* f, int io_flags) {
|
|
|
2480
2583
|
idxmap->index = read_index(f, io_flags);
|
|
2481
2584
|
FAISS_THROW_IF_NOT_MSG(idxmap->index, "IndexIDMap inner index is null");
|
|
2482
2585
|
idxmap->own_fields = true;
|
|
2483
|
-
|
|
2586
|
+
read_vector(idxmap->id_map, f);
|
|
2484
2587
|
FAISS_THROW_IF_NOT_FMT(
|
|
2485
|
-
idxmap->id_map.size() == idxmap->ntotal,
|
|
2588
|
+
idxmap->id_map.size() == static_cast<size_t>(idxmap->ntotal),
|
|
2486
2589
|
"IndexIDMap id_map size (%" PRId64
|
|
2487
2590
|
") does not match ntotal (%" PRId64 ")",
|
|
2488
2591
|
int64_t(idxmap->id_map.size()),
|
|
@@ -2760,6 +2863,66 @@ std::unique_ptr<Index> read_index_up(IOReader* f, int io_flags) {
|
|
|
2760
2863
|
idxnnd->d);
|
|
2761
2864
|
}
|
|
2762
2865
|
idx = std::move(idxnnd);
|
|
2866
|
+
} else if (h == fourcc("IPNf") || h == fourcc("IPNs")) {
|
|
2867
|
+
std::unique_ptr<IndexPiPNN> idxpipnn;
|
|
2868
|
+
if (h == fourcc("IPNf")) {
|
|
2869
|
+
idxpipnn = std::make_unique<IndexPiPNNFlat>();
|
|
2870
|
+
} else {
|
|
2871
|
+
idxpipnn = std::make_unique<IndexPiPNNSQ>();
|
|
2872
|
+
}
|
|
2873
|
+
read_index_header(*idxpipnn, f);
|
|
2874
|
+
READ1_BOOL(idxpipnn->defer_build);
|
|
2875
|
+
read_PiPNN(idxpipnn->pipnn, idxpipnn->ntotal, f);
|
|
2876
|
+
idxpipnn->storage = read_index(f, io_flags);
|
|
2877
|
+
idxpipnn->own_fields = true;
|
|
2878
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
2879
|
+
idxpipnn->storage, "IndexPiPNN requires non-null storage");
|
|
2880
|
+
IndexPiPNN::check_storage_supported(*idxpipnn->storage);
|
|
2881
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
2882
|
+
idxpipnn->storage->ntotal == idxpipnn->ntotal,
|
|
2883
|
+
"PiPNN storage ntotal %" PRId64 " != index ntotal %" PRId64,
|
|
2884
|
+
idxpipnn->storage->ntotal,
|
|
2885
|
+
idxpipnn->ntotal);
|
|
2886
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
2887
|
+
idxpipnn->storage->d == idxpipnn->d,
|
|
2888
|
+
"PiPNN storage d %d != index d %d",
|
|
2889
|
+
idxpipnn->storage->d,
|
|
2890
|
+
idxpipnn->d);
|
|
2891
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
2892
|
+
idxpipnn->storage->metric_type == idxpipnn->metric_type,
|
|
2893
|
+
"PiPNN storage metric %d != index metric %d",
|
|
2894
|
+
(int)idxpipnn->storage->metric_type,
|
|
2895
|
+
(int)idxpipnn->metric_type);
|
|
2896
|
+
idx = std::move(idxpipnn);
|
|
2897
|
+
} else if (h == fourcc("ISfs")) {
|
|
2898
|
+
auto idxsqfs = std::make_unique<IndexSQFastScan>();
|
|
2899
|
+
read_index_header(*idxsqfs, f);
|
|
2900
|
+
read_ScalarQuantizer(&idxsqfs->sq, f, *idxsqfs);
|
|
2901
|
+
READ1(idxsqfs->implem);
|
|
2902
|
+
READ1(idxsqfs->bbs);
|
|
2903
|
+
READ1(idxsqfs->qbs);
|
|
2904
|
+
FAISS_THROW_IF_NOT_MSG(idxsqfs->qbs >= 0, "qbs must be non-negative");
|
|
2905
|
+
READ1(idxsqfs->ntotal2);
|
|
2906
|
+
READ1(idxsqfs->M2);
|
|
2907
|
+
READVECTOR(idxsqfs->codes);
|
|
2908
|
+
READ1(idxsqfs->rerank_factor);
|
|
2909
|
+
READVECTOR(idxsqfs->lo_codes);
|
|
2910
|
+
|
|
2911
|
+
// Restore FastScan base-class fields from the SQ
|
|
2912
|
+
idxsqfs->M = idxsqfs->sq.d;
|
|
2913
|
+
idxsqfs->nbits = 4;
|
|
2914
|
+
idxsqfs->ksub = 16;
|
|
2915
|
+
idxsqfs->code_size = idxsqfs->M2 / 2;
|
|
2916
|
+
|
|
2917
|
+
validate_fastscan_fields(
|
|
2918
|
+
idxsqfs->M,
|
|
2919
|
+
idxsqfs->M2,
|
|
2920
|
+
idxsqfs->ksub,
|
|
2921
|
+
idxsqfs->bbs,
|
|
2922
|
+
"IndexSQFastScan");
|
|
2923
|
+
|
|
2924
|
+
idx = std::move(idxsqfs);
|
|
2925
|
+
|
|
2763
2926
|
} else if (h == fourcc("IPfs")) {
|
|
2764
2927
|
auto idxpqfs = std::make_unique<IndexPQFastScan>();
|
|
2765
2928
|
read_index_header(*idxpqfs, f);
|
|
@@ -2787,6 +2950,46 @@ std::unique_ptr<Index> read_index_up(IOReader* f, int io_flags) {
|
|
|
2787
2950
|
|
|
2788
2951
|
idx = std::move(idxpqfs);
|
|
2789
2952
|
|
|
2953
|
+
} else if (h == fourcc("IwSf")) {
|
|
2954
|
+
auto ivfsqfs = std::make_unique<IndexIVFSQFastScan>();
|
|
2955
|
+
read_ivf_header(ivfsqfs.get(), f);
|
|
2956
|
+
READ1_BOOL(ivfsqfs->by_residual);
|
|
2957
|
+
READ1(ivfsqfs->code_size);
|
|
2958
|
+
READ1(ivfsqfs->bbs);
|
|
2959
|
+
READ1(ivfsqfs->M2);
|
|
2960
|
+
READ1(ivfsqfs->implem);
|
|
2961
|
+
READ1(ivfsqfs->rerank_factor);
|
|
2962
|
+
read_ScalarQuantizer(&ivfsqfs->sq, f, *ivfsqfs);
|
|
2963
|
+
read_InvertedLists(*ivfsqfs, f, io_flags);
|
|
2964
|
+
|
|
2965
|
+
ivfsqfs->M = ivfsqfs->d;
|
|
2966
|
+
ivfsqfs->nbits = 4;
|
|
2967
|
+
ivfsqfs->ksub = 16;
|
|
2968
|
+
ivfsqfs->init_code_packer();
|
|
2969
|
+
|
|
2970
|
+
bool has_orig;
|
|
2971
|
+
READ1(has_orig);
|
|
2972
|
+
if (has_orig) {
|
|
2973
|
+
ivfsqfs->lo_codes_invlists = read_InvertedLists(f, io_flags);
|
|
2974
|
+
// Rebuild direct_map from lo_codes_invlists for reranking
|
|
2975
|
+
ivfsqfs->direct_map.set_type(
|
|
2976
|
+
DirectMap::Hashtable, ivfsqfs->invlists, 0);
|
|
2977
|
+
for (size_t list_no = 0; list_no < ivfsqfs->nlist; list_no++) {
|
|
2978
|
+
size_t list_size =
|
|
2979
|
+
ivfsqfs->lo_codes_invlists->list_size(list_no);
|
|
2980
|
+
if (list_size == 0) {
|
|
2981
|
+
continue;
|
|
2982
|
+
}
|
|
2983
|
+
InvertedLists::ScopedIds ids(
|
|
2984
|
+
ivfsqfs->lo_codes_invlists, list_no);
|
|
2985
|
+
for (size_t j = 0; j < list_size; j++) {
|
|
2986
|
+
ivfsqfs->direct_map.add_single_id(ids[j], list_no, j);
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2991
|
+
idx = std::move(ivfsqfs);
|
|
2992
|
+
|
|
2790
2993
|
} else if (h == fourcc("IwPf")) {
|
|
2791
2994
|
auto ivpq = std::make_unique<IndexIVFPQFastScan>();
|
|
2792
2995
|
read_ivf_header(ivpq.get(), f);
|
|
@@ -2937,8 +3140,25 @@ std::unique_ptr<Index> read_index_up(IOReader* f, int io_flags) {
|
|
|
2937
3140
|
auto idxq = std::make_unique<IndexRaBitQ>();
|
|
2938
3141
|
read_index_header(*idxq, f);
|
|
2939
3142
|
read_RaBitQuantizer(idxq->rabitq, f, idxq->d, false);
|
|
3143
|
+
// Update rabitq to match nb_bits
|
|
3144
|
+
idxq->rabitq.code_size =
|
|
3145
|
+
idxq->rabitq.compute_code_size(idxq->d, idxq->rabitq.nb_bits);
|
|
2940
3146
|
read_vector(idxq->codes, f);
|
|
2941
3147
|
READVECTOR(idxq->center);
|
|
3148
|
+
const size_t expected_codes_size = mul_no_overflow(
|
|
3149
|
+
static_cast<size_t>(idxq->ntotal),
|
|
3150
|
+
idxq->rabitq.code_size,
|
|
3151
|
+
"IndexRaBitQ codes");
|
|
3152
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
3153
|
+
idxq->codes.size() == expected_codes_size,
|
|
3154
|
+
"IndexRaBitQ codes size mismatch: got %zu, expected %zu",
|
|
3155
|
+
idxq->codes.size(),
|
|
3156
|
+
expected_codes_size);
|
|
3157
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
3158
|
+
idxq->center.size() == static_cast<size_t>(idxq->d),
|
|
3159
|
+
"IndexRaBitQ center size mismatch: got %zu, expected %d",
|
|
3160
|
+
idxq->center.size(),
|
|
3161
|
+
idxq->d);
|
|
2942
3162
|
READ1(idxq->qb);
|
|
2943
3163
|
// qb=0: Not quantized - direct distance computation on given float32s.
|
|
2944
3164
|
// qb>0 && qb<=8: Scalar-quantized with qb bits of precision.
|
|
@@ -2956,8 +3176,25 @@ std::unique_ptr<Index> read_index_up(IOReader* f, int io_flags) {
|
|
|
2956
3176
|
read_index_header(*idxq, f);
|
|
2957
3177
|
read_RaBitQuantizer(
|
|
2958
3178
|
idxq->rabitq, f, idxq->d, true); // Reads nb_bits from file
|
|
3179
|
+
// Update rabitq to match nb_bits
|
|
3180
|
+
idxq->rabitq.code_size =
|
|
3181
|
+
idxq->rabitq.compute_code_size(idxq->d, idxq->rabitq.nb_bits);
|
|
2959
3182
|
read_vector(idxq->codes, f);
|
|
2960
3183
|
READVECTOR(idxq->center);
|
|
3184
|
+
const size_t expected_codes_size = mul_no_overflow(
|
|
3185
|
+
static_cast<size_t>(idxq->ntotal),
|
|
3186
|
+
idxq->rabitq.code_size,
|
|
3187
|
+
"IndexRaBitQ codes");
|
|
3188
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
3189
|
+
idxq->codes.size() == expected_codes_size,
|
|
3190
|
+
"IndexRaBitQ codes size mismatch: got %zu, expected %zu",
|
|
3191
|
+
idxq->codes.size(),
|
|
3192
|
+
expected_codes_size);
|
|
3193
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
3194
|
+
idxq->center.size() == static_cast<size_t>(idxq->d),
|
|
3195
|
+
"IndexRaBitQ center size mismatch: got %zu, expected %d",
|
|
3196
|
+
idxq->center.size(),
|
|
3197
|
+
idxq->d);
|
|
2961
3198
|
READ1(idxq->qb);
|
|
2962
3199
|
// qb=0: Not quantized - direct distance computation on given float32s.
|
|
2963
3200
|
// qb>0 && qb<=8: Scalar-quantized with qb bits of precision.
|
|
@@ -3012,6 +3249,72 @@ std::unique_ptr<Index> read_index_up(IOReader* f, int io_flags) {
|
|
|
3012
3249
|
read_InvertedLists(*ivrq, f, io_flags);
|
|
3013
3250
|
idx = std::move(ivrq);
|
|
3014
3251
|
}
|
|
3252
|
+
#ifdef FAISS_ENABLE_DISK_IVF
|
|
3253
|
+
else if (h == fourcc("IwDr")) {
|
|
3254
|
+
auto ivdr = std::make_unique<IndexIVFRaBitQSSD>();
|
|
3255
|
+
read_ivf_header(ivdr.get(), f);
|
|
3256
|
+
read_RaBitQuantizer(ivdr->rabitq, f, ivdr->d, true);
|
|
3257
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
3258
|
+
ivdr->rabitq.metric_type == ivdr->metric_type,
|
|
3259
|
+
"IndexIVFRaBitQSSD: metric mismatch");
|
|
3260
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
3261
|
+
ivdr->metric_type == METRIC_L2 ||
|
|
3262
|
+
ivdr->metric_type == METRIC_INNER_PRODUCT,
|
|
3263
|
+
"IndexIVFRaBitQSSD: unsupported metric");
|
|
3264
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
3265
|
+
ivdr->rabitq.nb_bits >= 2 && ivdr->rabitq.nb_bits <= 9,
|
|
3266
|
+
"invalid IndexIVFRaBitQSSD nb_bits=%zu",
|
|
3267
|
+
ivdr->rabitq.nb_bits);
|
|
3268
|
+
ivdr->rabitq.code_size =
|
|
3269
|
+
ivdr->rabitq.compute_code_size(ivdr->d, ivdr->rabitq.nb_bits);
|
|
3270
|
+
ivdr->code_size = ivdr->rabitq.code_size;
|
|
3271
|
+
READ1(ivdr->mem_dim);
|
|
3272
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
3273
|
+
ivdr->d > 0 && ivdr->d % 64 == 0,
|
|
3274
|
+
"IndexIVFRaBitQSSD: d must be a positive multiple of 64");
|
|
3275
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
3276
|
+
ivdr->mem_dim >= 64 && ivdr->mem_dim <= size_t(ivdr->d) &&
|
|
3277
|
+
ivdr->mem_dim % 64 == 0,
|
|
3278
|
+
"IndexIVFRaBitQSSD: mem_dim must be a multiple of 64 in [64, d]");
|
|
3279
|
+
READ1_BOOL(ivdr->use_hacc);
|
|
3280
|
+
READ1(ivdr->drain_alpha);
|
|
3281
|
+
READ1(ivdr->qd_per_thread);
|
|
3282
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
3283
|
+
ivdr->drain_alpha >= 0 && ivdr->drain_alpha <= 1,
|
|
3284
|
+
"invalid IndexIVFRaBitQSSD drain_alpha=%g",
|
|
3285
|
+
ivdr->drain_alpha);
|
|
3286
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
3287
|
+
ivdr->qd_per_thread >= 1 &&
|
|
3288
|
+
ivdr->qd_per_thread <=
|
|
3289
|
+
IndexIVFRaBitQSSD::kMaxReadsInFlight,
|
|
3290
|
+
"invalid IndexIVFRaBitQSSD qd_per_thread=%zu",
|
|
3291
|
+
ivdr->qd_per_thread);
|
|
3292
|
+
READVECTOR(ivdr->centroid_norms);
|
|
3293
|
+
FAISS_THROW_IF_NOT(
|
|
3294
|
+
ivdr->centroid_norms.empty() ||
|
|
3295
|
+
ivdr->centroid_norms.size() == ivdr->nlist);
|
|
3296
|
+
READVECTOR(ivdr->centroid_scales);
|
|
3297
|
+
FAISS_THROW_IF_NOT(
|
|
3298
|
+
ivdr->centroid_scales.empty() ||
|
|
3299
|
+
ivdr->centroid_scales.size() == ivdr->nlist);
|
|
3300
|
+
read_InvertedLists(*ivdr, f, io_flags);
|
|
3301
|
+
if (ivdr->invlists) {
|
|
3302
|
+
// checks the type and the layout of the inverted lists
|
|
3303
|
+
ivdr->get_ssd_invlists();
|
|
3304
|
+
// the search accepts empty centroid_norms when ntotal is 0. ntotal
|
|
3305
|
+
// can exceed the list sizes: add() counts the vectors it skips
|
|
3306
|
+
// (coarse list -1).
|
|
3307
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
3308
|
+
size_t(ivdr->ntotal) >= ivdr->invlists->compute_ntotal(),
|
|
3309
|
+
"IndexIVFRaBitQSSD: the inverted lists hold more than ntotal vectors");
|
|
3310
|
+
} else {
|
|
3311
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
3312
|
+
ivdr->ntotal == 0,
|
|
3313
|
+
"IndexIVFRaBitQSSD: non-empty index needs inverted lists");
|
|
3314
|
+
}
|
|
3315
|
+
idx = std::move(ivdr);
|
|
3316
|
+
}
|
|
3317
|
+
#endif // FAISS_ENABLE_DISK_IVF
|
|
3015
3318
|
#ifdef FAISS_ENABLE_SVS
|
|
3016
3319
|
else if (
|
|
3017
3320
|
h == fourcc("ILVQ") || h == fourcc("ISVL") || h == fourcc("ISVD") ||
|
|
@@ -3310,7 +3613,8 @@ static void read_InvertedLists(IndexBinaryIVF& ivf, IOReader* f, int io_flags) {
|
|
|
3310
3613
|
auto ils = read_InvertedLists_up(f, io_flags);
|
|
3311
3614
|
FAISS_THROW_IF_NOT(
|
|
3312
3615
|
!ils ||
|
|
3313
|
-
(ils->nlist == ivf.nlist &&
|
|
3616
|
+
(ils->nlist == ivf.nlist &&
|
|
3617
|
+
ils->code_size == static_cast<size_t>(ivf.code_size)));
|
|
3314
3618
|
ivf.invlists = ils.release();
|
|
3315
3619
|
ivf.own_invlists = true;
|
|
3316
3620
|
}
|
|
@@ -3421,6 +3725,10 @@ static void read_binary_multi_hash_map(
|
|
|
3421
3725
|
int id_bits;
|
|
3422
3726
|
size_t sz;
|
|
3423
3727
|
READ1(id_bits);
|
|
3728
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
3729
|
+
id_bits >= 0 && id_bits <= 64,
|
|
3730
|
+
"multi hash map: invalid id_bits=%d (must be in [0, 64])",
|
|
3731
|
+
id_bits);
|
|
3424
3732
|
READ1(sz);
|
|
3425
3733
|
FAISS_CHECK_DESERIALIZATION_LOOP_LIMIT(sz, "multi hash map sz");
|
|
3426
3734
|
std::vector<uint8_t> buf;
|
|
@@ -3540,9 +3848,9 @@ std::unique_ptr<IndexBinary> read_index_binary_up(IOReader* f, int io_flags) {
|
|
|
3540
3848
|
read_index_binary_header(*idxmap, f);
|
|
3541
3849
|
idxmap->index = read_index_binary(f, io_flags);
|
|
3542
3850
|
idxmap->own_fields = true;
|
|
3543
|
-
|
|
3851
|
+
read_vector(idxmap->id_map, f);
|
|
3544
3852
|
FAISS_THROW_IF_NOT_FMT(
|
|
3545
|
-
idxmap->id_map.size() == idxmap->ntotal,
|
|
3853
|
+
idxmap->id_map.size() == static_cast<size_t>(idxmap->ntotal),
|
|
3546
3854
|
"IndexBinaryIDMap id_map size (%" PRId64
|
|
3547
3855
|
") does not match ntotal (%" PRId64 ")",
|
|
3548
3856
|
int64_t(idxmap->id_map.size()),
|
|
@@ -3566,7 +3874,8 @@ std::unique_ptr<IndexBinary> read_index_binary_up(IOReader* f, int io_flags) {
|
|
|
3566
3874
|
"invalid IndexBinaryHash b=%d (must be > 0)",
|
|
3567
3875
|
idxh->b);
|
|
3568
3876
|
FAISS_THROW_IF_NOT_FMT(
|
|
3569
|
-
static_cast<
|
|
3877
|
+
static_cast<int64_t>(idxh->b) <=
|
|
3878
|
+
static_cast<int64_t>(idxh->code_size) * 8,
|
|
3570
3879
|
"IndexBinaryHash b=%d exceeds code_size=%d bits",
|
|
3571
3880
|
idxh->b,
|
|
3572
3881
|
idxh->code_size);
|