faiss 0.3.1 → 0.3.3
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 +8 -0
- data/LICENSE.txt +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +2 -2
- data/vendor/faiss/faiss/AutoTune.h +3 -3
- data/vendor/faiss/faiss/Clustering.cpp +37 -6
- data/vendor/faiss/faiss/Clustering.h +12 -3
- data/vendor/faiss/faiss/IVFlib.cpp +6 -3
- data/vendor/faiss/faiss/IVFlib.h +2 -2
- data/vendor/faiss/faiss/Index.cpp +6 -2
- data/vendor/faiss/faiss/Index.h +30 -8
- data/vendor/faiss/faiss/Index2Layer.cpp +2 -2
- data/vendor/faiss/faiss/Index2Layer.h +2 -2
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +7 -7
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +14 -16
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +2 -2
- data/vendor/faiss/faiss/IndexBinary.cpp +13 -2
- data/vendor/faiss/faiss/IndexBinary.h +8 -2
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +2 -3
- data/vendor/faiss/faiss/IndexBinaryFlat.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +2 -2
- data/vendor/faiss/faiss/IndexBinaryFromFloat.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +2 -7
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +3 -3
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +2 -3
- data/vendor/faiss/faiss/IndexBinaryHash.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +3 -3
- data/vendor/faiss/faiss/IndexBinaryIVF.h +2 -2
- data/vendor/faiss/faiss/IndexFastScan.cpp +32 -18
- data/vendor/faiss/faiss/IndexFastScan.h +11 -2
- data/vendor/faiss/faiss/IndexFlat.cpp +13 -10
- data/vendor/faiss/faiss/IndexFlat.h +2 -2
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +170 -7
- data/vendor/faiss/faiss/IndexFlatCodes.h +25 -5
- data/vendor/faiss/faiss/IndexHNSW.cpp +156 -96
- data/vendor/faiss/faiss/IndexHNSW.h +54 -5
- data/vendor/faiss/faiss/IndexIDMap.cpp +19 -3
- data/vendor/faiss/faiss/IndexIDMap.h +5 -2
- data/vendor/faiss/faiss/IndexIVF.cpp +5 -6
- data/vendor/faiss/faiss/IndexIVF.h +13 -4
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +21 -7
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.h +5 -2
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +3 -14
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +2 -4
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +201 -91
- data/vendor/faiss/faiss/IndexIVFFastScan.h +33 -9
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFFlat.h +2 -2
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +3 -6
- data/vendor/faiss/faiss/IndexIVFPQ.h +2 -2
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +7 -14
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +2 -4
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFPQR.h +2 -2
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +2 -3
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +2 -2
- data/vendor/faiss/faiss/IndexLSH.cpp +2 -3
- data/vendor/faiss/faiss/IndexLSH.h +2 -2
- data/vendor/faiss/faiss/IndexLattice.cpp +3 -21
- data/vendor/faiss/faiss/IndexLattice.h +5 -24
- data/vendor/faiss/faiss/IndexNNDescent.cpp +2 -31
- data/vendor/faiss/faiss/IndexNNDescent.h +3 -3
- data/vendor/faiss/faiss/IndexNSG.cpp +2 -5
- data/vendor/faiss/faiss/IndexNSG.h +3 -3
- data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +56 -0
- data/vendor/faiss/faiss/IndexNeuralNetCodec.h +49 -0
- data/vendor/faiss/faiss/IndexPQ.cpp +26 -26
- data/vendor/faiss/faiss/IndexPQ.h +2 -2
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +2 -5
- data/vendor/faiss/faiss/IndexPQFastScan.h +2 -11
- data/vendor/faiss/faiss/IndexPreTransform.cpp +2 -2
- data/vendor/faiss/faiss/IndexPreTransform.h +3 -3
- data/vendor/faiss/faiss/IndexRefine.cpp +46 -9
- data/vendor/faiss/faiss/IndexRefine.h +9 -2
- data/vendor/faiss/faiss/IndexReplicas.cpp +2 -2
- data/vendor/faiss/faiss/IndexReplicas.h +2 -2
- data/vendor/faiss/faiss/IndexRowwiseMinMax.cpp +2 -2
- data/vendor/faiss/faiss/IndexRowwiseMinMax.h +2 -2
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +5 -4
- data/vendor/faiss/faiss/IndexScalarQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexShards.cpp +2 -2
- data/vendor/faiss/faiss/IndexShards.h +2 -2
- data/vendor/faiss/faiss/IndexShardsIVF.cpp +2 -2
- data/vendor/faiss/faiss/IndexShardsIVF.h +2 -2
- data/vendor/faiss/faiss/MatrixStats.cpp +2 -2
- data/vendor/faiss/faiss/MatrixStats.h +2 -2
- data/vendor/faiss/faiss/MetaIndexes.cpp +2 -3
- data/vendor/faiss/faiss/MetaIndexes.h +2 -2
- data/vendor/faiss/faiss/MetricType.h +9 -4
- data/vendor/faiss/faiss/VectorTransform.cpp +2 -2
- data/vendor/faiss/faiss/VectorTransform.h +2 -2
- data/vendor/faiss/faiss/clone_index.cpp +2 -2
- data/vendor/faiss/faiss/clone_index.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/SaDecodeKernels.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/detail/CoarseBitType.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/detail/UintReader.h +97 -19
- data/vendor/faiss/faiss/cppcontrib/factory_tools.cpp +192 -0
- data/vendor/faiss/faiss/cppcontrib/factory_tools.h +29 -0
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +85 -32
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-neon-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMax-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMaxFP16-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-neon-inl.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuAutoTune.cpp +2 -5
- data/vendor/faiss/faiss/gpu/GpuAutoTune.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +45 -13
- data/vendor/faiss/faiss/gpu/GpuCloner.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +12 -6
- data/vendor/faiss/faiss/gpu/GpuDistance.h +11 -7
- data/vendor/faiss/faiss/gpu/GpuFaissAssert.h +3 -3
- data/vendor/faiss/faiss/gpu/GpuIcmEncoder.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndex.h +10 -15
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +285 -0
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +8 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +4 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +3 -3
- data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndicesOptions.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuResources.cpp +7 -2
- data/vendor/faiss/faiss/gpu/GpuResources.h +11 -4
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +66 -11
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +15 -5
- data/vendor/faiss/faiss/gpu/impl/IndexUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +28 -23
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.h +2 -2
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +2 -2
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/PerfClustering.cpp +8 -2
- data/vendor/faiss/faiss/gpu/perf/PerfIVFPQAdd.cpp +2 -3
- data/vendor/faiss/faiss/gpu/perf/WriteIndex.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +10 -7
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +54 -54
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +144 -77
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +51 -51
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestGpuMemoryException.cpp +3 -3
- data/vendor/faiss/faiss/gpu/test/TestGpuResidualQuantizer.cpp +70 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +74 -4
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/test/demo_ivfpq_indexing_gpu.cpp +3 -3
- data/vendor/faiss/faiss/gpu/utils/{RaftUtils.h → CuvsUtils.h} +12 -11
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +8 -2
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +2 -2
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.h +2 -2
- data/vendor/faiss/faiss/gpu/utils/StaticUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/utils/Timer.cpp +6 -3
- data/vendor/faiss/faiss/gpu/utils/Timer.h +3 -3
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +79 -11
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +17 -5
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +27 -2
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +11 -3
- data/vendor/faiss/faiss/impl/CodePacker.cpp +2 -2
- data/vendor/faiss/faiss/impl/CodePacker.h +2 -2
- data/vendor/faiss/faiss/impl/DistanceComputer.h +48 -2
- data/vendor/faiss/faiss/impl/FaissAssert.h +6 -4
- data/vendor/faiss/faiss/impl/FaissException.cpp +2 -2
- data/vendor/faiss/faiss/impl/FaissException.h +2 -3
- data/vendor/faiss/faiss/impl/HNSW.cpp +378 -205
- data/vendor/faiss/faiss/impl/HNSW.h +55 -24
- data/vendor/faiss/faiss/impl/IDSelector.cpp +2 -2
- data/vendor/faiss/faiss/impl/IDSelector.h +2 -2
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +10 -10
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +2 -2
- data/vendor/faiss/faiss/impl/LookupTableScaler.h +36 -2
- data/vendor/faiss/faiss/impl/NNDescent.cpp +15 -10
- data/vendor/faiss/faiss/impl/NNDescent.h +2 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +26 -49
- data/vendor/faiss/faiss/impl/NSG.h +20 -8
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +2 -2
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +2 -2
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +2 -4
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.h +2 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +2 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +3 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +7 -3
- data/vendor/faiss/faiss/impl/Quantizer.h +2 -2
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +2 -36
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +3 -13
- data/vendor/faiss/faiss/impl/ResultHandler.h +153 -34
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +721 -104
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +5 -2
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +2 -2
- data/vendor/faiss/faiss/impl/ThreadedIndex.h +2 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-avx2.h +7 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-avx512.h +248 -0
- data/vendor/faiss/faiss/impl/code_distance/code_distance-generic.h +2 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-sve.h +440 -0
- data/vendor/faiss/faiss/impl/code_distance/code_distance.h +55 -2
- data/vendor/faiss/faiss/impl/index_read.cpp +31 -20
- data/vendor/faiss/faiss/impl/index_read_utils.h +37 -0
- data/vendor/faiss/faiss/impl/index_write.cpp +30 -16
- data/vendor/faiss/faiss/impl/io.cpp +15 -7
- data/vendor/faiss/faiss/impl/io.h +6 -6
- data/vendor/faiss/faiss/impl/io_macros.h +8 -9
- data/vendor/faiss/faiss/impl/kmeans1d.cpp +2 -3
- data/vendor/faiss/faiss/impl/kmeans1d.h +2 -2
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +2 -3
- data/vendor/faiss/faiss/impl/lattice_Zn.h +2 -2
- data/vendor/faiss/faiss/impl/platform_macros.h +34 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +13 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +20 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +3 -3
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +450 -3
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +8 -8
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +3 -3
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +151 -67
- data/vendor/faiss/faiss/index_factory.cpp +51 -34
- data/vendor/faiss/faiss/index_factory.h +2 -2
- data/vendor/faiss/faiss/index_io.h +14 -7
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +30 -10
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +5 -2
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +11 -3
- data/vendor/faiss/faiss/invlists/DirectMap.h +2 -2
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +57 -19
- data/vendor/faiss/faiss/invlists/InvertedLists.h +20 -11
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +2 -2
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +2 -2
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +23 -9
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +4 -3
- data/vendor/faiss/faiss/python/python_callbacks.cpp +5 -5
- data/vendor/faiss/faiss/python/python_callbacks.h +2 -2
- data/vendor/faiss/faiss/utils/AlignedTable.h +5 -3
- data/vendor/faiss/faiss/utils/Heap.cpp +2 -2
- data/vendor/faiss/faiss/utils/Heap.h +107 -2
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +346 -0
- data/vendor/faiss/faiss/utils/NeuralNet.h +147 -0
- data/vendor/faiss/faiss/utils/WorkerThread.cpp +2 -2
- data/vendor/faiss/faiss/utils/WorkerThread.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/generic.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/mode.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +2 -2
- data/vendor/faiss/faiss/utils/bf16.h +36 -0
- data/vendor/faiss/faiss/utils/distances.cpp +249 -90
- data/vendor/faiss/faiss/utils/distances.h +8 -8
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/avx512.h +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.h +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.h +2 -2
- data/vendor/faiss/faiss/utils/distances_simd.cpp +1543 -56
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +72 -2
- data/vendor/faiss/faiss/utils/extra_distances.cpp +87 -140
- data/vendor/faiss/faiss/utils/extra_distances.h +5 -4
- data/vendor/faiss/faiss/utils/fp16-arm.h +2 -2
- data/vendor/faiss/faiss/utils/fp16-fp16c.h +2 -2
- data/vendor/faiss/faiss/utils/fp16-inl.h +2 -2
- data/vendor/faiss/faiss/utils/fp16.h +2 -2
- data/vendor/faiss/faiss/utils/hamming-inl.h +2 -2
- data/vendor/faiss/faiss/utils/hamming.cpp +3 -4
- data/vendor/faiss/faiss/utils/hamming.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/avx512-inl.h +490 -0
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +6 -3
- data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +7 -3
- data/vendor/faiss/faiss/utils/hamming_distance/neon-inl.h +5 -5
- data/vendor/faiss/faiss/utils/ordered_key_value.h +2 -2
- data/vendor/faiss/faiss/utils/partitioning.cpp +2 -2
- data/vendor/faiss/faiss/utils/partitioning.h +2 -2
- data/vendor/faiss/faiss/utils/prefetch.h +2 -2
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +2 -2
- data/vendor/faiss/faiss/utils/quantize_lut.h +2 -2
- data/vendor/faiss/faiss/utils/random.cpp +45 -2
- data/vendor/faiss/faiss/utils/random.h +27 -2
- data/vendor/faiss/faiss/utils/simdlib.h +12 -3
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_avx512.h +296 -0
- data/vendor/faiss/faiss/utils/simdlib_emulated.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_neon.h +7 -4
- data/vendor/faiss/faiss/utils/simdlib_ppc64.h +1084 -0
- data/vendor/faiss/faiss/utils/sorting.cpp +2 -2
- data/vendor/faiss/faiss/utils/sorting.h +2 -2
- data/vendor/faiss/faiss/utils/transpose/transpose-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +176 -0
- data/vendor/faiss/faiss/utils/utils.cpp +17 -10
- data/vendor/faiss/faiss/utils/utils.h +7 -3
- metadata +22 -11
- data/vendor/faiss/faiss/impl/code_distance/code_distance_avx512.h +0 -102
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -16,6 +16,7 @@ namespace faiss {
|
|
16
16
|
|
17
17
|
struct NormTableScaler;
|
18
18
|
struct SIMDResultHandlerToFloat;
|
19
|
+
struct Quantizer;
|
19
20
|
|
20
21
|
/** Fast scan version of IVFPQ and IVFAQ. Works for 4-bit PQ/AQ for now.
|
21
22
|
*
|
@@ -59,6 +60,9 @@ struct IndexIVFFastScan : IndexIVF {
|
|
59
60
|
int qbs = 0;
|
60
61
|
size_t qbs2 = 0;
|
61
62
|
|
63
|
+
// quantizer used to pack the codes
|
64
|
+
Quantizer* fine_quantizer = nullptr;
|
65
|
+
|
62
66
|
IndexIVFFastScan(
|
63
67
|
Index* quantizer,
|
64
68
|
size_t d,
|
@@ -68,7 +72,9 @@ struct IndexIVFFastScan : IndexIVF {
|
|
68
72
|
|
69
73
|
IndexIVFFastScan();
|
70
74
|
|
75
|
+
/// called by implementations
|
71
76
|
void init_fastscan(
|
77
|
+
Quantizer* fine_quantizer,
|
72
78
|
size_t M,
|
73
79
|
size_t nbits,
|
74
80
|
size_t nlist,
|
@@ -148,7 +154,8 @@ struct IndexIVFFastScan : IndexIVF {
|
|
148
154
|
float* distances,
|
149
155
|
idx_t* labels,
|
150
156
|
const CoarseQuantized& cq,
|
151
|
-
const NormTableScaler* scaler
|
157
|
+
const NormTableScaler* scaler,
|
158
|
+
const IVFSearchParameters* params = nullptr) const;
|
152
159
|
|
153
160
|
void range_search_dispatch_implem(
|
154
161
|
idx_t n,
|
@@ -156,7 +163,8 @@ struct IndexIVFFastScan : IndexIVF {
|
|
156
163
|
float radius,
|
157
164
|
RangeSearchResult& rres,
|
158
165
|
const CoarseQuantized& cq_in,
|
159
|
-
const NormTableScaler* scaler
|
166
|
+
const NormTableScaler* scaler,
|
167
|
+
const IVFSearchParameters* params = nullptr) const;
|
160
168
|
|
161
169
|
// impl 1 and 2 are just for verification
|
162
170
|
template <class C>
|
@@ -167,7 +175,8 @@ struct IndexIVFFastScan : IndexIVF {
|
|
167
175
|
float* distances,
|
168
176
|
idx_t* labels,
|
169
177
|
const CoarseQuantized& cq,
|
170
|
-
const NormTableScaler* scaler
|
178
|
+
const NormTableScaler* scaler,
|
179
|
+
const IVFSearchParameters* params = nullptr) const;
|
171
180
|
|
172
181
|
template <class C>
|
173
182
|
void search_implem_2(
|
@@ -177,7 +186,8 @@ struct IndexIVFFastScan : IndexIVF {
|
|
177
186
|
float* distances,
|
178
187
|
idx_t* labels,
|
179
188
|
const CoarseQuantized& cq,
|
180
|
-
const NormTableScaler* scaler
|
189
|
+
const NormTableScaler* scaler,
|
190
|
+
const IVFSearchParameters* params = nullptr) const;
|
181
191
|
|
182
192
|
// implem 10 and 12 are not multithreaded internally, so
|
183
193
|
// export search stats
|
@@ -188,7 +198,8 @@ struct IndexIVFFastScan : IndexIVF {
|
|
188
198
|
const CoarseQuantized& cq,
|
189
199
|
size_t* ndis_out,
|
190
200
|
size_t* nlist_out,
|
191
|
-
const NormTableScaler* scaler
|
201
|
+
const NormTableScaler* scaler,
|
202
|
+
const IVFSearchParameters* params = nullptr) const;
|
192
203
|
|
193
204
|
void search_implem_12(
|
194
205
|
idx_t n,
|
@@ -197,7 +208,8 @@ struct IndexIVFFastScan : IndexIVF {
|
|
197
208
|
const CoarseQuantized& cq,
|
198
209
|
size_t* ndis_out,
|
199
210
|
size_t* nlist_out,
|
200
|
-
const NormTableScaler* scaler
|
211
|
+
const NormTableScaler* scaler,
|
212
|
+
const IVFSearchParameters* params = nullptr) const;
|
201
213
|
|
202
214
|
// implem 14 is multithreaded internally across nprobes and queries
|
203
215
|
void search_implem_14(
|
@@ -208,7 +220,8 @@ struct IndexIVFFastScan : IndexIVF {
|
|
208
220
|
idx_t* labels,
|
209
221
|
const CoarseQuantized& cq,
|
210
222
|
int impl,
|
211
|
-
const NormTableScaler* scaler
|
223
|
+
const NormTableScaler* scaler,
|
224
|
+
const IVFSearchParameters* params = nullptr) const;
|
212
225
|
|
213
226
|
// reconstruct vectors from packed invlists
|
214
227
|
void reconstruct_from_offset(int64_t list_no, int64_t offset, float* recons)
|
@@ -218,6 +231,17 @@ struct IndexIVFFastScan : IndexIVF {
|
|
218
231
|
|
219
232
|
// reconstruct orig invlists (for debugging)
|
220
233
|
void reconstruct_orig_invlists();
|
234
|
+
|
235
|
+
/** Decode a set of vectors.
|
236
|
+
*
|
237
|
+
* NOTE: The codes in the IndexFastScan object are non-contiguous.
|
238
|
+
* But this method requires a contiguous representation.
|
239
|
+
*
|
240
|
+
* @param n number of vectors
|
241
|
+
* @param bytes input encoded vectors, size n * code_size
|
242
|
+
* @param x output vectors, size n * d
|
243
|
+
*/
|
244
|
+
void sa_decode(idx_t n, const uint8_t* bytes, float* x) const override;
|
221
245
|
};
|
222
246
|
|
223
247
|
struct IVFFastScanStats {
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -22,7 +22,6 @@
|
|
22
22
|
#include <faiss/utils/utils.h>
|
23
23
|
|
24
24
|
#include <faiss/Clustering.h>
|
25
|
-
#include <faiss/IndexFlat.h>
|
26
25
|
|
27
26
|
#include <faiss/utils/hamming.h>
|
28
27
|
|
@@ -318,16 +317,14 @@ void IndexIVFPQ::reconstruct_from_offset(
|
|
318
317
|
float* recons) const {
|
319
318
|
const uint8_t* code = invlists->get_single_code(list_no, offset);
|
320
319
|
|
320
|
+
pq.decode(code, recons);
|
321
321
|
if (by_residual) {
|
322
322
|
std::vector<float> centroid(d);
|
323
323
|
quantizer->reconstruct(list_no, centroid.data());
|
324
324
|
|
325
|
-
pq.decode(code, recons);
|
326
325
|
for (int i = 0; i < d; ++i) {
|
327
326
|
recons[i] += centroid[i];
|
328
327
|
}
|
329
|
-
} else {
|
330
|
-
pq.decode(code, recons);
|
331
328
|
}
|
332
329
|
}
|
333
330
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -11,21 +11,17 @@
|
|
11
11
|
#include <cinttypes>
|
12
12
|
#include <cstdio>
|
13
13
|
|
14
|
-
#include <omp.h>
|
15
|
-
|
16
14
|
#include <memory>
|
17
15
|
|
18
16
|
#include <faiss/impl/AuxIndexStructures.h>
|
19
17
|
#include <faiss/impl/FaissAssert.h>
|
20
18
|
#include <faiss/utils/distances.h>
|
21
19
|
#include <faiss/utils/simdlib.h>
|
22
|
-
#include <faiss/utils/utils.h>
|
23
20
|
|
24
21
|
#include <faiss/invlists/BlockInvertedLists.h>
|
25
22
|
|
26
23
|
#include <faiss/impl/pq4_fast_scan.h>
|
27
24
|
#include <faiss/impl/simd_result_handlers.h>
|
28
|
-
#include <faiss/utils/quantize_lut.h>
|
29
25
|
|
30
26
|
namespace faiss {
|
31
27
|
|
@@ -46,7 +42,7 @@ IndexIVFPQFastScan::IndexIVFPQFastScan(
|
|
46
42
|
: IndexIVFFastScan(quantizer, d, nlist, 0, metric), pq(d, M, nbits) {
|
47
43
|
by_residual = false; // set to false by default because it's faster
|
48
44
|
|
49
|
-
init_fastscan(M, nbits, nlist, metric, bbs);
|
45
|
+
init_fastscan(&pq, M, nbits, nlist, metric, bbs);
|
50
46
|
}
|
51
47
|
|
52
48
|
IndexIVFPQFastScan::IndexIVFPQFastScan() {
|
@@ -65,7 +61,8 @@ IndexIVFPQFastScan::IndexIVFPQFastScan(const IndexIVFPQ& orig, int bbs)
|
|
65
61
|
pq(orig.pq) {
|
66
62
|
FAISS_THROW_IF_NOT(orig.pq.nbits == 4);
|
67
63
|
|
68
|
-
init_fastscan(
|
64
|
+
init_fastscan(
|
65
|
+
&pq, orig.pq.M, orig.pq.nbits, orig.nlist, orig.metric_type, bbs);
|
69
66
|
|
70
67
|
by_residual = orig.by_residual;
|
71
68
|
ntotal = orig.ntotal;
|
@@ -80,7 +77,8 @@ IndexIVFPQFastScan::IndexIVFPQFastScan(const IndexIVFPQ& orig, int bbs)
|
|
80
77
|
precomputed_table.nbytes());
|
81
78
|
}
|
82
79
|
|
83
|
-
|
80
|
+
#pragma omp parallel for if (nlist > 100)
|
81
|
+
for (idx_t i = 0; i < nlist; i++) {
|
84
82
|
size_t nb = orig.invlists->list_size(i);
|
85
83
|
size_t nb2 = roundup(nb, bbs);
|
86
84
|
AlignedTable<uint8_t> tmp(nb2 * M2 / 2);
|
@@ -286,9 +284,4 @@ void IndexIVFPQFastScan::compute_LUT(
|
|
286
284
|
}
|
287
285
|
}
|
288
286
|
|
289
|
-
void IndexIVFPQFastScan::sa_decode(idx_t n, const uint8_t* bytes, float* x)
|
290
|
-
const {
|
291
|
-
pq.decode(bytes, x, n);
|
292
|
-
}
|
293
|
-
|
294
287
|
} // namespace faiss
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -80,8 +80,6 @@ struct IndexIVFPQFastScan : IndexIVFFastScan {
|
|
80
80
|
const CoarseQuantized& cq,
|
81
81
|
AlignedTable<float>& dis_tables,
|
82
82
|
AlignedTable<float>& biases) const override;
|
83
|
-
|
84
|
-
void sa_decode(idx_t n, const uint8_t* bytes, float* x) const override;
|
85
83
|
};
|
86
84
|
|
87
85
|
} // namespace faiss
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -19,7 +19,6 @@
|
|
19
19
|
#include <faiss/impl/AuxIndexStructures.h>
|
20
20
|
#include <faiss/impl/FaissAssert.h>
|
21
21
|
#include <faiss/utils/hamming.h>
|
22
|
-
#include <faiss/utils/utils.h>
|
23
22
|
|
24
23
|
namespace faiss {
|
25
24
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -15,7 +15,6 @@
|
|
15
15
|
|
16
16
|
#include <faiss/impl/FaissAssert.h>
|
17
17
|
#include <faiss/utils/hamming.h>
|
18
|
-
#include <faiss/utils/utils.h>
|
19
18
|
|
20
19
|
namespace faiss {
|
21
20
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -15,7 +15,7 @@
|
|
15
15
|
namespace faiss {
|
16
16
|
|
17
17
|
IndexLattice::IndexLattice(idx_t d, int nsq, int scale_nbit, int r2)
|
18
|
-
:
|
18
|
+
: IndexFlatCodes(0, d, METRIC_L2),
|
19
19
|
nsq(nsq),
|
20
20
|
dsq(d / nsq),
|
21
21
|
zn_sphere_codec(dsq, r2),
|
@@ -114,22 +114,4 @@ void IndexLattice::sa_decode(idx_t n, const uint8_t* codes, float* x) const {
|
|
114
114
|
}
|
115
115
|
}
|
116
116
|
|
117
|
-
void IndexLattice::add(idx_t, const float*) {
|
118
|
-
FAISS_THROW_MSG("not implemented");
|
119
|
-
}
|
120
|
-
|
121
|
-
void IndexLattice::search(
|
122
|
-
idx_t,
|
123
|
-
const float*,
|
124
|
-
idx_t,
|
125
|
-
float*,
|
126
|
-
idx_t*,
|
127
|
-
const SearchParameters*) const {
|
128
|
-
FAISS_THROW_MSG("not implemented");
|
129
|
-
}
|
130
|
-
|
131
|
-
void IndexLattice::reset() {
|
132
|
-
FAISS_THROW_MSG("not implemented");
|
133
|
-
}
|
134
|
-
|
135
117
|
} // namespace faiss
|
@@ -1,25 +1,22 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*/
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
#ifndef FAISS_INDEX_LATTICE_H
|
11
|
-
#define FAISS_INDEX_LATTICE_H
|
8
|
+
#pragma once
|
12
9
|
|
13
10
|
#include <vector>
|
14
11
|
|
15
|
-
#include <faiss/
|
12
|
+
#include <faiss/IndexFlatCodes.h>
|
16
13
|
#include <faiss/impl/lattice_Zn.h>
|
17
14
|
|
18
15
|
namespace faiss {
|
19
16
|
|
20
17
|
/** Index that encodes a vector with a series of Zn lattice quantizers
|
21
18
|
*/
|
22
|
-
struct IndexLattice :
|
19
|
+
struct IndexLattice : IndexFlatCodes {
|
23
20
|
/// number of sub-vectors
|
24
21
|
int nsq;
|
25
22
|
/// dimension of sub-vectors
|
@@ -30,8 +27,6 @@ struct IndexLattice : Index {
|
|
30
27
|
|
31
28
|
/// nb bits used to encode the scale, per subvector
|
32
29
|
int scale_nbit, lattice_nbit;
|
33
|
-
/// total, in bytes
|
34
|
-
size_t code_size;
|
35
30
|
|
36
31
|
/// mins and maxes of the vector norms, per subquantizer
|
37
32
|
std::vector<float> trained;
|
@@ -46,20 +41,6 @@ struct IndexLattice : Index {
|
|
46
41
|
void sa_encode(idx_t n, const float* x, uint8_t* bytes) const override;
|
47
42
|
|
48
43
|
void sa_decode(idx_t n, const uint8_t* bytes, float* x) const override;
|
49
|
-
|
50
|
-
/// not implemented
|
51
|
-
void add(idx_t n, const float* x) override;
|
52
|
-
void search(
|
53
|
-
idx_t n,
|
54
|
-
const float* x,
|
55
|
-
idx_t k,
|
56
|
-
float* distances,
|
57
|
-
idx_t* labels,
|
58
|
-
const SearchParameters* params = nullptr) const override;
|
59
|
-
|
60
|
-
void reset() override;
|
61
44
|
};
|
62
45
|
|
63
46
|
} // namespace faiss
|
64
|
-
|
65
|
-
#endif
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -58,35 +58,6 @@ using storage_idx_t = NNDescent::storage_idx_t;
|
|
58
58
|
|
59
59
|
namespace {
|
60
60
|
|
61
|
-
/* Wrap the distance computer into one that negates the
|
62
|
-
distances. This makes supporting INNER_PRODUCE search easier */
|
63
|
-
|
64
|
-
struct NegativeDistanceComputer : DistanceComputer {
|
65
|
-
/// owned by this
|
66
|
-
DistanceComputer* basedis;
|
67
|
-
|
68
|
-
explicit NegativeDistanceComputer(DistanceComputer* basedis)
|
69
|
-
: basedis(basedis) {}
|
70
|
-
|
71
|
-
void set_query(const float* x) override {
|
72
|
-
basedis->set_query(x);
|
73
|
-
}
|
74
|
-
|
75
|
-
/// compute distance of vector i to current query
|
76
|
-
float operator()(idx_t i) override {
|
77
|
-
return -(*basedis)(i);
|
78
|
-
}
|
79
|
-
|
80
|
-
/// compute distance between two stored vectors
|
81
|
-
float symmetric_dis(idx_t i, idx_t j) override {
|
82
|
-
return -basedis->symmetric_dis(i, j);
|
83
|
-
}
|
84
|
-
|
85
|
-
~NegativeDistanceComputer() override {
|
86
|
-
delete basedis;
|
87
|
-
}
|
88
|
-
};
|
89
|
-
|
90
61
|
DistanceComputer* storage_distance_computer(const Index* storage) {
|
91
62
|
if (is_similarity_metric(storage->metric_type)) {
|
92
63
|
return new NegativeDistanceComputer(storage->get_distance_computer());
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -26,7 +26,7 @@ struct IndexNNDescent : Index {
|
|
26
26
|
|
27
27
|
/// Faiss results are 64-bit
|
28
28
|
|
29
|
-
// the link
|
29
|
+
// the link structure
|
30
30
|
NNDescent nndescent;
|
31
31
|
|
32
32
|
// the sequential storage
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -9,8 +9,6 @@
|
|
9
9
|
|
10
10
|
#include <faiss/IndexNSG.h>
|
11
11
|
|
12
|
-
#include <omp.h>
|
13
|
-
|
14
12
|
#include <cinttypes>
|
15
13
|
#include <memory>
|
16
14
|
|
@@ -18,7 +16,6 @@
|
|
18
16
|
#include <faiss/IndexNNDescent.h>
|
19
17
|
#include <faiss/impl/AuxIndexStructures.h>
|
20
18
|
#include <faiss/impl/FaissAssert.h>
|
21
|
-
#include <faiss/utils/Heap.h>
|
22
19
|
#include <faiss/utils/distances.h>
|
23
20
|
|
24
21
|
namespace faiss {
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -24,7 +24,7 @@ namespace faiss {
|
|
24
24
|
* link structure built on top */
|
25
25
|
|
26
26
|
struct IndexNSG : Index {
|
27
|
-
/// the link
|
27
|
+
/// the link structure
|
28
28
|
NSG nsg;
|
29
29
|
|
30
30
|
/// the sequential storage
|
@@ -0,0 +1,56 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include <faiss/IndexNeuralNetCodec.h>
|
9
|
+
#include <faiss/impl/FaissAssert.h>
|
10
|
+
#include <faiss/utils/hamming.h>
|
11
|
+
|
12
|
+
namespace faiss {
|
13
|
+
|
14
|
+
/*********************************************************
|
15
|
+
* IndexNeuralNetCodec implementation
|
16
|
+
*********************************************************/
|
17
|
+
|
18
|
+
IndexNeuralNetCodec::IndexNeuralNetCodec(
|
19
|
+
int d,
|
20
|
+
int M,
|
21
|
+
int nbits,
|
22
|
+
MetricType metric)
|
23
|
+
: IndexFlatCodes((M * nbits + 7) / 8, d, metric), M(M), nbits(nbits) {
|
24
|
+
is_trained = false;
|
25
|
+
}
|
26
|
+
|
27
|
+
void IndexNeuralNetCodec::train(idx_t n, const float* x) {
|
28
|
+
FAISS_THROW_MSG("Training not implemented in C++, use Pytorch");
|
29
|
+
}
|
30
|
+
|
31
|
+
void IndexNeuralNetCodec::sa_encode(idx_t n, const float* x, uint8_t* codes)
|
32
|
+
const {
|
33
|
+
nn::Tensor2D x_tensor(n, d, x);
|
34
|
+
nn::Int32Tensor2D codes_tensor = net->encode(x_tensor);
|
35
|
+
pack_bitstrings(n, M, nbits, codes_tensor.data(), codes, code_size);
|
36
|
+
}
|
37
|
+
|
38
|
+
void IndexNeuralNetCodec::sa_decode(idx_t n, const uint8_t* codes, float* x)
|
39
|
+
const {
|
40
|
+
nn::Int32Tensor2D codes_tensor(n, M);
|
41
|
+
unpack_bitstrings(n, M, nbits, codes, code_size, codes_tensor.data());
|
42
|
+
nn::Tensor2D x_tensor = net->decode(codes_tensor);
|
43
|
+
memcpy(x, x_tensor.data(), d * n * sizeof(float));
|
44
|
+
}
|
45
|
+
|
46
|
+
/*********************************************************
|
47
|
+
* IndexQINeuralNetCodec implementation
|
48
|
+
*********************************************************/
|
49
|
+
|
50
|
+
IndexQINCo::IndexQINCo(int d, int M, int nbits, int L, int h, MetricType metric)
|
51
|
+
: IndexNeuralNetCodec(d, M, nbits, metric),
|
52
|
+
qinco(d, 1 << nbits, L, M, h) {
|
53
|
+
net = &qinco;
|
54
|
+
}
|
55
|
+
|
56
|
+
} // namespace faiss
|
@@ -0,0 +1,49 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#pragma once
|
9
|
+
|
10
|
+
#include <vector>
|
11
|
+
|
12
|
+
#include <faiss/IndexFlatCodes.h>
|
13
|
+
#include <faiss/utils/NeuralNet.h>
|
14
|
+
|
15
|
+
namespace faiss {
|
16
|
+
|
17
|
+
struct IndexNeuralNetCodec : IndexFlatCodes {
|
18
|
+
NeuralNetCodec* net = nullptr;
|
19
|
+
size_t M, nbits;
|
20
|
+
|
21
|
+
explicit IndexNeuralNetCodec(
|
22
|
+
int d = 0,
|
23
|
+
int M = 0,
|
24
|
+
int nbits = 0,
|
25
|
+
MetricType metric = METRIC_L2);
|
26
|
+
|
27
|
+
void train(idx_t n, const float* x) override;
|
28
|
+
|
29
|
+
void sa_encode(idx_t n, const float* x, uint8_t* codes) const override;
|
30
|
+
void sa_decode(idx_t n, const uint8_t* codes, float* x) const override;
|
31
|
+
|
32
|
+
~IndexNeuralNetCodec() {}
|
33
|
+
};
|
34
|
+
|
35
|
+
struct IndexQINCo : IndexNeuralNetCodec {
|
36
|
+
QINCo qinco;
|
37
|
+
|
38
|
+
IndexQINCo(
|
39
|
+
int d,
|
40
|
+
int M,
|
41
|
+
int nbits,
|
42
|
+
int L,
|
43
|
+
int h,
|
44
|
+
MetricType metric = METRIC_L2);
|
45
|
+
|
46
|
+
~IndexQINCo() {}
|
47
|
+
};
|
48
|
+
|
49
|
+
} // namespace faiss
|