faiss 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/ext/faiss/extconf.rb +2 -1
- data/ext/faiss/{index_rb.cpp → index.cpp} +1 -1
- data/ext/faiss/index_binary.cpp +1 -1
- data/ext/faiss/kmeans.cpp +1 -1
- data/ext/faiss/pca_matrix.cpp +1 -1
- data/ext/faiss/product_quantizer.cpp +1 -1
- data/ext/faiss/{utils_rb.cpp → utils.cpp} +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +93 -80
- data/vendor/faiss/faiss/Clustering.cpp +39 -240
- data/vendor/faiss/faiss/Clustering.h +6 -0
- data/vendor/faiss/faiss/IVFlib.cpp +41 -21
- data/vendor/faiss/faiss/Index.cpp +6 -5
- data/vendor/faiss/faiss/Index.h +5 -5
- data/vendor/faiss/faiss/Index2Layer.cpp +37 -53
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +49 -37
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +36 -34
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +4 -1
- data/vendor/faiss/faiss/IndexBinary.cpp +5 -3
- data/vendor/faiss/faiss/IndexBinary.h +4 -4
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +1 -1
- data/vendor/faiss/faiss/IndexBinaryFlat.h +1 -1
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +4 -4
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +84 -92
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +9 -3
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +45 -236
- data/vendor/faiss/faiss/IndexBinaryHash.h +6 -6
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +87 -415
- data/vendor/faiss/faiss/IndexFastScan.cpp +72 -109
- data/vendor/faiss/faiss/IndexFastScan.h +25 -23
- data/vendor/faiss/faiss/IndexFlat.cpp +27 -20
- data/vendor/faiss/faiss/IndexFlat.h +21 -18
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +42 -19
- data/vendor/faiss/faiss/IndexHNSW.cpp +283 -145
- data/vendor/faiss/faiss/IndexHNSW.h +16 -2
- data/vendor/faiss/faiss/IndexIDMap.cpp +25 -21
- data/vendor/faiss/faiss/IndexIDMap.h +9 -7
- data/vendor/faiss/faiss/IndexIVF.cpp +465 -362
- data/vendor/faiss/faiss/IndexIVF.h +33 -12
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +77 -74
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +96 -93
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +4 -1
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +357 -238
- data/vendor/faiss/faiss/IndexIVFFastScan.h +42 -41
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +36 -68
- data/vendor/faiss/faiss/IndexIVFFlat.h +32 -0
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.cpp +53 -30
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.h +3 -1
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.cpp +18 -15
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +71 -843
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +151 -121
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +3 -0
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +21 -17
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +26 -39
- data/vendor/faiss/faiss/IndexIVFRaBitQ.h +2 -1
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +475 -476
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +248 -93
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +41 -127
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +1 -1
- data/vendor/faiss/faiss/IndexLSH.cpp +36 -19
- data/vendor/faiss/faiss/IndexLattice.cpp +13 -13
- data/vendor/faiss/faiss/IndexNNDescent.cpp +36 -21
- data/vendor/faiss/faiss/IndexNNDescent.h +2 -2
- data/vendor/faiss/faiss/IndexNSG.cpp +39 -23
- data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +31 -11
- data/vendor/faiss/faiss/IndexPQ.cpp +128 -221
- data/vendor/faiss/faiss/IndexPQ.h +3 -2
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +20 -14
- data/vendor/faiss/faiss/IndexPQFastScan.h +3 -0
- data/vendor/faiss/faiss/IndexPreTransform.cpp +25 -18
- data/vendor/faiss/faiss/IndexPreTransform.h +1 -1
- data/vendor/faiss/faiss/IndexRaBitQ.cpp +11 -36
- data/vendor/faiss/faiss/IndexRaBitQ.h +2 -1
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +41 -277
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +183 -27
- data/vendor/faiss/faiss/IndexRefine.cpp +30 -25
- data/vendor/faiss/faiss/IndexRefine.h +4 -4
- data/vendor/faiss/faiss/IndexReplicas.cpp +6 -6
- data/vendor/faiss/faiss/IndexRowwiseMinMax.cpp +15 -14
- data/vendor/faiss/faiss/IndexRowwiseMinMax.h +1 -1
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +82 -14
- data/vendor/faiss/faiss/IndexShards.cpp +10 -9
- data/vendor/faiss/faiss/IndexShardsIVF.cpp +21 -15
- data/vendor/faiss/faiss/MatrixStats.cpp +5 -4
- data/vendor/faiss/faiss/MetaIndexes.cpp +19 -17
- data/vendor/faiss/faiss/MetaIndexes.h +1 -1
- data/vendor/faiss/faiss/MetricType.h +14 -7
- data/vendor/faiss/faiss/SuperKMeans.cpp +656 -0
- data/vendor/faiss/faiss/SuperKMeans.h +97 -0
- data/vendor/faiss/faiss/VectorTransform.cpp +237 -149
- data/vendor/faiss/faiss/VectorTransform.h +16 -16
- data/vendor/faiss/faiss/build.cpp +23 -0
- data/vendor/faiss/faiss/build.h +15 -0
- data/vendor/faiss/faiss/clone_index.cpp +48 -47
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +47 -47
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +11 -0
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-avx2-inl.h +38 -38
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-inl.h +11 -0
- data/vendor/faiss/faiss/factory_tools.cpp +5 -0
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +6 -5
- data/vendor/faiss/faiss/gpu/GpuResources.h +1 -1
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +9 -9
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +4 -3
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +46 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +56 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +78 -1
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +72 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +23 -0
- data/vendor/faiss/faiss/gpu/utils/CuvsFilterConvert.h +1 -1
- data/vendor/faiss/faiss/gpu/utils/CuvsUtils.h +21 -10
- data/vendor/faiss/faiss/gpu_metal/GpuIndexFlat.h +22 -0
- data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +35 -0
- data/vendor/faiss/faiss/gpu_metal/MetalFlatKernels.h +40 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +51 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndexFlat.h +65 -0
- data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +66 -0
- data/vendor/faiss/faiss/gpu_metal/MetalResources.h +79 -0
- data/vendor/faiss/faiss/gpu_metal/StandardMetalResources.h +35 -0
- data/vendor/faiss/faiss/impl/AdSampling.cpp +103 -0
- data/vendor/faiss/faiss/impl/AdSampling.h +35 -0
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +29 -25
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +1 -0
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +10 -9
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +3 -0
- data/vendor/faiss/faiss/impl/ClusteringHelpers.cpp +244 -0
- data/vendor/faiss/faiss/impl/ClusteringHelpers.h +94 -0
- data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +16 -16
- data/vendor/faiss/faiss/impl/CodePacker.cpp +3 -3
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +1 -1
- data/vendor/faiss/faiss/impl/DistanceComputer.h +8 -8
- data/vendor/faiss/faiss/impl/FaissAssert.h +6 -3
- data/vendor/faiss/faiss/impl/FaissException.h +50 -3
- data/vendor/faiss/faiss/impl/HNSW.cpp +92 -317
- data/vendor/faiss/faiss/impl/HNSW.h +13 -34
- data/vendor/faiss/faiss/impl/IDSelector.cpp +15 -11
- data/vendor/faiss/faiss/impl/IDSelector.h +8 -8
- data/vendor/faiss/faiss/impl/InvertedListScannerStats.h +26 -0
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +82 -77
- data/vendor/faiss/faiss/impl/NNDescent.cpp +62 -25
- data/vendor/faiss/faiss/impl/NNDescent.h +6 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +38 -21
- data/vendor/faiss/faiss/impl/NSG.h +4 -4
- data/vendor/faiss/faiss/impl/Panorama.cpp +23 -6
- data/vendor/faiss/faiss/impl/Panorama.h +258 -87
- data/vendor/faiss/faiss/impl/PdxLayout.cpp +93 -0
- data/vendor/faiss/faiss/impl/PdxLayout.h +41 -0
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +46 -32
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +3 -3
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +35 -35
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +21 -16
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +30 -23
- data/vendor/faiss/faiss/impl/Quantizer.h +2 -2
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +55 -49
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +65 -0
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +296 -283
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +26 -23
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ResultHandler.h +99 -75
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +52 -4
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +27 -1
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +14 -11
- data/vendor/faiss/faiss/impl/VisitedTable.h +7 -0
- data/vendor/faiss/faiss/impl/approx_topk/approx_topk.h +276 -0
- data/vendor/faiss/faiss/impl/approx_topk/avx2.cpp +68 -0
- data/vendor/faiss/faiss/{utils → impl}/approx_topk/generic.h +15 -8
- data/vendor/faiss/faiss/impl/approx_topk/neon.cpp +68 -0
- data/vendor/faiss/faiss/impl/approx_topk/rq_beam_search_tab-inl.h +169 -0
- data/vendor/faiss/faiss/impl/approx_topk/rq_beam_search_tab.h +117 -0
- data/vendor/faiss/faiss/impl/approx_topk/simdlib256-inl.h +146 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHNSW_impl.h +73 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHash_impl.h +270 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryIVF_impl.h +460 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexIVFSpectralHash_impl.h +159 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexPQ_impl.h +92 -0
- data/vendor/faiss/faiss/impl/binary_hamming/avx2.cpp +26 -0
- data/vendor/faiss/faiss/impl/binary_hamming/avx512.cpp +26 -0
- data/vendor/faiss/faiss/impl/binary_hamming/dispatch.h +143 -0
- data/vendor/faiss/faiss/impl/binary_hamming/neon.cpp +26 -0
- data/vendor/faiss/faiss/impl/binary_hamming/rvv.cpp +26 -0
- data/vendor/faiss/faiss/impl/expanded_scanners.h +8 -3
- data/vendor/faiss/faiss/impl/{FastScanDistancePostProcessing.h → fast_scan/FastScanDistancePostProcessing.h} +13 -6
- data/vendor/faiss/faiss/impl/{LookupTableScaler.h → fast_scan/LookupTableScaler.h} +16 -5
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops.h +237 -0
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops_512.h +185 -0
- data/vendor/faiss/faiss/impl/fast_scan/decompose_qbs.h +229 -0
- data/vendor/faiss/faiss/impl/fast_scan/dispatching.h +268 -0
- data/vendor/faiss/faiss/impl/{pq4_fast_scan.cpp → fast_scan/fast_scan.cpp} +169 -2
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.h +341 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +36 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +40 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +120 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-riscv.cpp +104 -0
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd256.h +213 -0
- data/vendor/faiss/faiss/impl/{pq4_fast_scan_search_qbs.cpp → fast_scan/kernels_simd512.h} +26 -356
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_dispatching.h +90 -0
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_result_handler.h +108 -0
- data/vendor/faiss/faiss/impl/{simd_result_handlers.h → fast_scan/simd_result_handlers.h} +282 -134
- data/vendor/faiss/faiss/impl/hnsw/LockVector.cpp +54 -0
- data/vendor/faiss/faiss/impl/hnsw/LockVector.h +64 -0
- data/vendor/faiss/faiss/impl/hnsw/MinimaxHeap.cpp +91 -0
- data/vendor/faiss/faiss/impl/hnsw/MinimaxHeap.h +64 -0
- data/vendor/faiss/faiss/impl/hnsw/avx2.cpp +104 -0
- data/vendor/faiss/faiss/impl/hnsw/avx512.cpp +111 -0
- data/vendor/faiss/faiss/impl/index_read.cpp +1132 -45
- data/vendor/faiss/faiss/impl/index_read_utils.h +1 -1
- data/vendor/faiss/faiss/impl/index_write.cpp +95 -13
- data/vendor/faiss/faiss/impl/io.cpp +6 -6
- data/vendor/faiss/faiss/impl/io_macros.h +33 -16
- data/vendor/faiss/faiss/impl/kmeans1d.cpp +10 -10
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +37 -23
- data/vendor/faiss/faiss/impl/lattice_Zn.h +6 -6
- data/vendor/faiss/faiss/impl/mapped_io.cpp +6 -6
- data/vendor/faiss/faiss/impl/platform_macros.h +11 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +549 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.cpp +245 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.h +105 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/PQDistanceComputer_impl.h +106 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx2.cpp +21 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx512.cpp +21 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/neon.cpp +21 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/{pq_code_distance-avx2.cpp → pq_code_distance-avx2.h} +9 -13
- data/vendor/faiss/faiss/impl/pq_code_distance/{pq_code_distance-avx512.cpp → pq_code_distance-avx512.h} +9 -57
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.cpp +29 -111
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.h +96 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-inl.h +238 -5
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-sve.cpp +5 -7
- data/vendor/faiss/faiss/impl/pq_code_distance/rvv.cpp +68 -0
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +311 -477
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/codecs.h +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +3 -2
- data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +102 -11
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +27 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/similarities.h +3 -3
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +148 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +167 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +59 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +163 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-rvv.cpp +311 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.cpp +192 -8
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.h +12 -0
- data/vendor/faiss/faiss/impl/simd_dispatch.h +100 -66
- data/vendor/faiss/faiss/impl/simdlib/simdlib.h +57 -0
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_avx2.h +264 -172
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx512.h +414 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_dispatch.h +44 -0
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_emulated.h +231 -166
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_neon.h +270 -218
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_ppc64.h +201 -160
- data/vendor/faiss/faiss/impl/svs_io.cpp +12 -3
- data/vendor/faiss/faiss/impl/svs_io.h +8 -2
- data/vendor/faiss/faiss/index_factory.cpp +86 -18
- data/vendor/faiss/faiss/index_io.h +24 -0
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +66 -16
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +24 -14
- data/vendor/faiss/faiss/invlists/DirectMap.h +4 -3
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +157 -73
- data/vendor/faiss/faiss/invlists/InvertedLists.h +86 -23
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +4 -4
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +13 -13
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +2 -2
- data/vendor/faiss/faiss/svs/IndexSVSIVF.cpp +350 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVF.h +128 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLVQ.cpp +40 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLVQ.h +43 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLeanVec.cpp +225 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLeanVec.h +71 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +25 -1
- data/vendor/faiss/faiss/svs/IndexSVSVamana.h +18 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.cpp +12 -3
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.h +7 -2
- data/vendor/faiss/faiss/utils/Heap.cpp +10 -10
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +47 -36
- data/vendor/faiss/faiss/utils/NeuralNet.h +1 -1
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +10 -4
- data/vendor/faiss/faiss/utils/distances.cpp +390 -560
- data/vendor/faiss/faiss/utils/distances.h +20 -1
- data/vendor/faiss/faiss/utils/distances_dispatch.h +117 -37
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +8 -7
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +33 -14
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.h +12 -1
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +16 -293
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based_neon.cpp +57 -0
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_kernel-inl.h +290 -0
- data/vendor/faiss/faiss/utils/distances_simd.cpp +5 -177
- data/vendor/faiss/faiss/utils/extra_distances.cpp +9 -8
- data/vendor/faiss/faiss/utils/extra_distances.h +32 -6
- data/vendor/faiss/faiss/utils/hamming-inl.h +13 -11
- data/vendor/faiss/faiss/utils/hamming.cpp +66 -517
- data/vendor/faiss/faiss/utils/hamming.h +92 -2
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +287 -10
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx2.cpp +15 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512.cpp +15 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx2.h +142 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512.h +234 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-generic.h +368 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-neon.h +322 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-rvv.h +39 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer.h +146 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_impl.h +481 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_neon.cpp +15 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_rvv.cpp +15 -0
- data/vendor/faiss/faiss/utils/partitioning.cpp +66 -987
- data/vendor/faiss/faiss/utils/partitioning.h +31 -0
- data/vendor/faiss/faiss/utils/popcount.h +29 -0
- data/vendor/faiss/faiss/utils/pq_code_distance.h +2 -2
- data/vendor/faiss/faiss/utils/prefetch.h +2 -2
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +30 -30
- data/vendor/faiss/faiss/utils/quantize_lut.h +1 -1
- data/vendor/faiss/faiss/utils/rabitq_simd.h +57 -536
- data/vendor/faiss/faiss/utils/random.cpp +6 -6
- data/vendor/faiss/faiss/utils/simd_impl/IVFFlatScanner-inl.h +51 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_aarch64.cpp +5 -1
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +213 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +163 -10
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +250 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +7 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv.cpp +189 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_simdlib256.h +195 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_sse-inl.h +2 -1
- data/vendor/faiss/faiss/utils/{distances_fused/simdlib_based.h → simd_impl/exhaustive_L2sqr_blas_cmax.h} +5 -10
- data/vendor/faiss/faiss/utils/simd_impl/hamming_impl.h +481 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_avx2.cpp +14 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_neon.cpp +14 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_simdlib256.h +1085 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp +355 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +477 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_neon.cpp +55 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_rvv.cpp +55 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_dispatch.h +32 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels.h +43 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx2.cpp +57 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx512.cpp +45 -0
- data/vendor/faiss/faiss/utils/simd_levels.cpp +17 -5
- data/vendor/faiss/faiss/utils/simd_levels.h +93 -1
- data/vendor/faiss/faiss/utils/sorting.cpp +48 -36
- data/vendor/faiss/faiss/utils/utils.cpp +5 -5
- data/vendor/faiss/faiss/utils/utils.h +3 -3
- metadata +119 -34
- data/vendor/faiss/faiss/impl/RaBitQStats.cpp +0 -29
- data/vendor/faiss/faiss/impl/RaBitQStats.h +0 -56
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +0 -224
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +0 -230
- data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +0 -84
- data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +0 -196
- data/vendor/faiss/faiss/utils/approx_topk/mode.h +0 -34
- data/vendor/faiss/faiss/utils/distances_fused/avx512.h +0 -36
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +0 -235
- data/vendor/faiss/faiss/utils/hamming_distance/avx2-inl.h +0 -462
- data/vendor/faiss/faiss/utils/hamming_distance/avx512-inl.h +0 -490
- data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +0 -449
- data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +0 -87
- data/vendor/faiss/faiss/utils/hamming_distance/neon-inl.h +0 -524
- data/vendor/faiss/faiss/utils/simdlib.h +0 -42
- data/vendor/faiss/faiss/utils/simdlib_avx512.h +0 -365
- /data/ext/faiss/{utils_rb.h → utils.h} +0 -0
|
@@ -21,8 +21,8 @@ InvertedListsIterator::~InvertedListsIterator() {}
|
|
|
21
21
|
* InvertedLists implementation
|
|
22
22
|
******************************************/
|
|
23
23
|
|
|
24
|
-
InvertedLists::InvertedLists(size_t
|
|
25
|
-
: nlist(
|
|
24
|
+
InvertedLists::InvertedLists(size_t nlist_, size_t code_size_)
|
|
25
|
+
: nlist(nlist_), code_size(code_size_) {}
|
|
26
26
|
|
|
27
27
|
InvertedLists::~InvertedLists() {}
|
|
28
28
|
|
|
@@ -70,7 +70,7 @@ void InvertedLists::reset() {
|
|
|
70
70
|
|
|
71
71
|
void InvertedLists::merge_from(InvertedLists* oivf, size_t add_id) {
|
|
72
72
|
#pragma omp parallel for
|
|
73
|
-
for (idx_t i = 0; i < nlist; i++) {
|
|
73
|
+
for (idx_t i = 0; i < static_cast<idx_t>(nlist); i++) {
|
|
74
74
|
size_t list_size = oivf->list_size(i);
|
|
75
75
|
ScopedIds ids(oivf, i);
|
|
76
76
|
if (add_id == 0) {
|
|
@@ -109,12 +109,12 @@ size_t InvertedLists::copy_subset_to(
|
|
|
109
109
|
ntotal = compute_ntotal();
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
for (
|
|
112
|
+
for (size_t list_no = 0; list_no < nlist; list_no++) {
|
|
113
113
|
size_t n = list_size(list_no);
|
|
114
114
|
ScopedIds ids_in(this, list_no);
|
|
115
115
|
|
|
116
116
|
if (subset_type == SUBSET_TYPE_ID_RANGE) {
|
|
117
|
-
for (
|
|
117
|
+
for (size_t i = 0; i < n; i++) {
|
|
118
118
|
idx_t id = ids_in[i];
|
|
119
119
|
if (a1 <= id && id < a2) {
|
|
120
120
|
oivf.add_entry(
|
|
@@ -125,7 +125,7 @@ size_t InvertedLists::copy_subset_to(
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
} else if (subset_type == SUBSET_TYPE_ID_MOD) {
|
|
128
|
-
for (
|
|
128
|
+
for (size_t i = 0; i < n; i++) {
|
|
129
129
|
idx_t id = ids_in[i];
|
|
130
130
|
if (id % a1 == a2) {
|
|
131
131
|
oivf.add_entry(
|
|
@@ -143,7 +143,7 @@ size_t InvertedLists::copy_subset_to(
|
|
|
143
143
|
size_t next_accu_a2 = next_accu_n * a2 / ntotal;
|
|
144
144
|
size_t i2 = next_accu_a2 - accu_a2;
|
|
145
145
|
|
|
146
|
-
for (
|
|
146
|
+
for (size_t i = i1; i < i2; i++) {
|
|
147
147
|
oivf.add_entry(
|
|
148
148
|
list_no,
|
|
149
149
|
get_single_id(list_no, i),
|
|
@@ -157,7 +157,7 @@ size_t InvertedLists::copy_subset_to(
|
|
|
157
157
|
size_t i1 = n * a2 / a1;
|
|
158
158
|
size_t i2 = n * (a2 + 1) / a1;
|
|
159
159
|
|
|
160
|
-
for (
|
|
160
|
+
for (size_t i = i1; i < i2; i++) {
|
|
161
161
|
oivf.add_entry(
|
|
162
162
|
list_no,
|
|
163
163
|
get_single_id(list_no, i),
|
|
@@ -166,7 +166,8 @@ size_t InvertedLists::copy_subset_to(
|
|
|
166
166
|
|
|
167
167
|
n_added += i2 - i1;
|
|
168
168
|
} else if (subset_type == SUBSET_TYPE_INVLIST) {
|
|
169
|
-
if (list_no >= a1 &&
|
|
169
|
+
if (static_cast<idx_t>(list_no) >= a1 &&
|
|
170
|
+
static_cast<idx_t>(list_no) < a2) {
|
|
170
171
|
oivf.add_entries(
|
|
171
172
|
list_no,
|
|
172
173
|
n,
|
|
@@ -269,10 +270,10 @@ InvertedListsIterator* InvertedLists::get_iterator(
|
|
|
269
270
|
* ArrayInvertedLists implementation
|
|
270
271
|
******************************************/
|
|
271
272
|
|
|
272
|
-
ArrayInvertedLists::ArrayInvertedLists(size_t
|
|
273
|
-
: InvertedLists(
|
|
274
|
-
ids.resize(
|
|
275
|
-
codes.resize(
|
|
273
|
+
ArrayInvertedLists::ArrayInvertedLists(size_t nlist_in, size_t code_size_in)
|
|
274
|
+
: InvertedLists(nlist_in, code_size_in) {
|
|
275
|
+
ids.resize(nlist_in);
|
|
276
|
+
codes.resize(nlist_in);
|
|
276
277
|
}
|
|
277
278
|
|
|
278
279
|
size_t ArrayInvertedLists::add_entries(
|
|
@@ -288,7 +289,9 @@ size_t ArrayInvertedLists::add_entries(
|
|
|
288
289
|
ids[list_no].resize(o + n_entry);
|
|
289
290
|
memcpy(&ids[list_no][o], ids_in, sizeof(ids_in[0]) * n_entry);
|
|
290
291
|
codes[list_no].resize((o + n_entry) * code_size);
|
|
291
|
-
|
|
292
|
+
if (code_size > 0) {
|
|
293
|
+
memcpy(&codes[list_no][o * code_size], code, code_size * n_entry);
|
|
294
|
+
}
|
|
292
295
|
return o;
|
|
293
296
|
}
|
|
294
297
|
|
|
@@ -327,7 +330,11 @@ void ArrayInvertedLists::update_entries(
|
|
|
327
330
|
assert(list_no < nlist);
|
|
328
331
|
assert(n_entry + offset <= ids[list_no].size());
|
|
329
332
|
memcpy(&ids[list_no][offset], ids_in, sizeof(ids_in[0]) * n_entry);
|
|
330
|
-
|
|
333
|
+
if (code_size > 0) {
|
|
334
|
+
memcpy(&codes[list_no][offset * code_size],
|
|
335
|
+
codes_in,
|
|
336
|
+
code_size * n_entry);
|
|
337
|
+
}
|
|
331
338
|
}
|
|
332
339
|
|
|
333
340
|
void ArrayInvertedLists::permute_invlists(const idx_t* map) {
|
|
@@ -351,23 +358,25 @@ ArrayInvertedLists::~ArrayInvertedLists() {}
|
|
|
351
358
|
**********************************************/
|
|
352
359
|
|
|
353
360
|
ArrayInvertedListsPanorama::ArrayInvertedListsPanorama(
|
|
354
|
-
size_t
|
|
355
|
-
size_t
|
|
356
|
-
size_t
|
|
357
|
-
|
|
358
|
-
|
|
361
|
+
size_t nlist_in,
|
|
362
|
+
size_t code_size_in,
|
|
363
|
+
size_t n_levels_in,
|
|
364
|
+
size_t batch_size)
|
|
365
|
+
: ArrayInvertedLists(nlist_in, code_size_in),
|
|
366
|
+
n_levels(n_levels_in),
|
|
359
367
|
level_width(
|
|
360
|
-
(((
|
|
368
|
+
(((code_size_in / sizeof(float)) + n_levels_in - 1) /
|
|
369
|
+
n_levels_in) *
|
|
361
370
|
sizeof(float)),
|
|
362
|
-
pano(
|
|
363
|
-
FAISS_THROW_IF_NOT(
|
|
364
|
-
FAISS_THROW_IF_NOT(
|
|
371
|
+
pano(code_size_in, n_levels_in, batch_size) {
|
|
372
|
+
FAISS_THROW_IF_NOT(n_levels_in > 0);
|
|
373
|
+
FAISS_THROW_IF_NOT(code_size_in % sizeof(float) == 0);
|
|
365
374
|
FAISS_THROW_IF_NOT_MSG(
|
|
366
375
|
!use_iterator,
|
|
367
376
|
"IndexIVFFlatPanorama does not support iterators, use vanilla IndexIVFFlat instead");
|
|
368
377
|
FAISS_ASSERT(level_width % sizeof(float) == 0);
|
|
369
378
|
|
|
370
|
-
cum_sums.resize(
|
|
379
|
+
cum_sums.resize(nlist_in);
|
|
371
380
|
}
|
|
372
381
|
|
|
373
382
|
const float* ArrayInvertedListsPanorama::get_cum_sums(size_t list_no) const {
|
|
@@ -387,9 +396,9 @@ size_t ArrayInvertedListsPanorama::add_entries(
|
|
|
387
396
|
memcpy(&ids[list_no][o], ids_in, sizeof(ids_in[0]) * n_entry);
|
|
388
397
|
|
|
389
398
|
size_t new_size = o + n_entry;
|
|
390
|
-
size_t num_batches = (new_size +
|
|
391
|
-
codes[list_no].resize(num_batches *
|
|
392
|
-
cum_sums[list_no].resize(num_batches *
|
|
399
|
+
size_t num_batches = (new_size + pano.batch_size - 1) / pano.batch_size;
|
|
400
|
+
codes[list_no].resize(num_batches * pano.batch_size * code_size);
|
|
401
|
+
cum_sums[list_no].resize(num_batches * pano.batch_size * (n_levels + 1));
|
|
393
402
|
|
|
394
403
|
// Cast to float* is safe here as we guarantee codes are always float
|
|
395
404
|
// vectors for `IndexIVFFlatPanorama` (verified by the constructor).
|
|
@@ -423,9 +432,9 @@ void ArrayInvertedListsPanorama::update_entries(
|
|
|
423
432
|
void ArrayInvertedListsPanorama::resize(size_t list_no, size_t new_size) {
|
|
424
433
|
ids[list_no].resize(new_size);
|
|
425
434
|
|
|
426
|
-
size_t num_batches = (new_size +
|
|
427
|
-
codes[list_no].resize(num_batches *
|
|
428
|
-
cum_sums[list_no].resize(num_batches *
|
|
435
|
+
size_t num_batches = (new_size + pano.batch_size - 1) / pano.batch_size;
|
|
436
|
+
codes[list_no].resize(num_batches * pano.batch_size * code_size);
|
|
437
|
+
cum_sums[list_no].resize(num_batches * pano.batch_size * (n_levels + 1));
|
|
429
438
|
}
|
|
430
439
|
|
|
431
440
|
const uint8_t* ArrayInvertedListsPanorama::get_single_code(
|
|
@@ -444,11 +453,11 @@ const uint8_t* ArrayInvertedListsPanorama::get_single_code(
|
|
|
444
453
|
|
|
445
454
|
void ArrayInvertedListsPanorama::release_codes(
|
|
446
455
|
size_t list_no,
|
|
447
|
-
const uint8_t*
|
|
456
|
+
const uint8_t* codes_in) const {
|
|
448
457
|
// Only delete if it's heap-allocated (from get_single_code).
|
|
449
458
|
// If it's from get_codes (raw storage), it will be codes[list_no].data()
|
|
450
|
-
if (
|
|
451
|
-
delete[]
|
|
459
|
+
if (codes_in != this->codes[list_no].data()) {
|
|
460
|
+
delete[] codes_in;
|
|
452
461
|
}
|
|
453
462
|
}
|
|
454
463
|
|
|
@@ -503,7 +512,7 @@ HStackInvertedLists::HStackInvertedLists(int nil, const InvertedLists** ils_in)
|
|
|
503
512
|
|
|
504
513
|
size_t HStackInvertedLists::list_size(size_t list_no) const {
|
|
505
514
|
size_t sz = 0;
|
|
506
|
-
for (
|
|
515
|
+
for (size_t i = 0; i < ils.size(); i++) {
|
|
507
516
|
const InvertedLists* il = ils[i];
|
|
508
517
|
sz += il->list_size(list_no);
|
|
509
518
|
}
|
|
@@ -513,7 +522,7 @@ size_t HStackInvertedLists::list_size(size_t list_no) const {
|
|
|
513
522
|
const uint8_t* HStackInvertedLists::get_codes(size_t list_no) const {
|
|
514
523
|
uint8_t *codes = new uint8_t[code_size * list_size(list_no)], *c = codes;
|
|
515
524
|
|
|
516
|
-
for (
|
|
525
|
+
for (size_t i = 0; i < ils.size(); i++) {
|
|
517
526
|
const InvertedLists* il = ils[i];
|
|
518
527
|
size_t sz = il->list_size(list_no) * code_size;
|
|
519
528
|
if (sz > 0) {
|
|
@@ -527,7 +536,7 @@ const uint8_t* HStackInvertedLists::get_codes(size_t list_no) const {
|
|
|
527
536
|
const uint8_t* HStackInvertedLists::get_single_code(
|
|
528
537
|
size_t list_no,
|
|
529
538
|
size_t offset) const {
|
|
530
|
-
for (
|
|
539
|
+
for (size_t i = 0; i < ils.size(); i++) {
|
|
531
540
|
const InvertedLists* il = ils[i];
|
|
532
541
|
size_t sz = il->list_size(list_no);
|
|
533
542
|
if (offset < sz) {
|
|
@@ -548,7 +557,7 @@ void HStackInvertedLists::release_codes(size_t, const uint8_t* codes) const {
|
|
|
548
557
|
const idx_t* HStackInvertedLists::get_ids(size_t list_no) const {
|
|
549
558
|
idx_t *ids = new idx_t[list_size(list_no)], *c = ids;
|
|
550
559
|
|
|
551
|
-
for (
|
|
560
|
+
for (size_t i = 0; i < ils.size(); i++) {
|
|
552
561
|
const InvertedLists* il = ils[i];
|
|
553
562
|
size_t sz = il->list_size(list_no);
|
|
554
563
|
if (sz > 0) {
|
|
@@ -560,7 +569,7 @@ const idx_t* HStackInvertedLists::get_ids(size_t list_no) const {
|
|
|
560
569
|
}
|
|
561
570
|
|
|
562
571
|
idx_t HStackInvertedLists::get_single_id(size_t list_no, size_t offset) const {
|
|
563
|
-
for (
|
|
572
|
+
for (size_t i = 0; i < ils.size(); i++) {
|
|
564
573
|
const InvertedLists* il = ils[i];
|
|
565
574
|
size_t sz = il->list_size(list_no);
|
|
566
575
|
if (offset < sz) {
|
|
@@ -575,11 +584,11 @@ void HStackInvertedLists::release_ids(size_t, const idx_t* ids) const {
|
|
|
575
584
|
delete[] ids;
|
|
576
585
|
}
|
|
577
586
|
|
|
578
|
-
void HStackInvertedLists::prefetch_lists(const idx_t* list_nos, int
|
|
587
|
+
void HStackInvertedLists::prefetch_lists(const idx_t* list_nos, int nlist_in)
|
|
579
588
|
const {
|
|
580
|
-
for (
|
|
589
|
+
for (size_t i = 0; i < ils.size(); i++) {
|
|
581
590
|
const InvertedLists* il = ils[i];
|
|
582
|
-
il->prefetch_lists(list_nos,
|
|
591
|
+
il->prefetch_lists(list_nos, nlist_in);
|
|
583
592
|
}
|
|
584
593
|
}
|
|
585
594
|
|
|
@@ -590,20 +599,21 @@ void HStackInvertedLists::prefetch_lists(const idx_t* list_nos, int nlist)
|
|
|
590
599
|
namespace {
|
|
591
600
|
|
|
592
601
|
idx_t translate_list_no(const SliceInvertedLists* sil, idx_t list_no) {
|
|
593
|
-
FAISS_THROW_IF_NOT(
|
|
602
|
+
FAISS_THROW_IF_NOT(
|
|
603
|
+
list_no >= 0 && static_cast<size_t>(list_no) < sil->nlist);
|
|
594
604
|
return list_no + sil->i0;
|
|
595
605
|
}
|
|
596
606
|
|
|
597
607
|
} // namespace
|
|
598
608
|
|
|
599
609
|
SliceInvertedLists::SliceInvertedLists(
|
|
600
|
-
const InvertedLists*
|
|
601
|
-
idx_t
|
|
602
|
-
idx_t
|
|
603
|
-
: ReadOnlyInvertedLists(
|
|
604
|
-
il(
|
|
605
|
-
i0(
|
|
606
|
-
i1(
|
|
610
|
+
const InvertedLists* il_,
|
|
611
|
+
idx_t i0_,
|
|
612
|
+
idx_t i1_)
|
|
613
|
+
: ReadOnlyInvertedLists(i1_ - i0_, il_->code_size),
|
|
614
|
+
il(il_),
|
|
615
|
+
i0(i0_),
|
|
616
|
+
i1(i1_) {}
|
|
607
617
|
|
|
608
618
|
size_t SliceInvertedLists::list_size(size_t list_no) const {
|
|
609
619
|
return il->list_size(translate_list_no(this, list_no));
|
|
@@ -636,10 +646,10 @@ void SliceInvertedLists::release_ids(size_t list_no, const idx_t* ids) const {
|
|
|
636
646
|
return il->release_ids(translate_list_no(this, list_no), ids);
|
|
637
647
|
}
|
|
638
648
|
|
|
639
|
-
void SliceInvertedLists::prefetch_lists(const idx_t* list_nos, int
|
|
649
|
+
void SliceInvertedLists::prefetch_lists(const idx_t* list_nos, int nlist_in)
|
|
640
650
|
const {
|
|
641
651
|
std::vector<idx_t> translated_list_nos;
|
|
642
|
-
for (
|
|
652
|
+
for (size_t j = 0; j < static_cast<size_t>(nlist_in); j++) {
|
|
643
653
|
idx_t list_no = list_nos[j];
|
|
644
654
|
if (list_no < 0) {
|
|
645
655
|
continue;
|
|
@@ -657,7 +667,8 @@ namespace {
|
|
|
657
667
|
|
|
658
668
|
// find the invlist this number belongs to
|
|
659
669
|
int translate_list_no(const VStackInvertedLists* vil, idx_t list_no) {
|
|
660
|
-
FAISS_THROW_IF_NOT(
|
|
670
|
+
FAISS_THROW_IF_NOT(
|
|
671
|
+
list_no >= 0 && static_cast<size_t>(list_no) < vil->nlist);
|
|
661
672
|
int i0 = 0, i1 = vil->ils.size();
|
|
662
673
|
const idx_t* cumsz = vil->cumsz.data();
|
|
663
674
|
while (i0 + 1 < i1) {
|
|
@@ -740,11 +751,11 @@ void VStackInvertedLists::release_ids(size_t list_no, const idx_t* ids) const {
|
|
|
740
751
|
return ils[i]->release_ids(list_no, ids);
|
|
741
752
|
}
|
|
742
753
|
|
|
743
|
-
void VStackInvertedLists::prefetch_lists(const idx_t* list_nos, int
|
|
754
|
+
void VStackInvertedLists::prefetch_lists(const idx_t* list_nos, int nlist_in)
|
|
744
755
|
const {
|
|
745
|
-
std::vector<int> ilno(
|
|
756
|
+
std::vector<int> ilno(nlist_in, -1);
|
|
746
757
|
std::vector<int> n_per_il(ils.size(), 0);
|
|
747
|
-
for (int j = 0; j <
|
|
758
|
+
for (int j = 0; j < nlist_in; j++) {
|
|
748
759
|
idx_t list_no = list_nos[j];
|
|
749
760
|
if (list_no < 0) {
|
|
750
761
|
continue;
|
|
@@ -753,11 +764,11 @@ void VStackInvertedLists::prefetch_lists(const idx_t* list_nos, int nlist)
|
|
|
753
764
|
n_per_il[i]++;
|
|
754
765
|
}
|
|
755
766
|
std::vector<int> cum_n_per_il(ils.size() + 1, 0);
|
|
756
|
-
for (
|
|
767
|
+
for (size_t j = 0; j < ils.size(); j++) {
|
|
757
768
|
cum_n_per_il[j + 1] = cum_n_per_il[j] + n_per_il[j];
|
|
758
769
|
}
|
|
759
770
|
std::vector<idx_t> sorted_list_nos(cum_n_per_il.back());
|
|
760
|
-
for (int j = 0; j <
|
|
771
|
+
for (int j = 0; j < nlist_in; j++) {
|
|
761
772
|
idx_t list_no = list_nos[j];
|
|
762
773
|
if (list_no < 0) {
|
|
763
774
|
continue;
|
|
@@ -768,7 +779,7 @@ void VStackInvertedLists::prefetch_lists(const idx_t* list_nos, int nlist)
|
|
|
768
779
|
}
|
|
769
780
|
|
|
770
781
|
int i0 = 0;
|
|
771
|
-
for (
|
|
782
|
+
for (size_t j = 0; j < ils.size(); j++) {
|
|
772
783
|
int i1 = i0 + n_per_il[j];
|
|
773
784
|
if (i1 > i0) {
|
|
774
785
|
ils[j]->prefetch_lists(sorted_list_nos.data() + i0, i1 - i0);
|
|
@@ -782,11 +793,11 @@ void VStackInvertedLists::prefetch_lists(const idx_t* list_nos, int nlist)
|
|
|
782
793
|
******************************************/
|
|
783
794
|
|
|
784
795
|
MaskedInvertedLists::MaskedInvertedLists(
|
|
785
|
-
const InvertedLists*
|
|
786
|
-
const InvertedLists*
|
|
787
|
-
: ReadOnlyInvertedLists(
|
|
788
|
-
il0(
|
|
789
|
-
il1(
|
|
796
|
+
const InvertedLists* il0_in,
|
|
797
|
+
const InvertedLists* il1_in)
|
|
798
|
+
: ReadOnlyInvertedLists(il0_in->nlist, il0_in->code_size),
|
|
799
|
+
il0(il0_in),
|
|
800
|
+
il1(il1_in) {
|
|
790
801
|
FAISS_THROW_IF_NOT(il1->nlist == nlist);
|
|
791
802
|
FAISS_THROW_IF_NOT(il1->code_size == code_size);
|
|
792
803
|
}
|
|
@@ -829,10 +840,10 @@ const uint8_t* MaskedInvertedLists::get_single_code(
|
|
|
829
840
|
return (sz ? il0 : il1)->get_single_code(list_no, offset);
|
|
830
841
|
}
|
|
831
842
|
|
|
832
|
-
void MaskedInvertedLists::prefetch_lists(const idx_t* list_nos, int
|
|
843
|
+
void MaskedInvertedLists::prefetch_lists(const idx_t* list_nos, int nlist_in)
|
|
833
844
|
const {
|
|
834
845
|
std::vector<idx_t> list0, list1;
|
|
835
|
-
for (int i = 0; i <
|
|
846
|
+
for (int i = 0; i < nlist_in; i++) {
|
|
836
847
|
idx_t list_no = list_nos[i];
|
|
837
848
|
if (list_no < 0) {
|
|
838
849
|
continue;
|
|
@@ -849,11 +860,11 @@ void MaskedInvertedLists::prefetch_lists(const idx_t* list_nos, int nlist)
|
|
|
849
860
|
******************************************/
|
|
850
861
|
|
|
851
862
|
StopWordsInvertedLists::StopWordsInvertedLists(
|
|
852
|
-
const InvertedLists*
|
|
853
|
-
size_t
|
|
854
|
-
: ReadOnlyInvertedLists(
|
|
855
|
-
il0(
|
|
856
|
-
maxsize(
|
|
863
|
+
const InvertedLists* il0_in,
|
|
864
|
+
size_t maxsize_in)
|
|
865
|
+
: ReadOnlyInvertedLists(il0_in->nlist, il0_in->code_size),
|
|
866
|
+
il0(il0_in),
|
|
867
|
+
maxsize(maxsize_in) {}
|
|
857
868
|
|
|
858
869
|
size_t StopWordsInvertedLists::list_size(size_t list_no) const {
|
|
859
870
|
size_t sz = il0->list_size(list_no);
|
|
@@ -896,10 +907,10 @@ const uint8_t* StopWordsInvertedLists::get_single_code(
|
|
|
896
907
|
return il0->get_single_code(list_no, offset);
|
|
897
908
|
}
|
|
898
909
|
|
|
899
|
-
void StopWordsInvertedLists::prefetch_lists(const idx_t* list_nos, int
|
|
910
|
+
void StopWordsInvertedLists::prefetch_lists(const idx_t* list_nos, int nlist_in)
|
|
900
911
|
const {
|
|
901
912
|
std::vector<idx_t> list0;
|
|
902
|
-
for (int i = 0; i <
|
|
913
|
+
for (int i = 0; i < nlist_in; i++) {
|
|
903
914
|
idx_t list_no = list_nos[i];
|
|
904
915
|
if (list_no < 0) {
|
|
905
916
|
continue;
|
|
@@ -911,4 +922,77 @@ void StopWordsInvertedLists::prefetch_lists(const idx_t* list_nos, int nlist)
|
|
|
911
922
|
il0->prefetch_lists(list0.data(), list0.size());
|
|
912
923
|
}
|
|
913
924
|
|
|
925
|
+
/*****************************************
|
|
926
|
+
* CappedInvertedLists implementation
|
|
927
|
+
******************************************/
|
|
928
|
+
|
|
929
|
+
CappedInvertedLists::CappedInvertedLists(InvertedLists* il0, size_t maxsize)
|
|
930
|
+
: InvertedLists(il0->nlist, il0->code_size),
|
|
931
|
+
il0(il0),
|
|
932
|
+
maxsize(maxsize) {}
|
|
933
|
+
|
|
934
|
+
size_t CappedInvertedLists::list_size(size_t list_no) const {
|
|
935
|
+
size_t sz = il0->list_size(list_no);
|
|
936
|
+
return sz < maxsize ? sz : maxsize;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
size_t CappedInvertedLists::real_list_size(size_t list_no) const {
|
|
940
|
+
return il0->list_size(list_no);
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
const uint8_t* CappedInvertedLists::get_codes(size_t list_no) const {
|
|
944
|
+
return il0->get_codes(list_no);
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
const idx_t* CappedInvertedLists::get_ids(size_t list_no) const {
|
|
948
|
+
return il0->get_ids(list_no);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
void CappedInvertedLists::release_codes(size_t list_no, const uint8_t* codes)
|
|
952
|
+
const {
|
|
953
|
+
il0->release_codes(list_no, codes);
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
void CappedInvertedLists::release_ids(size_t list_no, const idx_t* ids) const {
|
|
957
|
+
il0->release_ids(list_no, ids);
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
idx_t CappedInvertedLists::get_single_id(size_t list_no, size_t offset) const {
|
|
961
|
+
FAISS_THROW_IF_NOT(offset < list_size(list_no));
|
|
962
|
+
return il0->get_single_id(list_no, offset);
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
const uint8_t* CappedInvertedLists::get_single_code(
|
|
966
|
+
size_t list_no,
|
|
967
|
+
size_t offset) const {
|
|
968
|
+
FAISS_THROW_IF_NOT(offset < list_size(list_no));
|
|
969
|
+
return il0->get_single_code(list_no, offset);
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
void CappedInvertedLists::prefetch_lists(const idx_t* list_nos, int nlist)
|
|
973
|
+
const {
|
|
974
|
+
il0->prefetch_lists(list_nos, nlist);
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
size_t CappedInvertedLists::add_entries(
|
|
978
|
+
size_t list_no,
|
|
979
|
+
size_t n_entry,
|
|
980
|
+
const idx_t* ids,
|
|
981
|
+
const uint8_t* code) {
|
|
982
|
+
return il0->add_entries(list_no, n_entry, ids, code);
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
void CappedInvertedLists::update_entries(
|
|
986
|
+
size_t list_no,
|
|
987
|
+
size_t offset,
|
|
988
|
+
size_t n_entry,
|
|
989
|
+
const idx_t* ids,
|
|
990
|
+
const uint8_t* code) {
|
|
991
|
+
il0->update_entries(list_no, offset, n_entry, ids, code);
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
void CappedInvertedLists::resize(size_t list_no, size_t new_size) {
|
|
995
|
+
il0->resize(list_no, new_size);
|
|
996
|
+
}
|
|
997
|
+
|
|
914
998
|
} // namespace faiss
|