faiss 0.3.2 → 0.3.4
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/ext/faiss/extconf.rb +1 -1
- data/ext/faiss/index.cpp +10 -14
- data/ext/faiss/numo.hpp +957 -833
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +2 -2
- data/vendor/faiss/faiss/AutoTune.h +2 -2
- data/vendor/faiss/faiss/Clustering.cpp +2 -2
- data/vendor/faiss/faiss/Clustering.h +2 -2
- data/vendor/faiss/faiss/IVFlib.cpp +2 -2
- data/vendor/faiss/faiss/IVFlib.h +2 -2
- data/vendor/faiss/faiss/Index.cpp +6 -2
- data/vendor/faiss/faiss/Index.h +10 -3
- 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 +2 -2
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +2 -3
- data/vendor/faiss/faiss/IndexBinaryHash.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +2 -2
- data/vendor/faiss/faiss/IndexBinaryIVF.h +2 -2
- data/vendor/faiss/faiss/IndexFastScan.cpp +10 -14
- data/vendor/faiss/faiss/IndexFastScan.h +11 -2
- data/vendor/faiss/faiss/IndexFlat.cpp +2 -3
- data/vendor/faiss/faiss/IndexFlat.h +2 -2
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +11 -2
- data/vendor/faiss/faiss/IndexFlatCodes.h +5 -2
- data/vendor/faiss/faiss/IndexHNSW.cpp +13 -6
- data/vendor/faiss/faiss/IndexHNSW.h +2 -2
- data/vendor/faiss/faiss/IndexIDMap.cpp +19 -3
- data/vendor/faiss/faiss/IndexIDMap.h +5 -2
- data/vendor/faiss/faiss/IndexIVF.cpp +2 -3
- data/vendor/faiss/faiss/IndexIVF.h +5 -4
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +6 -7
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +3 -14
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +2 -4
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +71 -34
- data/vendor/faiss/faiss/IndexIVFFastScan.h +19 -2
- 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 +2 -3
- data/vendor/faiss/faiss/IndexIVFPQ.h +2 -2
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +7 -33
- 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 +2 -2
- data/vendor/faiss/faiss/IndexLattice.h +2 -2
- data/vendor/faiss/faiss/IndexNNDescent.cpp +2 -2
- data/vendor/faiss/faiss/IndexNNDescent.h +2 -2
- data/vendor/faiss/faiss/IndexNSG.cpp +2 -5
- data/vendor/faiss/faiss/IndexNSG.h +2 -2
- data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +2 -2
- data/vendor/faiss/faiss/IndexNeuralNetCodec.h +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/IndexRefine.cpp +41 -4
- 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 +2 -3
- 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 +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/cppcontrib/factory_tools.cpp +44 -4
- data/vendor/faiss/faiss/cppcontrib/factory_tools.h +7 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +2 -2
- 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 +13 -13
- data/vendor/faiss/faiss/gpu/GpuCloner.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +6 -6
- data/vendor/faiss/faiss/gpu/GpuDistance.h +11 -7
- data/vendor/faiss/faiss/gpu/GpuFaissAssert.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIcmEncoder.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndex.h +8 -7
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +6 -3
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +2 -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 +51 -21
- 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 +2 -2
- 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 +2 -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 +2 -2
- 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 +80 -78
- 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 +2 -2
- data/vendor/faiss/faiss/gpu/utils/{RaftUtils.h → CuvsUtils.h} +12 -11
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +2 -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 +2 -2
- data/vendor/faiss/faiss/gpu/utils/Timer.h +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/impl/FaissAssert.h +2 -2
- 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 +24 -19
- data/vendor/faiss/faiss/impl/HNSW.h +12 -2
- 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 +2 -2
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +2 -2
- data/vendor/faiss/faiss/impl/LookupTableScaler.h +2 -2
- data/vendor/faiss/faiss/impl/NNDescent.cpp +2 -2
- data/vendor/faiss/faiss/impl/NNDescent.h +2 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +27 -21
- 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 +2 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +2 -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 +2 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-avx512.h +2 -2
- 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 +2 -5
- data/vendor/faiss/faiss/impl/index_read_utils.h +2 -2
- data/vendor/faiss/faiss/impl/index_write.cpp +2 -6
- data/vendor/faiss/faiss/impl/io.cpp +2 -2
- data/vendor/faiss/faiss/impl/io.h +2 -2
- data/vendor/faiss/faiss/impl/io_macros.h +2 -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 +12 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +2 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +20 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +2 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +2 -2
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +3 -3
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +2 -2
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +18 -18
- data/vendor/faiss/faiss/index_factory.cpp +20 -21
- data/vendor/faiss/faiss/index_factory.h +2 -2
- data/vendor/faiss/faiss/index_io.h +2 -2
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +2 -2
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +2 -2
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +2 -2
- data/vendor/faiss/faiss/invlists/DirectMap.h +2 -2
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +2 -2
- data/vendor/faiss/faiss/invlists/InvertedLists.h +2 -2
- 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 +2 -3
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +2 -2
- data/vendor/faiss/faiss/python/python_callbacks.cpp +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +11 -7
- data/vendor/faiss/faiss/utils/NeuralNet.h +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/utils/distances.cpp +191 -2
- data/vendor/faiss/faiss/utils/distances.h +3 -3
- 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 +502 -3
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +2 -2
- data/vendor/faiss/faiss/utils/extra_distances.cpp +2 -3
- data/vendor/faiss/faiss/utils/extra_distances.h +2 -2
- 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 +2 -3
- 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 +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +5 -2
- 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 +2 -2
- data/vendor/faiss/faiss/utils/random.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_avx512.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_emulated.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_neon.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_ppc64.h +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/utils/utils.cpp +7 -7
- data/vendor/faiss/faiss/utils/utils.h +4 -3
- metadata +9 -10
@@ -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.
|
@@ -12,7 +12,6 @@
|
|
12
12
|
#include <cinttypes>
|
13
13
|
#include <cstdint>
|
14
14
|
#include <cstdio>
|
15
|
-
#include <limits>
|
16
15
|
|
17
16
|
#include <faiss/impl/AuxIndexStructures.h>
|
18
17
|
#include <faiss/impl/FaissAssert.h>
|
@@ -83,6 +82,23 @@ void IndexIDMapTemplate<IndexT>::add_with_ids(
|
|
83
82
|
this->ntotal = index->ntotal;
|
84
83
|
}
|
85
84
|
|
85
|
+
template <typename IndexT>
|
86
|
+
size_t IndexIDMapTemplate<IndexT>::sa_code_size() const {
|
87
|
+
return index->sa_code_size();
|
88
|
+
}
|
89
|
+
|
90
|
+
template <typename IndexT>
|
91
|
+
void IndexIDMapTemplate<IndexT>::add_sa_codes(
|
92
|
+
idx_t n,
|
93
|
+
const uint8_t* codes,
|
94
|
+
const idx_t* xids) {
|
95
|
+
index->add_sa_codes(n, codes, xids);
|
96
|
+
for (idx_t i = 0; i < n; i++) {
|
97
|
+
id_map.push_back(xids[i]);
|
98
|
+
}
|
99
|
+
this->ntotal = index->ntotal;
|
100
|
+
}
|
101
|
+
|
86
102
|
namespace {
|
87
103
|
|
88
104
|
/// RAII object to reset the IDSelector in the params object
|
@@ -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.
|
@@ -60,6 +60,9 @@ struct IndexIDMapTemplate : IndexT {
|
|
60
60
|
void merge_from(IndexT& otherIndex, idx_t add_id = 0) override;
|
61
61
|
void check_compatible_for_merge(const IndexT& otherIndex) const override;
|
62
62
|
|
63
|
+
size_t sa_code_size() const override;
|
64
|
+
void add_sa_codes(idx_t n, const uint8_t* x, const idx_t* xids) override;
|
65
|
+
|
63
66
|
~IndexIDMapTemplate() override;
|
64
67
|
IndexIDMapTemplate() {
|
65
68
|
own_fields = false;
|
@@ -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.
|
@@ -18,7 +18,6 @@
|
|
18
18
|
#include <cinttypes>
|
19
19
|
#include <cstdio>
|
20
20
|
#include <limits>
|
21
|
-
#include <memory>
|
22
21
|
|
23
22
|
#include <faiss/utils/hamming.h>
|
24
23
|
#include <faiss/utils/utils.h>
|
@@ -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.
|
@@ -258,7 +258,8 @@ struct IndexIVF : Index, IndexIVFInterface {
|
|
258
258
|
* @param codes codes to add size n * sa_code_size()
|
259
259
|
* @param xids corresponding ids, size n
|
260
260
|
*/
|
261
|
-
void add_sa_codes(idx_t n, const uint8_t* codes, const idx_t* xids)
|
261
|
+
void add_sa_codes(idx_t n, const uint8_t* codes, const idx_t* xids)
|
262
|
+
override;
|
262
263
|
|
263
264
|
/** Train the encoder for the vectors.
|
264
265
|
*
|
@@ -435,7 +436,7 @@ struct IndexIVF : Index, IndexIVFInterface {
|
|
435
436
|
size_t sa_code_size() const override;
|
436
437
|
|
437
438
|
/** encode a set of vectors
|
438
|
-
* sa_encode will call
|
439
|
+
* sa_encode will call encode_vectors with include_listno=true
|
439
440
|
* @param n nb of vectors to encode
|
440
441
|
* @param x the vectors to encode
|
441
442
|
* @param bytes output array for the codes
|
@@ -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,7 +16,6 @@
|
|
16
16
|
#include <faiss/impl/ResultHandler.h>
|
17
17
|
#include <faiss/utils/distances.h>
|
18
18
|
#include <faiss/utils/extra_distances.h>
|
19
|
-
#include <faiss/utils/utils.h>
|
20
19
|
|
21
20
|
namespace faiss {
|
22
21
|
|
@@ -186,10 +185,10 @@ struct AQInvertedListScannerDecompress : AQInvertedListScanner {
|
|
186
185
|
float coarse_dis = 0;
|
187
186
|
|
188
187
|
/// following codes come from this inverted list
|
189
|
-
void set_list(idx_t list_no, float
|
190
|
-
AQInvertedListScanner::set_list(list_no,
|
188
|
+
void set_list(idx_t list_no, float coarse_dis_2) override {
|
189
|
+
AQInvertedListScanner::set_list(list_no, coarse_dis_2);
|
191
190
|
if (ia.by_residual) {
|
192
|
-
this->coarse_dis =
|
191
|
+
this->coarse_dis = coarse_dis_2;
|
193
192
|
}
|
194
193
|
}
|
195
194
|
|
@@ -275,7 +274,7 @@ InvertedListScanner* IndexIVFAdditiveQuantizer::get_InvertedListScanner(
|
|
275
274
|
return new AQInvertedListScannerLUT<false, AdditiveQuantizer::st>( \
|
276
275
|
*this, store_pairs);
|
277
276
|
A(ST_LUT_nonorm)
|
278
|
-
|
277
|
+
A(ST_norm_from_LUT)
|
279
278
|
A(ST_norm_float)
|
280
279
|
A(ST_norm_qint8)
|
281
280
|
A(ST_norm_qint4)
|
@@ -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.
|
@@ -7,12 +7,9 @@
|
|
7
7
|
|
8
8
|
#include <faiss/IndexIVFAdditiveQuantizerFastScan.h>
|
9
9
|
|
10
|
-
#include <cassert>
|
11
10
|
#include <cinttypes>
|
12
11
|
#include <cstdio>
|
13
12
|
|
14
|
-
#include <omp.h>
|
15
|
-
|
16
13
|
#include <memory>
|
17
14
|
|
18
15
|
#include <faiss/impl/AuxIndexStructures.h>
|
@@ -23,7 +20,6 @@
|
|
23
20
|
#include <faiss/utils/distances.h>
|
24
21
|
#include <faiss/utils/hamming.h>
|
25
22
|
#include <faiss/utils/quantize_lut.h>
|
26
|
-
#include <faiss/utils/simdlib.h>
|
27
23
|
#include <faiss/utils/utils.h>
|
28
24
|
|
29
25
|
namespace faiss {
|
@@ -70,7 +66,7 @@ void IndexIVFAdditiveQuantizerFastScan::init(
|
|
70
66
|
} else {
|
71
67
|
M = aq->M;
|
72
68
|
}
|
73
|
-
init_fastscan(M, 4, nlist, metric, bbs);
|
69
|
+
init_fastscan(aq, M, 4, nlist, metric, bbs);
|
74
70
|
|
75
71
|
max_train_points = 1024 * ksub * M;
|
76
72
|
by_residual = true;
|
@@ -443,13 +439,6 @@ void IndexIVFAdditiveQuantizerFastScan::compute_LUT(
|
|
443
439
|
}
|
444
440
|
}
|
445
441
|
|
446
|
-
void IndexIVFAdditiveQuantizerFastScan::sa_decode(
|
447
|
-
idx_t n,
|
448
|
-
const uint8_t* bytes,
|
449
|
-
float* x) const {
|
450
|
-
aq->decode(bytes, x, n);
|
451
|
-
}
|
452
|
-
|
453
442
|
/********** IndexIVFLocalSearchQuantizerFastScan ************/
|
454
443
|
IndexIVFLocalSearchQuantizerFastScan::IndexIVFLocalSearchQuantizerFastScan(
|
455
444
|
Index* quantizer,
|
@@ -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.
|
@@ -96,8 +96,6 @@ struct IndexIVFAdditiveQuantizerFastScan : IndexIVFFastScan {
|
|
96
96
|
const CoarseQuantized& cq,
|
97
97
|
AlignedTable<float>& dis_tables,
|
98
98
|
AlignedTable<float>& biases) const override;
|
99
|
-
|
100
|
-
void sa_decode(idx_t n, const uint8_t* bytes, float* x) const override;
|
101
99
|
};
|
102
100
|
|
103
101
|
struct IndexIVFLocalSearchQuantizerFastScan
|
@@ -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.
|
@@ -23,7 +23,6 @@
|
|
23
23
|
#include <faiss/impl/pq4_fast_scan.h>
|
24
24
|
#include <faiss/impl/simd_result_handlers.h>
|
25
25
|
#include <faiss/invlists/BlockInvertedLists.h>
|
26
|
-
#include <faiss/utils/distances.h>
|
27
26
|
#include <faiss/utils/hamming.h>
|
28
27
|
#include <faiss/utils/quantize_lut.h>
|
29
28
|
#include <faiss/utils/utils.h>
|
@@ -56,20 +55,24 @@ IndexIVFFastScan::IndexIVFFastScan() {
|
|
56
55
|
}
|
57
56
|
|
58
57
|
void IndexIVFFastScan::init_fastscan(
|
58
|
+
Quantizer* fine_quantizer,
|
59
59
|
size_t M,
|
60
|
-
size_t
|
60
|
+
size_t nbits_init,
|
61
61
|
size_t nlist,
|
62
62
|
MetricType /* metric */,
|
63
|
-
int
|
64
|
-
FAISS_THROW_IF_NOT(
|
65
|
-
FAISS_THROW_IF_NOT(
|
63
|
+
int bbs_2) {
|
64
|
+
FAISS_THROW_IF_NOT(bbs_2 % 32 == 0);
|
65
|
+
FAISS_THROW_IF_NOT(nbits_init == 4);
|
66
|
+
FAISS_THROW_IF_NOT(fine_quantizer->d == d);
|
66
67
|
|
68
|
+
this->fine_quantizer = fine_quantizer;
|
67
69
|
this->M = M;
|
68
|
-
this->nbits =
|
69
|
-
this->bbs =
|
70
|
-
ksub = (1 <<
|
70
|
+
this->nbits = nbits_init;
|
71
|
+
this->bbs = bbs_2;
|
72
|
+
ksub = (1 << nbits_init);
|
71
73
|
M2 = roundup(M, 2);
|
72
74
|
code_size = M2 / 2;
|
75
|
+
FAISS_THROW_IF_NOT(code_size == fine_quantizer->code_size);
|
73
76
|
|
74
77
|
is_trained = false;
|
75
78
|
replace_invlists(new BlockInvertedLists(nlist, get_CodePacker()), true);
|
@@ -1029,11 +1032,11 @@ void IndexIVFFastScan::search_implem_12(
|
|
1029
1032
|
|
1030
1033
|
// prepare the result handlers
|
1031
1034
|
|
1032
|
-
int
|
1035
|
+
int actual_qbs2 = this->qbs2 ? this->qbs2 : 11;
|
1033
1036
|
|
1034
1037
|
std::vector<uint16_t> tmp_bias;
|
1035
1038
|
if (biases.get()) {
|
1036
|
-
tmp_bias.resize(
|
1039
|
+
tmp_bias.resize(actual_qbs2);
|
1037
1040
|
handler.dbias = tmp_bias.data();
|
1038
1041
|
}
|
1039
1042
|
|
@@ -1046,7 +1049,7 @@ void IndexIVFFastScan::search_implem_12(
|
|
1046
1049
|
int list_no = qcs[i0].list_no;
|
1047
1050
|
size_t i1 = i0 + 1;
|
1048
1051
|
|
1049
|
-
while (i1 < qcs.size() && i1 < i0 +
|
1052
|
+
while (i1 < qcs.size() && i1 < i0 + actual_qbs2) {
|
1050
1053
|
if (qcs[i1].list_no != list_no) {
|
1051
1054
|
break;
|
1052
1055
|
}
|
@@ -1066,7 +1069,7 @@ void IndexIVFFastScan::search_implem_12(
|
|
1066
1069
|
std::vector<int> q_map(nc), lut_entries(nc);
|
1067
1070
|
AlignedTable<uint8_t> LUT(nc * dim12);
|
1068
1071
|
memset(LUT.get(), -1, nc * dim12);
|
1069
|
-
int
|
1072
|
+
int qbs_for_list = pq4_preferred_qbs(nc);
|
1070
1073
|
|
1071
1074
|
for (size_t i = i0; i < i1; i++) {
|
1072
1075
|
const QC& qc = qcs[i];
|
@@ -1078,7 +1081,11 @@ void IndexIVFFastScan::search_implem_12(
|
|
1078
1081
|
}
|
1079
1082
|
}
|
1080
1083
|
pq4_pack_LUT_qbs_q_map(
|
1081
|
-
|
1084
|
+
qbs_for_list,
|
1085
|
+
M2,
|
1086
|
+
dis_tables.get(),
|
1087
|
+
lut_entries.data(),
|
1088
|
+
LUT.get());
|
1082
1089
|
|
1083
1090
|
// access the inverted list
|
1084
1091
|
|
@@ -1094,7 +1101,13 @@ void IndexIVFFastScan::search_implem_12(
|
|
1094
1101
|
handler.id_map = ids.get();
|
1095
1102
|
|
1096
1103
|
pq4_accumulate_loop_qbs(
|
1097
|
-
|
1104
|
+
qbs_for_list,
|
1105
|
+
list_size,
|
1106
|
+
M2,
|
1107
|
+
codes.get(),
|
1108
|
+
LUT.get(),
|
1109
|
+
handler,
|
1110
|
+
scaler);
|
1098
1111
|
// prepare for next loop
|
1099
1112
|
i0 = i1;
|
1100
1113
|
}
|
@@ -1232,11 +1245,11 @@ void IndexIVFFastScan::search_implem_14(
|
|
1232
1245
|
is_max, impl, n, k, local_dis.data(), local_idx.data(), sel));
|
1233
1246
|
handler->begin(normalizers.get());
|
1234
1247
|
|
1235
|
-
int
|
1248
|
+
int actual_qbs2 = this->qbs2 ? this->qbs2 : 11;
|
1236
1249
|
|
1237
1250
|
std::vector<uint16_t> tmp_bias;
|
1238
1251
|
if (biases.get()) {
|
1239
|
-
tmp_bias.resize(
|
1252
|
+
tmp_bias.resize(actual_qbs2);
|
1240
1253
|
handler->dbias = tmp_bias.data();
|
1241
1254
|
}
|
1242
1255
|
|
@@ -1256,7 +1269,7 @@ void IndexIVFFastScan::search_implem_14(
|
|
1256
1269
|
std::vector<int> q_map(nc), lut_entries(nc);
|
1257
1270
|
AlignedTable<uint8_t> LUT(nc * dim12);
|
1258
1271
|
memset(LUT.get(), -1, nc * dim12);
|
1259
|
-
int
|
1272
|
+
int qbs_for_list = pq4_preferred_qbs(nc);
|
1260
1273
|
|
1261
1274
|
for (size_t i = i0; i < i1; i++) {
|
1262
1275
|
const QC& qc = qcs[i];
|
@@ -1269,7 +1282,11 @@ void IndexIVFFastScan::search_implem_14(
|
|
1269
1282
|
}
|
1270
1283
|
}
|
1271
1284
|
pq4_pack_LUT_qbs_q_map(
|
1272
|
-
|
1285
|
+
qbs_for_list,
|
1286
|
+
M2,
|
1287
|
+
dis_tables.get(),
|
1288
|
+
lut_entries.data(),
|
1289
|
+
LUT.get());
|
1273
1290
|
|
1274
1291
|
// access the inverted list
|
1275
1292
|
|
@@ -1285,7 +1302,7 @@ void IndexIVFFastScan::search_implem_14(
|
|
1285
1302
|
handler->id_map = ids.get();
|
1286
1303
|
|
1287
1304
|
pq4_accumulate_loop_qbs(
|
1288
|
-
|
1305
|
+
qbs_for_list,
|
1289
1306
|
list_size,
|
1290
1307
|
M2,
|
1291
1308
|
codes.get(),
|
@@ -1340,34 +1357,30 @@ void IndexIVFFastScan::reconstruct_from_offset(
|
|
1340
1357
|
int64_t offset,
|
1341
1358
|
float* recons) const {
|
1342
1359
|
// unpack codes
|
1360
|
+
size_t coarse_size = coarse_code_size();
|
1361
|
+
std::vector<uint8_t> code(coarse_size + code_size, 0);
|
1362
|
+
encode_listno(list_no, code.data());
|
1343
1363
|
InvertedLists::ScopedCodes list_codes(invlists, list_no);
|
1344
|
-
|
1345
|
-
|
1364
|
+
BitstringWriter bsw(code.data() + coarse_size, code_size);
|
1365
|
+
|
1346
1366
|
for (size_t m = 0; m < M; m++) {
|
1347
1367
|
uint8_t c =
|
1348
1368
|
pq4_get_packed_element(list_codes.get(), bbs, M2, offset, m);
|
1349
1369
|
bsw.write(c, nbits);
|
1350
1370
|
}
|
1351
|
-
sa_decode(1, code.data(), recons);
|
1352
1371
|
|
1353
|
-
|
1354
|
-
if (by_residual) {
|
1355
|
-
std::vector<float> centroid(d);
|
1356
|
-
quantizer->reconstruct(list_no, centroid.data());
|
1357
|
-
for (int i = 0; i < d; ++i) {
|
1358
|
-
recons[i] += centroid[i];
|
1359
|
-
}
|
1360
|
-
}
|
1372
|
+
sa_decode(1, code.data(), recons);
|
1361
1373
|
}
|
1362
1374
|
|
1363
1375
|
void IndexIVFFastScan::reconstruct_orig_invlists() {
|
1364
1376
|
FAISS_THROW_IF_NOT(orig_invlists != nullptr);
|
1365
1377
|
FAISS_THROW_IF_NOT(orig_invlists->list_size(0) == 0);
|
1366
1378
|
|
1367
|
-
|
1379
|
+
#pragma omp parallel for if (nlist > 100)
|
1380
|
+
for (idx_t list_no = 0; list_no < nlist; list_no++) {
|
1368
1381
|
InvertedLists::ScopedCodes codes(invlists, list_no);
|
1369
1382
|
InvertedLists::ScopedIds ids(invlists, list_no);
|
1370
|
-
size_t list_size =
|
1383
|
+
size_t list_size = invlists->list_size(list_no);
|
1371
1384
|
std::vector<uint8_t> code(code_size, 0);
|
1372
1385
|
|
1373
1386
|
for (size_t offset = 0; offset < list_size; offset++) {
|
@@ -1387,6 +1400,30 @@ void IndexIVFFastScan::reconstruct_orig_invlists() {
|
|
1387
1400
|
}
|
1388
1401
|
}
|
1389
1402
|
|
1403
|
+
void IndexIVFFastScan::sa_decode(idx_t n, const uint8_t* codes, float* x)
|
1404
|
+
const {
|
1405
|
+
size_t coarse_size = coarse_code_size();
|
1406
|
+
|
1407
|
+
#pragma omp parallel if (n > 1)
|
1408
|
+
{
|
1409
|
+
std::vector<float> residual(d);
|
1410
|
+
|
1411
|
+
#pragma omp for
|
1412
|
+
for (idx_t i = 0; i < n; i++) {
|
1413
|
+
const uint8_t* code = codes + i * (code_size + coarse_size);
|
1414
|
+
int64_t list_no = decode_listno(code);
|
1415
|
+
float* xi = x + i * d;
|
1416
|
+
fine_quantizer->decode(code + coarse_size, xi, 1);
|
1417
|
+
if (by_residual) {
|
1418
|
+
quantizer->reconstruct(list_no, residual.data());
|
1419
|
+
for (size_t j = 0; j < d; j++) {
|
1420
|
+
xi[j] += residual[j];
|
1421
|
+
}
|
1422
|
+
}
|
1423
|
+
}
|
1424
|
+
}
|
1425
|
+
}
|
1426
|
+
|
1390
1427
|
IVFFastScanStats IVFFastScan_stats;
|
1391
1428
|
|
1392
1429
|
} // 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.
|
@@ -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,
|
@@ -225,6 +231,17 @@ struct IndexIVFFastScan : IndexIVF {
|
|
225
231
|
|
226
232
|
// reconstruct orig invlists (for debugging)
|
227
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;
|
228
245
|
};
|
229
246
|
|
230
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
|
|
@@ -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,28 +284,4 @@ void IndexIVFPQFastScan::compute_LUT(
|
|
286
284
|
}
|
287
285
|
}
|
288
286
|
|
289
|
-
void IndexIVFPQFastScan::sa_decode(idx_t n, const uint8_t* codes, float* x)
|
290
|
-
const {
|
291
|
-
size_t coarse_size = coarse_code_size();
|
292
|
-
|
293
|
-
#pragma omp parallel if (n > 1)
|
294
|
-
{
|
295
|
-
std::vector<float> residual(d);
|
296
|
-
|
297
|
-
#pragma omp for
|
298
|
-
for (idx_t i = 0; i < n; i++) {
|
299
|
-
const uint8_t* code = codes + i * (code_size + coarse_size);
|
300
|
-
int64_t list_no = decode_listno(code);
|
301
|
-
float* xi = x + i * d;
|
302
|
-
pq.decode(code + coarse_size, xi);
|
303
|
-
if (by_residual) {
|
304
|
-
quantizer->reconstruct(list_no, residual.data());
|
305
|
-
for (size_t j = 0; j < d; j++) {
|
306
|
-
xi[j] += residual[j];
|
307
|
-
}
|
308
|
-
}
|
309
|
-
}
|
310
|
-
}
|
311
|
-
}
|
312
|
-
|
313
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
|