faiss 0.5.3 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/ext/faiss/ext.cpp +1 -1
- data/ext/faiss/extconf.rb +4 -4
- data/ext/faiss/index.cpp +63 -45
- data/ext/faiss/index_binary.cpp +37 -27
- data/ext/faiss/kmeans.cpp +9 -8
- data/ext/faiss/pca_matrix.cpp +9 -7
- data/ext/faiss/product_quantizer.cpp +13 -11
- data/ext/faiss/utils.cpp +4 -2
- data/ext/faiss/utils.h +4 -0
- data/lib/faiss/version.rb +1 -1
- data/lib/faiss.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +214 -82
- data/vendor/faiss/faiss/AutoTune.h +14 -1
- data/vendor/faiss/faiss/Clustering.cpp +97 -249
- data/vendor/faiss/faiss/Clustering.h +18 -0
- data/vendor/faiss/faiss/IVFlib.cpp +67 -44
- data/vendor/faiss/faiss/Index.cpp +25 -12
- data/vendor/faiss/faiss/Index.h +26 -4
- data/vendor/faiss/faiss/Index2Layer.cpp +37 -53
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +68 -61
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +36 -34
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +4 -1
- data/vendor/faiss/faiss/IndexBinary.cpp +6 -3
- data/vendor/faiss/faiss/IndexBinary.h +4 -4
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +1 -1
- data/vendor/faiss/faiss/IndexBinaryFlat.h +1 -1
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +4 -4
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +92 -95
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +9 -3
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +45 -236
- data/vendor/faiss/faiss/IndexBinaryHash.h +6 -6
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +120 -414
- data/vendor/faiss/faiss/IndexFastScan.cpp +105 -129
- data/vendor/faiss/faiss/IndexFastScan.h +35 -24
- data/vendor/faiss/faiss/IndexFlat.cpp +216 -152
- data/vendor/faiss/faiss/IndexFlat.h +32 -14
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +88 -41
- data/vendor/faiss/faiss/IndexFlatCodes.h +7 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +299 -187
- data/vendor/faiss/faiss/IndexHNSW.h +30 -14
- data/vendor/faiss/faiss/IndexIDMap.cpp +26 -22
- data/vendor/faiss/faiss/IndexIDMap.h +9 -7
- data/vendor/faiss/faiss/IndexIVF.cpp +535 -405
- data/vendor/faiss/faiss/IndexIVF.h +47 -16
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +77 -74
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +105 -99
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +6 -3
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +379 -249
- data/vendor/faiss/faiss/IndexIVFFastScan.h +65 -60
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +41 -124
- data/vendor/faiss/faiss/IndexIVFFlat.h +32 -0
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.cpp +89 -138
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.h +3 -1
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.cpp +18 -15
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +77 -907
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +184 -122
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +3 -0
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +23 -18
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +59 -60
- data/vendor/faiss/faiss/IndexIVFRaBitQ.h +4 -3
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +564 -416
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +269 -111
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +41 -127
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +1 -1
- data/vendor/faiss/faiss/IndexLSH.cpp +44 -25
- data/vendor/faiss/faiss/IndexLattice.cpp +41 -36
- data/vendor/faiss/faiss/IndexNNDescent.cpp +37 -21
- data/vendor/faiss/faiss/IndexNNDescent.h +2 -2
- data/vendor/faiss/faiss/IndexNSG.cpp +40 -23
- data/vendor/faiss/faiss/IndexNSG.h +0 -2
- data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +32 -12
- data/vendor/faiss/faiss/IndexPQ.cpp +129 -213
- data/vendor/faiss/faiss/IndexPQ.h +3 -2
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +20 -14
- data/vendor/faiss/faiss/IndexPQFastScan.h +3 -0
- data/vendor/faiss/faiss/IndexPreTransform.cpp +25 -18
- data/vendor/faiss/faiss/IndexPreTransform.h +1 -1
- data/vendor/faiss/faiss/IndexRaBitQ.cpp +31 -43
- data/vendor/faiss/faiss/IndexRaBitQ.h +4 -3
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +135 -317
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +192 -34
- data/vendor/faiss/faiss/IndexRefine.cpp +30 -55
- data/vendor/faiss/faiss/IndexRefine.h +4 -4
- data/vendor/faiss/faiss/IndexReplicas.cpp +6 -6
- data/vendor/faiss/faiss/IndexRowwiseMinMax.cpp +15 -14
- data/vendor/faiss/faiss/IndexRowwiseMinMax.h +1 -1
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +82 -14
- data/vendor/faiss/faiss/IndexShards.cpp +13 -13
- data/vendor/faiss/faiss/IndexShardsIVF.cpp +21 -15
- data/vendor/faiss/faiss/MatrixStats.cpp +5 -4
- data/vendor/faiss/faiss/MetaIndexes.cpp +19 -17
- data/vendor/faiss/faiss/MetaIndexes.h +1 -1
- data/vendor/faiss/faiss/MetricType.h +29 -6
- data/vendor/faiss/faiss/SuperKMeans.cpp +656 -0
- data/vendor/faiss/faiss/SuperKMeans.h +97 -0
- data/vendor/faiss/faiss/VectorTransform.cpp +349 -141
- data/vendor/faiss/faiss/VectorTransform.h +39 -16
- data/vendor/faiss/faiss/build.cpp +23 -0
- data/vendor/faiss/faiss/build.h +15 -0
- data/vendor/faiss/faiss/clone_index.cpp +55 -51
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +47 -47
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +11 -0
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-avx2-inl.h +38 -38
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-inl.h +11 -0
- data/vendor/faiss/faiss/{cppcontrib/factory_tools.cpp → factory_tools.cpp} +6 -1
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +1 -1
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +6 -5
- data/vendor/faiss/faiss/gpu/GpuResources.h +1 -1
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +9 -9
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +4 -3
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +46 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +56 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +78 -1
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +72 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +23 -0
- data/vendor/faiss/faiss/gpu/utils/CuvsFilterConvert.h +1 -1
- data/vendor/faiss/faiss/gpu/utils/CuvsUtils.h +21 -10
- data/vendor/faiss/faiss/gpu_metal/GpuIndexFlat.h +22 -0
- data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +35 -0
- data/vendor/faiss/faiss/gpu_metal/MetalFlatKernels.h +40 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +51 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndexFlat.h +65 -0
- data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +66 -0
- data/vendor/faiss/faiss/gpu_metal/MetalResources.h +79 -0
- data/vendor/faiss/faiss/gpu_metal/StandardMetalResources.h +35 -0
- data/vendor/faiss/faiss/impl/AdSampling.cpp +103 -0
- data/vendor/faiss/faiss/impl/AdSampling.h +35 -0
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +64 -34
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +1 -0
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +10 -9
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +3 -28
- data/vendor/faiss/faiss/impl/ClusteringHelpers.cpp +244 -0
- data/vendor/faiss/faiss/impl/ClusteringHelpers.h +94 -0
- data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +367 -0
- data/vendor/faiss/faiss/impl/ClusteringInitialization.h +107 -0
- data/vendor/faiss/faiss/impl/CodePacker.cpp +7 -3
- data/vendor/faiss/faiss/impl/CodePacker.h +11 -3
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +83 -0
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.h +47 -0
- data/vendor/faiss/faiss/impl/DistanceComputer.h +8 -8
- data/vendor/faiss/faiss/impl/FaissAssert.h +64 -3
- data/vendor/faiss/faiss/impl/FaissException.h +50 -3
- data/vendor/faiss/faiss/impl/HNSW.cpp +117 -351
- data/vendor/faiss/faiss/impl/HNSW.h +21 -40
- data/vendor/faiss/faiss/impl/IDSelector.cpp +15 -11
- data/vendor/faiss/faiss/impl/IDSelector.h +8 -8
- data/vendor/faiss/faiss/impl/InvertedListScannerStats.h +26 -0
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +114 -102
- data/vendor/faiss/faiss/impl/NNDescent.cpp +63 -26
- data/vendor/faiss/faiss/impl/NNDescent.h +6 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +44 -26
- data/vendor/faiss/faiss/impl/NSG.h +20 -10
- data/vendor/faiss/faiss/impl/Panorama.cpp +76 -52
- data/vendor/faiss/faiss/impl/Panorama.h +265 -78
- data/vendor/faiss/faiss/impl/PdxLayout.cpp +93 -0
- data/vendor/faiss/faiss/impl/PdxLayout.h +41 -0
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +62 -37
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +3 -3
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +35 -35
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +21 -16
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +99 -80
- data/vendor/faiss/faiss/impl/Quantizer.h +2 -2
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +135 -37
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +148 -21
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +298 -301
- data/vendor/faiss/faiss/impl/RaBitQuantizer.h +3 -10
- data/vendor/faiss/faiss/impl/RaBitQuantizerMultiBit.cpp +15 -41
- data/vendor/faiss/faiss/impl/RaBitQuantizerMultiBit.h +0 -4
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +40 -32
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ResultHandler.h +218 -113
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +119 -2362
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +27 -3
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +14 -11
- data/vendor/faiss/faiss/impl/VisitedTable.cpp +42 -0
- data/vendor/faiss/faiss/impl/VisitedTable.h +76 -0
- data/vendor/faiss/faiss/impl/approx_topk/approx_topk.h +276 -0
- data/vendor/faiss/faiss/impl/approx_topk/avx2.cpp +68 -0
- data/vendor/faiss/faiss/{utils → impl}/approx_topk/generic.h +15 -8
- data/vendor/faiss/faiss/impl/approx_topk/neon.cpp +68 -0
- data/vendor/faiss/faiss/impl/approx_topk/rq_beam_search_tab-inl.h +169 -0
- data/vendor/faiss/faiss/impl/approx_topk/rq_beam_search_tab.h +117 -0
- data/vendor/faiss/faiss/impl/approx_topk/simdlib256-inl.h +146 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHNSW_impl.h +73 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHash_impl.h +270 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryIVF_impl.h +460 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexIVFSpectralHash_impl.h +159 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexPQ_impl.h +92 -0
- data/vendor/faiss/faiss/impl/binary_hamming/avx2.cpp +26 -0
- data/vendor/faiss/faiss/impl/binary_hamming/avx512.cpp +26 -0
- data/vendor/faiss/faiss/impl/binary_hamming/dispatch.h +143 -0
- data/vendor/faiss/faiss/impl/binary_hamming/neon.cpp +26 -0
- data/vendor/faiss/faiss/impl/binary_hamming/rvv.cpp +26 -0
- data/vendor/faiss/faiss/impl/expanded_scanners.h +163 -0
- data/vendor/faiss/faiss/impl/{FastScanDistancePostProcessing.h → fast_scan/FastScanDistancePostProcessing.h} +13 -6
- data/vendor/faiss/faiss/impl/{LookupTableScaler.h → fast_scan/LookupTableScaler.h} +16 -5
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops.h +237 -0
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops_512.h +185 -0
- data/vendor/faiss/faiss/impl/fast_scan/decompose_qbs.h +229 -0
- data/vendor/faiss/faiss/impl/fast_scan/dispatching.h +268 -0
- data/vendor/faiss/faiss/impl/{pq4_fast_scan.cpp → fast_scan/fast_scan.cpp} +176 -4
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.h +341 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +36 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +40 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +120 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-riscv.cpp +104 -0
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd256.h +213 -0
- data/vendor/faiss/faiss/impl/{pq4_fast_scan_search_qbs.cpp → fast_scan/kernels_simd512.h} +26 -348
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_dispatching.h +90 -0
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_result_handler.h +108 -0
- data/vendor/faiss/faiss/impl/{simd_result_handlers.h → fast_scan/simd_result_handlers.h} +290 -142
- data/vendor/faiss/faiss/impl/hnsw/LockVector.cpp +54 -0
- data/vendor/faiss/faiss/impl/hnsw/LockVector.h +64 -0
- data/vendor/faiss/faiss/impl/hnsw/MinimaxHeap.cpp +91 -0
- data/vendor/faiss/faiss/impl/hnsw/MinimaxHeap.h +64 -0
- data/vendor/faiss/faiss/impl/hnsw/avx2.cpp +104 -0
- data/vendor/faiss/faiss/impl/hnsw/avx512.cpp +111 -0
- data/vendor/faiss/faiss/impl/index_read.cpp +1950 -505
- data/vendor/faiss/faiss/impl/index_read_utils.h +1 -2
- data/vendor/faiss/faiss/impl/index_write.cpp +112 -21
- data/vendor/faiss/faiss/impl/io.cpp +6 -6
- data/vendor/faiss/faiss/impl/io_macros.h +33 -16
- data/vendor/faiss/faiss/impl/kmeans1d.cpp +10 -10
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +81 -40
- data/vendor/faiss/faiss/impl/lattice_Zn.h +6 -6
- data/vendor/faiss/faiss/impl/mapped_io.cpp +15 -8
- data/vendor/faiss/faiss/impl/platform_macros.h +11 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +549 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.cpp +245 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.h +105 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/PQDistanceComputer_impl.h +106 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx2.cpp +21 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx512.cpp +21 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/neon.cpp +21 -0
- data/vendor/faiss/faiss/impl/{code_distance/code_distance-avx2.h → pq_code_distance/pq_code_distance-avx2.h} +43 -220
- data/vendor/faiss/faiss/impl/{code_distance/code_distance-avx512.h → pq_code_distance/pq_code_distance-avx512.h} +25 -112
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.cpp +59 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.h +96 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-inl.h +256 -0
- data/vendor/faiss/faiss/impl/{code_distance/code_distance-sve.h → pq_code_distance/pq_code_distance-sve.cpp} +57 -146
- data/vendor/faiss/faiss/impl/pq_code_distance/rvv.cpp +68 -0
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +320 -483
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/codecs.h +121 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +137 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +371 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +190 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/similarities.h +94 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +603 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +597 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +388 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +630 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-rvv.cpp +311 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.cpp +387 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.h +54 -0
- data/vendor/faiss/faiss/impl/simd_dispatch.h +173 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib.h +57 -0
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_avx2.h +274 -171
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx512.h +414 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_dispatch.h +44 -0
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_emulated.h +231 -166
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_neon.h +275 -217
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_ppc64.h +201 -160
- data/vendor/faiss/faiss/impl/svs_io.cpp +12 -3
- data/vendor/faiss/faiss/impl/svs_io.h +8 -2
- data/vendor/faiss/faiss/index_factory.cpp +115 -28
- data/vendor/faiss/faiss/index_io.h +53 -3
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +73 -20
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +24 -14
- data/vendor/faiss/faiss/invlists/DirectMap.h +4 -3
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +157 -73
- data/vendor/faiss/faiss/invlists/InvertedLists.h +86 -23
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +4 -4
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +14 -14
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +9 -19
- data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +2 -2
- data/vendor/faiss/faiss/svs/IndexSVSFlat.h +2 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVF.cpp +350 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVF.h +128 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLVQ.cpp +40 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLVQ.h +43 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLeanVec.cpp +225 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLeanVec.h +71 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +25 -1
- data/vendor/faiss/faiss/svs/IndexSVSVamana.h +19 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.cpp +19 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.h +14 -0
- data/vendor/faiss/faiss/utils/Heap.cpp +56 -10
- data/vendor/faiss/faiss/utils/Heap.h +21 -0
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +54 -40
- data/vendor/faiss/faiss/utils/NeuralNet.h +1 -1
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +10 -4
- data/vendor/faiss/faiss/utils/distances.cpp +507 -559
- data/vendor/faiss/faiss/utils/distances.h +118 -1
- data/vendor/faiss/faiss/utils/distances_dispatch.h +250 -0
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +8 -7
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +33 -14
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.h +12 -1
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +16 -293
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based_neon.cpp +57 -0
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_kernel-inl.h +290 -0
- data/vendor/faiss/faiss/utils/distances_simd.cpp +72 -3681
- data/vendor/faiss/faiss/utils/extra_distances.cpp +60 -102
- data/vendor/faiss/faiss/utils/extra_distances.h +79 -7
- data/vendor/faiss/faiss/utils/hamming-inl.h +13 -11
- data/vendor/faiss/faiss/utils/hamming.cpp +66 -517
- data/vendor/faiss/faiss/utils/hamming.h +92 -2
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +287 -10
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx2.cpp +15 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512.cpp +15 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx2.h +142 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512.h +234 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-generic.h +368 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-neon.h +322 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-rvv.h +39 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer.h +146 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_impl.h +481 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_neon.cpp +15 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_rvv.cpp +15 -0
- data/vendor/faiss/faiss/utils/partitioning.cpp +66 -987
- data/vendor/faiss/faiss/utils/partitioning.h +31 -0
- data/vendor/faiss/faiss/utils/popcount.h +29 -0
- data/vendor/faiss/faiss/utils/pq_code_distance.h +251 -0
- data/vendor/faiss/faiss/utils/prefetch.h +2 -2
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +30 -30
- data/vendor/faiss/faiss/utils/quantize_lut.h +1 -1
- data/vendor/faiss/faiss/utils/rabitq_simd.h +124 -343
- data/vendor/faiss/faiss/utils/random.cpp +6 -6
- data/vendor/faiss/faiss/utils/simd_impl/IVFFlatScanner-inl.h +51 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_aarch64.cpp +154 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +777 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +306 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +1431 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +1095 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv.cpp +189 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_simdlib256.h +195 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_sse-inl.h +392 -0
- data/vendor/faiss/faiss/utils/{distances_fused/simdlib_based.h → simd_impl/exhaustive_L2sqr_blas_cmax.h} +5 -10
- data/vendor/faiss/faiss/utils/simd_impl/hamming_impl.h +481 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_avx2.cpp +14 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_neon.cpp +14 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_simdlib256.h +1085 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp +355 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +477 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_neon.cpp +55 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_rvv.cpp +55 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_dispatch.h +32 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels.h +43 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx2.cpp +57 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx512.cpp +45 -0
- data/vendor/faiss/faiss/utils/simd_levels.cpp +334 -0
- data/vendor/faiss/faiss/utils/simd_levels.h +183 -0
- data/vendor/faiss/faiss/utils/sorting.cpp +48 -36
- data/vendor/faiss/faiss/utils/utils.cpp +21 -14
- data/vendor/faiss/faiss/utils/utils.h +3 -3
- metadata +156 -42
- data/vendor/faiss/faiss/impl/RaBitQStats.cpp +0 -29
- data/vendor/faiss/faiss/impl/RaBitQStats.h +0 -56
- data/vendor/faiss/faiss/impl/code_distance/code_distance-generic.h +0 -81
- data/vendor/faiss/faiss/impl/code_distance/code_distance.h +0 -186
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +0 -216
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +0 -224
- data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +0 -84
- data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +0 -196
- data/vendor/faiss/faiss/utils/approx_topk/mode.h +0 -34
- data/vendor/faiss/faiss/utils/distances_fused/avx512.h +0 -36
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +0 -228
- data/vendor/faiss/faiss/utils/hamming_distance/avx2-inl.h +0 -462
- data/vendor/faiss/faiss/utils/hamming_distance/avx512-inl.h +0 -490
- data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +0 -450
- data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +0 -87
- data/vendor/faiss/faiss/utils/hamming_distance/neon-inl.h +0 -524
- data/vendor/faiss/faiss/utils/simdlib.h +0 -42
- data/vendor/faiss/faiss/utils/simdlib_avx512.h +0 -296
- /data/vendor/faiss/faiss/{cppcontrib/factory_tools.h → factory_tools.h} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '08fc3bcca329e78e913982923c3fb3743e07591ffd717f5f3027e0609037b5de'
|
|
4
|
+
data.tar.gz: 2a1a79aeaef1756a974fe7e9c3448794496ef145046da39aae3b6ce04a9bf131
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 86e6528125608c64ab9bec3f289019cc0a4125e6719d8c43ca7e9f8eb09cb57ce42f9e040fd0290969f45f70fb25c789a50de7aceef07c38b0acb5ca5e674c49
|
|
7
|
+
data.tar.gz: 4efe37e9e855ab4da2e620e391ac817e6bfa808ca227ea047b55eaff4e7cfdae4c5af59d35b57963653d208e50334edc048fc168fd6d49f805cdb07d3dbc115e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## 0.6.1 (2026-05-23)
|
|
2
|
+
|
|
3
|
+
- Updated Faiss to 1.14.2
|
|
4
|
+
|
|
5
|
+
## 0.6.0 (2026-04-06)
|
|
6
|
+
|
|
7
|
+
- Updated Faiss to 1.14.1
|
|
8
|
+
- Added `id_map` method to `IndexIDMap2`
|
|
9
|
+
- Switched to `numo-narray-alt`
|
|
10
|
+
- Dropped support for Ruby < 3.3
|
|
11
|
+
- Dropped support for C++17
|
|
12
|
+
|
|
1
13
|
## 0.5.3 (2026-02-12)
|
|
2
14
|
|
|
3
15
|
- Added `IndexIDMap2` class
|
data/ext/faiss/ext.cpp
CHANGED
data/ext/faiss/extconf.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require "mkmf-rice"
|
|
2
|
-
require "numo/narray"
|
|
2
|
+
require "numo/narray/alt"
|
|
3
3
|
|
|
4
4
|
# libomp changed to keg-only
|
|
5
5
|
# https://github.com/Homebrew/homebrew-core/issues/112107
|
|
@@ -13,14 +13,13 @@ abort "BLAS not found" unless have_library("blas")
|
|
|
13
13
|
abort "LAPACK not found" unless have_library("lapack")
|
|
14
14
|
abort "OpenMP not found" unless have_library("omp") || have_library("gomp")
|
|
15
15
|
|
|
16
|
-
numo = File.join(Gem.loaded_specs["numo-narray"].require_path, "numo")
|
|
16
|
+
numo = File.join(Gem.loaded_specs["numo-narray-alt"].require_path, "numo")
|
|
17
17
|
abort "Numo not found" unless find_header("numo/narray.h", numo)
|
|
18
18
|
|
|
19
19
|
# for https://bugs.ruby-lang.org/issues/19005
|
|
20
20
|
$LDFLAGS += " -Wl,-undefined,dynamic_lookup" if RbConfig::CONFIG["host_os"] =~ /darwin/i
|
|
21
21
|
|
|
22
|
-
$CXXFLAGS += " -std=c++
|
|
23
|
-
$CXXFLAGS += " -Wall -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable -Wno-unused-private-field -Wno-deprecated-declarations -Wno-sign-compare"
|
|
22
|
+
$CXXFLAGS += " -std=c++20 $(optflags) -DFINTEGER=int"
|
|
24
23
|
|
|
25
24
|
# -march=native not supported with ARM Mac
|
|
26
25
|
default_optflags = RbConfig::CONFIG["host_os"] =~ /darwin/i && RbConfig::CONFIG["host_cpu"] =~ /arm|aarch64/i ? "" : " -march=native"
|
|
@@ -34,6 +33,7 @@ ext = File.expand_path(".", __dir__)
|
|
|
34
33
|
vendor = File.expand_path("../../vendor/faiss", __dir__)
|
|
35
34
|
|
|
36
35
|
$srcs = Dir["{#{ext},#{vendor}/faiss,#{vendor}/faiss/{impl,invlists,utils}/**}/*.{cpp}"]
|
|
36
|
+
$srcs -= ["avx2", "avx512", "aarch64", "arm_sve"].map { |v| "#{vendor}/faiss/utils/simd_impl/distances_#{v}.cpp" }
|
|
37
37
|
$objs = $srcs.map { |v| v.sub(/cpp\z/, "o") }
|
|
38
38
|
abort "Faiss not found" unless find_header("faiss/Index.h", vendor)
|
|
39
39
|
$VPATH << vendor
|
data/ext/faiss/index.cpp
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
#include <algorithm>
|
|
2
|
+
#include <cstddef>
|
|
3
|
+
#include <cstdint>
|
|
4
|
+
#include <limits>
|
|
2
5
|
#include <string>
|
|
6
|
+
#include <utility>
|
|
3
7
|
#include <vector>
|
|
4
8
|
|
|
5
9
|
#include <faiss/AutoTune.h>
|
|
@@ -8,14 +12,14 @@
|
|
|
8
12
|
#include <faiss/IndexHNSW.h>
|
|
9
13
|
#include <faiss/IndexIDMap.h>
|
|
10
14
|
#include <faiss/IndexIVFFlat.h>
|
|
11
|
-
#include <faiss/IndexLSH.h>
|
|
12
|
-
#include <faiss/IndexScalarQuantizer.h>
|
|
13
|
-
#include <faiss/IndexPQ.h>
|
|
14
15
|
#include <faiss/IndexIVFPQ.h>
|
|
15
16
|
#include <faiss/IndexIVFPQR.h>
|
|
17
|
+
#include <faiss/IndexLSH.h>
|
|
18
|
+
#include <faiss/IndexPQ.h>
|
|
19
|
+
#include <faiss/IndexScalarQuantizer.h>
|
|
20
|
+
#include <faiss/MetricType.h>
|
|
16
21
|
#include <faiss/index_io.h>
|
|
17
22
|
#include <rice/rice.hpp>
|
|
18
|
-
#include <rice/stl.hpp>
|
|
19
23
|
|
|
20
24
|
#include "numo.hpp"
|
|
21
25
|
#include "utils.h"
|
|
@@ -33,10 +37,10 @@ namespace Rice::detail {
|
|
|
33
37
|
|
|
34
38
|
explicit From_Ruby(Arg* arg) : arg_(arg) { }
|
|
35
39
|
|
|
36
|
-
double is_convertible(VALUE value) { return Convertible::Exact; }
|
|
40
|
+
double is_convertible(VALUE /*value*/) { return Convertible::Exact; }
|
|
37
41
|
|
|
38
42
|
faiss::MetricType convert(VALUE x) {
|
|
39
|
-
|
|
43
|
+
std::string s = Object(x).to_s().str();
|
|
40
44
|
if (s == "inner_product") {
|
|
41
45
|
return faiss::METRIC_INNER_PRODUCT;
|
|
42
46
|
} else if (s == "l2") {
|
|
@@ -62,10 +66,10 @@ namespace Rice::detail {
|
|
|
62
66
|
|
|
63
67
|
explicit From_Ruby(Arg* arg) : arg_(arg) { }
|
|
64
68
|
|
|
65
|
-
double is_convertible(VALUE value) { return Convertible::Exact; }
|
|
69
|
+
double is_convertible(VALUE /*value*/) { return Convertible::Exact; }
|
|
66
70
|
|
|
67
71
|
faiss::ScalarQuantizer::QuantizerType convert(VALUE x) {
|
|
68
|
-
|
|
72
|
+
std::string s = Object(x).to_s().str();
|
|
69
73
|
if (s == "qt_8bit") {
|
|
70
74
|
return faiss::ScalarQuantizer::QT_8bit;
|
|
71
75
|
} else if (s == "qt_4bit") {
|
|
@@ -94,17 +98,17 @@ void init_index(Rice::Module& m) {
|
|
|
94
98
|
Rice::define_class_under<faiss::Index>(m, "Index")
|
|
95
99
|
.define_method(
|
|
96
100
|
"d",
|
|
97
|
-
[](faiss::Index
|
|
101
|
+
[](faiss::Index& self) {
|
|
98
102
|
return self.d;
|
|
99
103
|
})
|
|
100
104
|
.define_method(
|
|
101
105
|
"trained?",
|
|
102
|
-
[](faiss::Index
|
|
106
|
+
[](faiss::Index& self) {
|
|
103
107
|
return self.is_trained;
|
|
104
108
|
})
|
|
105
109
|
.define_method(
|
|
106
110
|
"ntotal",
|
|
107
|
-
[](faiss::Index
|
|
111
|
+
[](faiss::Index& self) {
|
|
108
112
|
return self.ntotal;
|
|
109
113
|
})
|
|
110
114
|
.define_method(
|
|
@@ -112,8 +116,8 @@ void init_index(Rice::Module& m) {
|
|
|
112
116
|
[](Rice::Object rb_self, numo::SFloat objects) {
|
|
113
117
|
check_frozen(rb_self);
|
|
114
118
|
|
|
115
|
-
auto
|
|
116
|
-
|
|
119
|
+
auto& self = *Rice::Data_Object<faiss::Index>{rb_self};
|
|
120
|
+
size_t n = check_shape(objects, self.d);
|
|
117
121
|
self.train(n, objects.read_ptr());
|
|
118
122
|
})
|
|
119
123
|
.define_method(
|
|
@@ -121,8 +125,8 @@ void init_index(Rice::Module& m) {
|
|
|
121
125
|
[](Rice::Object rb_self, numo::SFloat objects) {
|
|
122
126
|
check_frozen(rb_self);
|
|
123
127
|
|
|
124
|
-
auto
|
|
125
|
-
|
|
128
|
+
auto& self = *Rice::Data_Object<faiss::Index>{rb_self};
|
|
129
|
+
size_t n = check_shape(objects, self.d);
|
|
126
130
|
self.add(n, objects.read_ptr());
|
|
127
131
|
})
|
|
128
132
|
.define_method(
|
|
@@ -130,8 +134,8 @@ void init_index(Rice::Module& m) {
|
|
|
130
134
|
[](Rice::Object rb_self, numo::SFloat objects, numo::Int64 ids) {
|
|
131
135
|
check_frozen(rb_self);
|
|
132
136
|
|
|
133
|
-
auto
|
|
134
|
-
|
|
137
|
+
auto& self = *Rice::Data_Object<faiss::Index>{rb_self};
|
|
138
|
+
size_t n = check_shape(objects, self.d);
|
|
135
139
|
if (ids.ndim() != 1 || ids.shape()[0] != n) {
|
|
136
140
|
throw Rice::Exception(rb_eArgError, "expected ids to be 1d array with size %d", n);
|
|
137
141
|
}
|
|
@@ -142,36 +146,42 @@ void init_index(Rice::Module& m) {
|
|
|
142
146
|
[](Rice::Object rb_self, numo::Int64 ids) {
|
|
143
147
|
check_frozen(rb_self);
|
|
144
148
|
|
|
145
|
-
auto
|
|
149
|
+
auto& self = *Rice::Data_Object<faiss::Index>{rb_self};
|
|
146
150
|
if (ids.ndim() != 1) {
|
|
147
151
|
throw Rice::Exception(rb_eArgError, "expected ids to be 1d array");
|
|
148
152
|
}
|
|
149
|
-
|
|
153
|
+
size_t n = ids.shape()[0];
|
|
150
154
|
faiss::IDSelectorBatch sel(n, ids.read_ptr());
|
|
151
155
|
return self.remove_ids(sel);
|
|
152
156
|
})
|
|
153
157
|
.define_method(
|
|
154
158
|
"search",
|
|
155
|
-
[](Rice::Object rb_self, numo::SFloat objects,
|
|
156
|
-
auto
|
|
157
|
-
|
|
159
|
+
[](Rice::Object rb_self, numo::SFloat objects, int64_t k) {
|
|
160
|
+
auto& self = *Rice::Data_Object<faiss::Index>{rb_self};
|
|
161
|
+
size_t n = check_shape(objects, self.d);
|
|
162
|
+
if (k <= 0) {
|
|
163
|
+
throw Rice::Exception(rb_eArgError, "expected k to be positive");
|
|
164
|
+
}
|
|
165
|
+
if (k >= std::numeric_limits<size_t>::max() / n) {
|
|
166
|
+
throw Rice::Exception(rb_eArgError, "k too large");
|
|
167
|
+
}
|
|
158
168
|
|
|
159
|
-
|
|
160
|
-
|
|
169
|
+
numo::SFloat distances({n, static_cast<size_t>(k)});
|
|
170
|
+
numo::Int64 labels({n, static_cast<size_t>(k)});
|
|
161
171
|
|
|
162
172
|
if (rb_self.is_frozen()) {
|
|
163
173
|
// Don't mess with Ruby-owned memory while the GVL is released
|
|
164
|
-
auto objects_ptr = objects.read_ptr();
|
|
174
|
+
const auto* objects_ptr = objects.read_ptr();
|
|
165
175
|
std::vector<float> objects_vec(objects_ptr, objects_ptr + n * self.d);
|
|
166
|
-
std::vector<float> distances_vec(n * k);
|
|
167
|
-
std::vector<int64_t> labels_vec(n * k);
|
|
176
|
+
std::vector<float> distances_vec(n * static_cast<size_t>(k));
|
|
177
|
+
std::vector<int64_t> labels_vec(n * static_cast<size_t>(k));
|
|
168
178
|
|
|
169
179
|
Rice::detail::no_gvl([&] {
|
|
170
180
|
self.search(n, objects_vec.data(), k, distances_vec.data(), labels_vec.data());
|
|
171
181
|
});
|
|
172
182
|
|
|
173
|
-
std::copy(distances_vec
|
|
174
|
-
std::copy(labels_vec
|
|
183
|
+
std::ranges::copy(distances_vec, distances.write_ptr());
|
|
184
|
+
std::ranges::copy(labels_vec, labels.write_ptr());
|
|
175
185
|
} else {
|
|
176
186
|
self.search(n, objects.read_ptr(), k, distances.write_ptr(), labels.write_ptr());
|
|
177
187
|
}
|
|
@@ -186,32 +196,32 @@ void init_index(Rice::Module& m) {
|
|
|
186
196
|
[](Rice::Object rb_self, double val) {
|
|
187
197
|
check_frozen(rb_self);
|
|
188
198
|
|
|
189
|
-
auto
|
|
199
|
+
auto& self = *Rice::Data_Object<faiss::Index>{rb_self};
|
|
190
200
|
faiss::ParameterSpace().set_index_parameter(&self, "nprobe", val);
|
|
191
201
|
})
|
|
192
202
|
.define_method(
|
|
193
203
|
"reconstruct",
|
|
194
|
-
[](faiss::Index
|
|
195
|
-
auto d = static_cast<
|
|
196
|
-
|
|
204
|
+
[](faiss::Index& self, int64_t key) {
|
|
205
|
+
auto d = static_cast<size_t>(self.d);
|
|
206
|
+
numo::SFloat recons({d});
|
|
197
207
|
self.reconstruct(key, recons.write_ptr());
|
|
198
208
|
return recons;
|
|
199
209
|
})
|
|
200
210
|
.define_method(
|
|
201
211
|
"reconstruct_batch",
|
|
202
|
-
[](faiss::Index
|
|
212
|
+
[](faiss::Index& self, numo::Int64 ids) {
|
|
203
213
|
if (ids.ndim() != 1) {
|
|
204
214
|
throw Rice::Exception(rb_eArgError, "expected ids to be 1d array");
|
|
205
215
|
}
|
|
206
|
-
auto n = static_cast<
|
|
207
|
-
auto d = static_cast<
|
|
208
|
-
|
|
216
|
+
auto n = static_cast<size_t>(ids.shape()[0]);
|
|
217
|
+
auto d = static_cast<size_t>(self.d);
|
|
218
|
+
numo::SFloat recons({n, d});
|
|
209
219
|
self.reconstruct_batch(n, ids.read_ptr(), recons.write_ptr());
|
|
210
220
|
return recons;
|
|
211
221
|
})
|
|
212
222
|
.define_method(
|
|
213
223
|
"reconstruct_n",
|
|
214
|
-
[](faiss::Index
|
|
224
|
+
[](faiss::Index& self, int64_t i0, int64_t ni) {
|
|
215
225
|
if (ni < 0) {
|
|
216
226
|
throw Rice::Exception(rb_eArgError, "expected n to be non-negative");
|
|
217
227
|
}
|
|
@@ -219,15 +229,15 @@ void init_index(Rice::Module& m) {
|
|
|
219
229
|
if (i0 < 0 || i0 > self.ntotal - ni) {
|
|
220
230
|
throw Rice::Exception(rb_eIndexError, "index out of range");
|
|
221
231
|
}
|
|
222
|
-
auto d = static_cast<
|
|
223
|
-
auto n = static_cast<
|
|
224
|
-
|
|
232
|
+
auto d = static_cast<size_t>(self.d);
|
|
233
|
+
auto n = static_cast<size_t>(ni);
|
|
234
|
+
numo::SFloat recons({n, d});
|
|
225
235
|
self.reconstruct_n(i0, ni, recons.write_ptr());
|
|
226
236
|
return recons;
|
|
227
237
|
})
|
|
228
238
|
.define_method(
|
|
229
239
|
"save",
|
|
230
|
-
[](faiss::Index
|
|
240
|
+
[](faiss::Index& self, Rice::String fname) {
|
|
231
241
|
faiss::write_index(&self, fname.c_str());
|
|
232
242
|
})
|
|
233
243
|
.define_singleton_function(
|
|
@@ -273,13 +283,21 @@ void init_index(Rice::Module& m) {
|
|
|
273
283
|
.define_constructor(Rice::Constructor<faiss::ParameterSpace>())
|
|
274
284
|
.define_method(
|
|
275
285
|
"set_index_parameter",
|
|
276
|
-
[](faiss::ParameterSpace& self, faiss::Index* index,
|
|
277
|
-
self.set_index_parameter(index, name, val);
|
|
286
|
+
[](faiss::ParameterSpace& self, faiss::Index* index, Rice::String name, double val) {
|
|
287
|
+
self.set_index_parameter(index, name.str(), val);
|
|
278
288
|
});
|
|
279
289
|
|
|
280
290
|
Rice::define_class_under<faiss::IndexIDMap, faiss::Index>(m, "IndexIDMap")
|
|
281
291
|
.define_constructor(Rice::Constructor<faiss::IndexIDMap, faiss::Index*>());
|
|
282
292
|
|
|
283
293
|
Rice::define_class_under<faiss::IndexIDMap2, faiss::Index>(m, "IndexIDMap2")
|
|
284
|
-
.define_constructor(Rice::Constructor<faiss::IndexIDMap2, faiss::Index*>())
|
|
294
|
+
.define_constructor(Rice::Constructor<faiss::IndexIDMap2, faiss::Index*>())
|
|
295
|
+
.define_method(
|
|
296
|
+
"id_map",
|
|
297
|
+
[](faiss::IndexIDMap2& self) {
|
|
298
|
+
size_t n = self.id_map.size();
|
|
299
|
+
numo::Int64 ids({n});
|
|
300
|
+
std::ranges::copy(self.id_map, ids.write_ptr());
|
|
301
|
+
return ids;
|
|
302
|
+
});
|
|
285
303
|
}
|
data/ext/faiss/index_binary.cpp
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
#include <algorithm>
|
|
2
|
+
#include <cstddef>
|
|
3
|
+
#include <cstdint>
|
|
4
|
+
#include <limits>
|
|
5
|
+
#include <utility>
|
|
2
6
|
#include <vector>
|
|
3
7
|
|
|
4
8
|
#include <faiss/IndexBinary.h>
|
|
@@ -15,17 +19,17 @@ void init_index_binary(Rice::Module& m) {
|
|
|
15
19
|
Rice::define_class_under<faiss::IndexBinary>(m, "IndexBinary")
|
|
16
20
|
.define_method(
|
|
17
21
|
"d",
|
|
18
|
-
[](faiss::IndexBinary
|
|
22
|
+
[](faiss::IndexBinary& self) {
|
|
19
23
|
return self.d;
|
|
20
24
|
})
|
|
21
25
|
.define_method(
|
|
22
26
|
"trained?",
|
|
23
|
-
[](faiss::IndexBinary
|
|
27
|
+
[](faiss::IndexBinary& self) {
|
|
24
28
|
return self.is_trained;
|
|
25
29
|
})
|
|
26
30
|
.define_method(
|
|
27
31
|
"ntotal",
|
|
28
|
-
[](faiss::IndexBinary
|
|
32
|
+
[](faiss::IndexBinary& self) {
|
|
29
33
|
return self.ntotal;
|
|
30
34
|
})
|
|
31
35
|
.define_method(
|
|
@@ -33,8 +37,8 @@ void init_index_binary(Rice::Module& m) {
|
|
|
33
37
|
[](Rice::Object rb_self, numo::UInt8 objects) {
|
|
34
38
|
check_frozen(rb_self);
|
|
35
39
|
|
|
36
|
-
auto
|
|
37
|
-
|
|
40
|
+
auto& self = *Rice::Data_Object<faiss::IndexBinary>{rb_self};
|
|
41
|
+
size_t n = check_shape(objects, self.d / 8);
|
|
38
42
|
self.train(n, objects.read_ptr());
|
|
39
43
|
})
|
|
40
44
|
.define_method(
|
|
@@ -42,8 +46,8 @@ void init_index_binary(Rice::Module& m) {
|
|
|
42
46
|
[](Rice::Object rb_self, numo::UInt8 objects) {
|
|
43
47
|
check_frozen(rb_self);
|
|
44
48
|
|
|
45
|
-
auto
|
|
46
|
-
|
|
49
|
+
auto& self = *Rice::Data_Object<faiss::IndexBinary>{rb_self};
|
|
50
|
+
size_t n = check_shape(objects, self.d / 8);
|
|
47
51
|
self.add(n, objects.read_ptr());
|
|
48
52
|
})
|
|
49
53
|
.define_method(
|
|
@@ -51,36 +55,42 @@ void init_index_binary(Rice::Module& m) {
|
|
|
51
55
|
[](Rice::Object rb_self, numo::Int64 ids) {
|
|
52
56
|
check_frozen(rb_self);
|
|
53
57
|
|
|
54
|
-
auto
|
|
58
|
+
auto& self = *Rice::Data_Object<faiss::IndexBinary>{rb_self};
|
|
55
59
|
if (ids.ndim() != 1) {
|
|
56
60
|
throw Rice::Exception(rb_eArgError, "expected ids to be 1d array");
|
|
57
61
|
}
|
|
58
|
-
|
|
62
|
+
size_t n = ids.shape()[0];
|
|
59
63
|
faiss::IDSelectorBatch sel(n, ids.read_ptr());
|
|
60
64
|
return self.remove_ids(sel);
|
|
61
65
|
})
|
|
62
66
|
.define_method(
|
|
63
67
|
"search",
|
|
64
|
-
[](Rice::Object rb_self, numo::UInt8 objects,
|
|
65
|
-
auto
|
|
66
|
-
|
|
68
|
+
[](Rice::Object rb_self, numo::UInt8 objects, int64_t k) {
|
|
69
|
+
auto& self = *Rice::Data_Object<faiss::IndexBinary>{rb_self};
|
|
70
|
+
size_t n = check_shape(objects, self.d / 8);
|
|
71
|
+
if (k <= 0) {
|
|
72
|
+
throw Rice::Exception(rb_eArgError, "expected k to be positive");
|
|
73
|
+
}
|
|
74
|
+
if (std::cmp_greater_equal(k, std::numeric_limits<size_t>::max() / n)) {
|
|
75
|
+
throw Rice::Exception(rb_eArgError, "k too large");
|
|
76
|
+
}
|
|
67
77
|
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
numo::Int32 distances({n, static_cast<size_t>(k)});
|
|
79
|
+
numo::Int64 labels({n, static_cast<size_t>(k)});
|
|
70
80
|
|
|
71
81
|
if (rb_self.is_frozen()) {
|
|
72
82
|
// Don't mess with Ruby-owned memory while the GVL is released
|
|
73
|
-
auto objects_ptr = objects.read_ptr();
|
|
83
|
+
const auto* objects_ptr = objects.read_ptr();
|
|
74
84
|
std::vector<uint8_t> objects_vec(objects_ptr, objects_ptr + n * (self.d / 8));
|
|
75
|
-
std::vector<int32_t> distances_vec(n * k);
|
|
76
|
-
std::vector<int64_t> labels_vec(n * k);
|
|
85
|
+
std::vector<int32_t> distances_vec(n * static_cast<size_t>(k));
|
|
86
|
+
std::vector<int64_t> labels_vec(n * static_cast<size_t>(k));
|
|
77
87
|
|
|
78
88
|
Rice::detail::no_gvl([&] {
|
|
79
89
|
self.search(n, objects_vec.data(), k, distances_vec.data(), labels_vec.data());
|
|
80
90
|
});
|
|
81
91
|
|
|
82
|
-
std::copy(distances_vec
|
|
83
|
-
std::copy(labels_vec
|
|
92
|
+
std::ranges::copy(distances_vec, distances.write_ptr());
|
|
93
|
+
std::ranges::copy(labels_vec, labels.write_ptr());
|
|
84
94
|
} else {
|
|
85
95
|
self.search(n, objects.read_ptr(), k, distances.write_ptr(), labels.write_ptr());
|
|
86
96
|
}
|
|
@@ -92,15 +102,15 @@ void init_index_binary(Rice::Module& m) {
|
|
|
92
102
|
})
|
|
93
103
|
.define_method(
|
|
94
104
|
"reconstruct",
|
|
95
|
-
[](faiss::IndexBinary
|
|
96
|
-
auto d = static_cast<
|
|
97
|
-
|
|
105
|
+
[](faiss::IndexBinary& self, int64_t key) {
|
|
106
|
+
auto d = static_cast<size_t>(self.d / 8);
|
|
107
|
+
numo::UInt8 recons({d});
|
|
98
108
|
self.reconstruct(key, recons.write_ptr());
|
|
99
109
|
return recons;
|
|
100
110
|
})
|
|
101
111
|
.define_method(
|
|
102
112
|
"reconstruct_n",
|
|
103
|
-
[](faiss::IndexBinary
|
|
113
|
+
[](faiss::IndexBinary& self, int64_t i0, int64_t ni) {
|
|
104
114
|
if (ni < 0) {
|
|
105
115
|
throw Rice::Exception(rb_eArgError, "expected n to be non-negative");
|
|
106
116
|
}
|
|
@@ -108,15 +118,15 @@ void init_index_binary(Rice::Module& m) {
|
|
|
108
118
|
if (i0 < 0 || i0 > self.ntotal - ni) {
|
|
109
119
|
throw Rice::Exception(rb_eIndexError, "index out of range");
|
|
110
120
|
}
|
|
111
|
-
auto d = static_cast<
|
|
112
|
-
auto n = static_cast<
|
|
113
|
-
|
|
121
|
+
auto d = static_cast<size_t>(self.d / 8);
|
|
122
|
+
auto n = static_cast<size_t>(ni);
|
|
123
|
+
numo::UInt8 recons({n, d});
|
|
114
124
|
self.reconstruct_n(i0, ni, recons.write_ptr());
|
|
115
125
|
return recons;
|
|
116
126
|
})
|
|
117
127
|
.define_method(
|
|
118
128
|
"save",
|
|
119
|
-
[](faiss::IndexBinary
|
|
129
|
+
[](faiss::IndexBinary& self, Rice::String fname) {
|
|
120
130
|
faiss::write_index_binary(&self, fname.c_str());
|
|
121
131
|
})
|
|
122
132
|
.define_singleton_function(
|
data/ext/faiss/kmeans.cpp
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#include <algorithm>
|
|
2
|
+
#include <cstddef>
|
|
2
3
|
|
|
3
4
|
#include <faiss/Clustering.h>
|
|
4
5
|
#include <faiss/IndexFlat.h>
|
|
@@ -17,27 +18,27 @@ void init_kmeans(Rice::Module& m) {
|
|
|
17
18
|
})
|
|
18
19
|
.define_method(
|
|
19
20
|
"d",
|
|
20
|
-
[](faiss::Clustering
|
|
21
|
+
[](faiss::Clustering& self) {
|
|
21
22
|
return self.d;
|
|
22
23
|
})
|
|
23
24
|
.define_method(
|
|
24
25
|
"k",
|
|
25
|
-
[](faiss::Clustering
|
|
26
|
+
[](faiss::Clustering& self) {
|
|
26
27
|
return self.k;
|
|
27
28
|
})
|
|
28
29
|
.define_method(
|
|
29
30
|
"centroids",
|
|
30
|
-
[](faiss::Clustering
|
|
31
|
-
|
|
32
|
-
std::copy(self.centroids
|
|
31
|
+
[](faiss::Clustering& self) {
|
|
32
|
+
numo::SFloat centroids({self.k, self.d});
|
|
33
|
+
std::ranges::copy(self.centroids, centroids.write_ptr());
|
|
33
34
|
return centroids;
|
|
34
35
|
})
|
|
35
36
|
.define_method(
|
|
36
37
|
"train",
|
|
37
38
|
[](Rice::Object rb_self, numo::SFloat objects) {
|
|
38
|
-
auto
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
auto& self = *Rice::Data_Object<faiss::Clustering>{rb_self};
|
|
40
|
+
size_t n = check_shape(objects, self.d);
|
|
41
|
+
faiss::IndexFlatL2 index(self.d);
|
|
41
42
|
rb_self.iv_set("@index", index);
|
|
42
43
|
self.train(n, objects.read_ptr(), index);
|
|
43
44
|
});
|
data/ext/faiss/pca_matrix.cpp
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
#include <cstddef>
|
|
2
|
+
|
|
1
3
|
#include <faiss/VectorTransform.h>
|
|
2
4
|
#include <rice/rice.hpp>
|
|
3
5
|
|
|
@@ -9,26 +11,26 @@ void init_pca_matrix(Rice::Module& m) {
|
|
|
9
11
|
.define_constructor(Rice::Constructor<faiss::PCAMatrix, int, int>())
|
|
10
12
|
.define_method(
|
|
11
13
|
"d_in",
|
|
12
|
-
[](faiss::PCAMatrix
|
|
14
|
+
[](faiss::PCAMatrix& self) {
|
|
13
15
|
return self.d_in;
|
|
14
16
|
})
|
|
15
17
|
.define_method(
|
|
16
18
|
"d_out",
|
|
17
|
-
[](faiss::PCAMatrix
|
|
19
|
+
[](faiss::PCAMatrix& self) {
|
|
18
20
|
return self.d_out;
|
|
19
21
|
})
|
|
20
22
|
.define_method(
|
|
21
23
|
"train",
|
|
22
|
-
[](faiss::PCAMatrix
|
|
23
|
-
|
|
24
|
+
[](faiss::PCAMatrix& self, numo::SFloat objects) {
|
|
25
|
+
size_t n = check_shape(objects, self.d_in);
|
|
24
26
|
self.train(n, objects.read_ptr());
|
|
25
27
|
})
|
|
26
28
|
.define_method(
|
|
27
29
|
"apply",
|
|
28
|
-
[](faiss::PCAMatrix
|
|
29
|
-
|
|
30
|
+
[](faiss::PCAMatrix& self, numo::SFloat objects) {
|
|
31
|
+
size_t n = check_shape(objects, self.d_in);
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
numo::SFloat ary({n, static_cast<size_t>(self.d_out)});
|
|
32
34
|
self.apply_noalloc(n, objects.read_ptr(), ary.write_ptr());
|
|
33
35
|
return ary;
|
|
34
36
|
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
#include <cstddef>
|
|
2
|
+
|
|
1
3
|
#include <faiss/impl/ProductQuantizer.h>
|
|
2
4
|
#include <faiss/index_io.h>
|
|
3
5
|
#include <rice/rice.hpp>
|
|
@@ -10,41 +12,41 @@ void init_product_quantizer(Rice::Module& m) {
|
|
|
10
12
|
.define_constructor(Rice::Constructor<faiss::ProductQuantizer, size_t, size_t, size_t>())
|
|
11
13
|
.define_method(
|
|
12
14
|
"d",
|
|
13
|
-
[](faiss::ProductQuantizer
|
|
15
|
+
[](faiss::ProductQuantizer& self) {
|
|
14
16
|
return self.d;
|
|
15
17
|
})
|
|
16
18
|
.define_method(
|
|
17
19
|
"m",
|
|
18
|
-
[](faiss::ProductQuantizer
|
|
20
|
+
[](faiss::ProductQuantizer& self) {
|
|
19
21
|
return self.M;
|
|
20
22
|
})
|
|
21
23
|
.define_method(
|
|
22
24
|
"train",
|
|
23
|
-
[](faiss::ProductQuantizer
|
|
24
|
-
|
|
25
|
+
[](faiss::ProductQuantizer& self, numo::SFloat objects) {
|
|
26
|
+
size_t n = check_shape(objects, self.d);
|
|
25
27
|
self.train(n, objects.read_ptr());
|
|
26
28
|
})
|
|
27
29
|
.define_method(
|
|
28
30
|
"compute_codes",
|
|
29
|
-
[](faiss::ProductQuantizer
|
|
30
|
-
|
|
31
|
+
[](faiss::ProductQuantizer& self, numo::SFloat objects) {
|
|
32
|
+
size_t n = check_shape(objects, self.d);
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
numo::UInt8 codes({n, self.M});
|
|
33
35
|
self.compute_codes(objects.read_ptr(), codes.write_ptr(), n);
|
|
34
36
|
return codes;
|
|
35
37
|
})
|
|
36
38
|
.define_method(
|
|
37
39
|
"decode",
|
|
38
|
-
[](faiss::ProductQuantizer
|
|
39
|
-
|
|
40
|
+
[](faiss::ProductQuantizer& self, numo::UInt8 objects) {
|
|
41
|
+
size_t n = check_shape(objects, self.M);
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
numo::SFloat x({n, self.d});
|
|
42
44
|
self.decode(objects.read_ptr(), x.write_ptr(), n);
|
|
43
45
|
return x;
|
|
44
46
|
})
|
|
45
47
|
.define_method(
|
|
46
48
|
"save",
|
|
47
|
-
[](faiss::ProductQuantizer
|
|
49
|
+
[](faiss::ProductQuantizer& self, Rice::String fname) {
|
|
48
50
|
faiss::write_ProductQuantizer(&self, fname.c_str());
|
|
49
51
|
})
|
|
50
52
|
.define_singleton_function(
|
data/ext/faiss/utils.cpp
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
#include <cstddef>
|
|
2
|
+
|
|
1
3
|
#include <rice/rice.hpp>
|
|
2
4
|
|
|
3
5
|
#include "numo.hpp"
|
|
4
6
|
#include "utils.h"
|
|
5
7
|
|
|
6
8
|
size_t check_shape(const numo::NArray& objects, size_t k) {
|
|
7
|
-
|
|
9
|
+
size_t ndim = objects.ndim();
|
|
8
10
|
if (ndim != 2) {
|
|
9
11
|
throw Rice::Exception(rb_eArgError, "expected 2 dimensions, not %d", ndim);
|
|
10
12
|
}
|
|
11
|
-
|
|
13
|
+
size_t* shape = objects.shape();
|
|
12
14
|
if (shape[1] != k) {
|
|
13
15
|
throw Rice::Exception(rb_eArgError, "expected 2nd dimension to be %d, not %d", k, shape[1]);
|
|
14
16
|
}
|
data/ext/faiss/utils.h
CHANGED
data/lib/faiss/version.rb
CHANGED
data/lib/faiss.rb
CHANGED