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.
|
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
#pragma once
|
9
9
|
|
10
|
+
#include <faiss/impl/platform_macros.h>
|
10
11
|
#include <cstdint>
|
11
12
|
|
12
13
|
namespace faiss {
|
@@ -31,7 +32,11 @@ struct Uint8Reader {
|
|
31
32
|
if (N_ELEMENTS > CPOS + 3) {
|
32
33
|
const uint32_t code32 = *reinterpret_cast<const uint32_t*>(
|
33
34
|
codes + ELEMENT_TO_READ * 4);
|
35
|
+
#ifdef FAISS_BIG_ENDIAN
|
36
|
+
return (code32) >> 24;
|
37
|
+
#else
|
34
38
|
return (code32 & 0x000000FF);
|
39
|
+
#endif
|
35
40
|
} else {
|
36
41
|
return codes[CPOS];
|
37
42
|
}
|
@@ -40,7 +45,11 @@ struct Uint8Reader {
|
|
40
45
|
if (N_ELEMENTS > CPOS + 2) {
|
41
46
|
const uint32_t code32 = *reinterpret_cast<const uint32_t*>(
|
42
47
|
codes + ELEMENT_TO_READ * 4);
|
48
|
+
#ifdef FAISS_BIG_ENDIAN
|
49
|
+
return (code32 & 0x00FF0000) >> 16;
|
50
|
+
#else
|
43
51
|
return (code32 & 0x0000FF00) >> 8;
|
52
|
+
#endif
|
44
53
|
} else {
|
45
54
|
return codes[CPOS];
|
46
55
|
}
|
@@ -49,7 +58,11 @@ struct Uint8Reader {
|
|
49
58
|
if (N_ELEMENTS > CPOS + 1) {
|
50
59
|
const uint32_t code32 = *reinterpret_cast<const uint32_t*>(
|
51
60
|
codes + ELEMENT_TO_READ * 4);
|
61
|
+
#ifdef FAISS_BIG_ENDIAN
|
62
|
+
return (code32 & 0x0000FF00) >> 8;
|
63
|
+
#else
|
52
64
|
return (code32 & 0x00FF0000) >> 16;
|
65
|
+
#endif
|
53
66
|
} else {
|
54
67
|
return codes[CPOS];
|
55
68
|
}
|
@@ -58,7 +71,11 @@ struct Uint8Reader {
|
|
58
71
|
if (N_ELEMENTS > CPOS) {
|
59
72
|
const uint32_t code32 = *reinterpret_cast<const uint32_t*>(
|
60
73
|
codes + ELEMENT_TO_READ * 4);
|
74
|
+
#ifdef FAISS_BIG_ENDIAN
|
75
|
+
return (code32 & 0x000000FF);
|
76
|
+
#else
|
61
77
|
return (code32) >> 24;
|
78
|
+
#endif
|
62
79
|
} else {
|
63
80
|
return codes[CPOS];
|
64
81
|
}
|
@@ -87,40 +104,61 @@ struct Uint10Reader {
|
|
87
104
|
switch (SUB_ELEMENT) {
|
88
105
|
case 0: {
|
89
106
|
if (N_ELEMENTS > CPOS + 2) {
|
90
|
-
|
107
|
+
uint32_t code32 = *reinterpret_cast<const uint32_t*>(
|
91
108
|
codes + ELEMENT_TO_READ * 5);
|
109
|
+
#ifdef FAISS_BIG_ENDIAN
|
110
|
+
code32 = Swap4Bytes(code32);
|
111
|
+
#endif
|
92
112
|
return (code32 & 0b0000001111111111);
|
93
113
|
} else {
|
94
|
-
|
114
|
+
uint16_t code16 = *reinterpret_cast<const uint16_t*>(
|
95
115
|
codes + ELEMENT_TO_READ * 5 + 0);
|
116
|
+
#ifdef FAISS_BIG_ENDIAN
|
117
|
+
code16 = Swap2Bytes(code16);
|
118
|
+
#endif
|
96
119
|
return (code16 & 0b0000001111111111);
|
97
120
|
}
|
98
121
|
}
|
99
122
|
case 1: {
|
100
123
|
if (N_ELEMENTS > CPOS + 1) {
|
101
|
-
|
124
|
+
uint32_t code32 = *reinterpret_cast<const uint32_t*>(
|
102
125
|
codes + ELEMENT_TO_READ * 5);
|
126
|
+
#ifdef FAISS_BIG_ENDIAN
|
127
|
+
code32 = Swap4Bytes(code32);
|
128
|
+
#endif
|
103
129
|
return (code32 & 0b000011111111110000000000) >> 10;
|
104
130
|
} else {
|
105
|
-
|
131
|
+
uint16_t code16 = *reinterpret_cast<const uint16_t*>(
|
106
132
|
codes + ELEMENT_TO_READ * 5 + 1);
|
133
|
+
#ifdef FAISS_BIG_ENDIAN
|
134
|
+
code16 = Swap2Bytes(code16);
|
135
|
+
#endif
|
107
136
|
return (code16 & 0b0000111111111100) >> 2;
|
108
137
|
}
|
109
138
|
}
|
110
139
|
case 2: {
|
111
140
|
if (N_ELEMENTS > CPOS) {
|
112
|
-
|
141
|
+
uint32_t code32 = *reinterpret_cast<const uint32_t*>(
|
113
142
|
codes + ELEMENT_TO_READ * 5);
|
143
|
+
#ifdef FAISS_BIG_ENDIAN
|
144
|
+
code32 = Swap4Bytes(code32);
|
145
|
+
#endif
|
114
146
|
return (code32 & 0b00111111111100000000000000000000) >> 20;
|
115
147
|
} else {
|
116
|
-
|
148
|
+
uint16_t code16 = *reinterpret_cast<const uint16_t*>(
|
117
149
|
codes + ELEMENT_TO_READ * 5 + 2);
|
150
|
+
#ifdef FAISS_BIG_ENDIAN
|
151
|
+
code16 = Swap2Bytes(code16);
|
152
|
+
#endif
|
118
153
|
return (code16 & 0b0011111111110000) >> 4;
|
119
154
|
}
|
120
155
|
}
|
121
156
|
case 3: {
|
122
|
-
|
157
|
+
uint16_t code16 = *reinterpret_cast<const uint16_t*>(
|
123
158
|
codes + ELEMENT_TO_READ * 5 + 3);
|
159
|
+
#ifdef FAISS_BIG_ENDIAN
|
160
|
+
code16 = Swap2Bytes(code16);
|
161
|
+
#endif
|
124
162
|
return (code16 & 0b1111111111000000) >> 6;
|
125
163
|
}
|
126
164
|
}
|
@@ -147,45 +185,69 @@ struct Uint12Reader {
|
|
147
185
|
switch (SUB_ELEMENT) {
|
148
186
|
case 0: {
|
149
187
|
if (N_ELEMENTS > CPOS + 2) {
|
150
|
-
|
188
|
+
uint32_t code32 = *reinterpret_cast<const uint32_t*>(
|
151
189
|
codes + ELEMENT_TO_READ * 6);
|
190
|
+
#ifdef FAISS_BIG_ENDIAN
|
191
|
+
code32 = Swap4Bytes(code32);
|
192
|
+
#endif
|
152
193
|
return (code32 & 0b0000111111111111);
|
153
194
|
} else {
|
154
|
-
|
195
|
+
uint16_t code16 = *reinterpret_cast<const uint16_t*>(
|
155
196
|
codes + ELEMENT_TO_READ * 6 + 0);
|
197
|
+
#ifdef FAISS_BIG_ENDIAN
|
198
|
+
code16 = Swap2Bytes(code16);
|
199
|
+
#endif
|
156
200
|
return (code16 & 0b0000111111111111);
|
157
201
|
}
|
158
202
|
}
|
159
203
|
case 1: {
|
160
204
|
if (N_ELEMENTS > CPOS + 1) {
|
161
|
-
|
205
|
+
uint32_t code32 = *reinterpret_cast<const uint32_t*>(
|
162
206
|
codes + ELEMENT_TO_READ * 6);
|
207
|
+
#ifdef FAISS_BIG_ENDIAN
|
208
|
+
code32 = Swap4Bytes(code32);
|
209
|
+
#endif
|
163
210
|
return (code32 & 0b111111111111000000000000) >> 12;
|
164
211
|
} else {
|
165
|
-
|
212
|
+
uint16_t code16 = *reinterpret_cast<const uint16_t*>(
|
166
213
|
codes + ELEMENT_TO_READ * 6 + 1);
|
214
|
+
#ifdef FAISS_BIG_ENDIAN
|
215
|
+
code16 = Swap2Bytes(code16);
|
216
|
+
#endif
|
167
217
|
return (code16 & 0b1111111111110000) >> 4;
|
168
218
|
}
|
169
219
|
}
|
170
220
|
case 2: {
|
171
221
|
if (N_ELEMENTS > CPOS + 1) {
|
172
|
-
|
222
|
+
uint32_t code32 = *reinterpret_cast<const uint32_t*>(
|
173
223
|
codes + ELEMENT_TO_READ * 6 + 2);
|
224
|
+
#ifdef FAISS_BIG_ENDIAN
|
225
|
+
code32 = Swap4Bytes(code32);
|
226
|
+
#endif
|
174
227
|
return (code32 & 0b000011111111111100000000) >> 8;
|
175
228
|
} else {
|
176
|
-
|
229
|
+
uint16_t code16 = *reinterpret_cast<const uint16_t*>(
|
177
230
|
codes + ELEMENT_TO_READ * 6 + 3);
|
231
|
+
#ifdef FAISS_BIG_ENDIAN
|
232
|
+
code16 = Swap2Bytes(code16);
|
233
|
+
#endif
|
178
234
|
return (code16 & 0b0000111111111111);
|
179
235
|
}
|
180
236
|
}
|
181
237
|
case 3: {
|
182
238
|
if (N_ELEMENTS > CPOS) {
|
183
|
-
|
239
|
+
uint32_t code32 = *reinterpret_cast<const uint32_t*>(
|
184
240
|
codes + ELEMENT_TO_READ * 6 + 2);
|
241
|
+
#ifdef FAISS_BIG_ENDIAN
|
242
|
+
code32 = Swap4Bytes(code32);
|
243
|
+
#endif
|
185
244
|
return (code32 & 0b11111111111100000000000000000000) >> 20;
|
186
245
|
} else {
|
187
|
-
|
246
|
+
uint16_t code16 = *reinterpret_cast<const uint16_t*>(
|
188
247
|
codes + ELEMENT_TO_READ * 6 + 4);
|
248
|
+
#ifdef FAISS_BIG_ENDIAN
|
249
|
+
code16 = Swap2Bytes(code16);
|
250
|
+
#endif
|
189
251
|
return (code16 & 0b1111111111110000) >> 4;
|
190
252
|
}
|
191
253
|
}
|
@@ -208,23 +270,39 @@ struct Uint16Reader {
|
|
208
270
|
switch (SUB_ELEMENT) {
|
209
271
|
case 0: {
|
210
272
|
if (N_ELEMENTS > CPOS + 1) {
|
211
|
-
|
273
|
+
uint32_t code32 = *reinterpret_cast<const uint32_t*>(
|
212
274
|
codes + ELEMENT_TO_READ * 4);
|
275
|
+
#ifdef FAISS_BIG_ENDIAN
|
276
|
+
code32 = Swap4Bytes(code32);
|
277
|
+
#endif
|
213
278
|
return (code32 & 0x0000FFFF);
|
214
279
|
} else {
|
215
280
|
const uint16_t* const __restrict codesFp16 =
|
216
281
|
reinterpret_cast<const uint16_t*>(codes);
|
282
|
+
#ifdef FAISS_BIG_ENDIAN
|
283
|
+
uint16_t rt = codesFp16[CPOS];
|
284
|
+
rt = Swap2Bytes(rt);
|
285
|
+
return rt;
|
286
|
+
#endif
|
217
287
|
return codesFp16[CPOS];
|
218
288
|
}
|
219
289
|
}
|
220
290
|
case 1: {
|
221
291
|
if (N_ELEMENTS > CPOS) {
|
222
|
-
|
292
|
+
uint32_t code32 = *reinterpret_cast<const uint32_t*>(
|
223
293
|
codes + ELEMENT_TO_READ * 4);
|
294
|
+
#ifdef FAISS_BIG_ENDIAN
|
295
|
+
code32 = Swap4Bytes(code32);
|
296
|
+
#endif
|
224
297
|
return code32 >> 16;
|
225
298
|
} else {
|
226
299
|
const uint16_t* const __restrict codesFp16 =
|
227
300
|
reinterpret_cast<const uint16_t*>(codes);
|
301
|
+
#ifdef FAISS_BIG_ENDIAN
|
302
|
+
uint16_t rt = codesFp16[CPOS];
|
303
|
+
rt = Swap2Bytes(rt);
|
304
|
+
return rt;
|
305
|
+
#endif
|
228
306
|
return codesFp16[CPOS];
|
229
307
|
}
|
230
308
|
}
|
@@ -0,0 +1,192 @@
|
|
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
|
+
// -*- c++ -*-
|
9
|
+
|
10
|
+
#include <faiss/cppcontrib/factory_tools.h>
|
11
|
+
#include <map>
|
12
|
+
|
13
|
+
namespace faiss {
|
14
|
+
|
15
|
+
namespace {
|
16
|
+
|
17
|
+
const std::map<faiss::ScalarQuantizer::QuantizerType, std::string> sq_types = {
|
18
|
+
{faiss::ScalarQuantizer::QT_8bit, "SQ8"},
|
19
|
+
{faiss::ScalarQuantizer::QT_4bit, "SQ4"},
|
20
|
+
{faiss::ScalarQuantizer::QT_6bit, "SQ6"},
|
21
|
+
{faiss::ScalarQuantizer::QT_fp16, "SQfp16"},
|
22
|
+
{faiss::ScalarQuantizer::QT_bf16, "SQbf16"},
|
23
|
+
{faiss::ScalarQuantizer::QT_8bit_direct_signed, "SQ8_direct_signed"},
|
24
|
+
{faiss::ScalarQuantizer::QT_8bit_direct, "SQ8_direct"},
|
25
|
+
};
|
26
|
+
|
27
|
+
int get_hnsw_M(const faiss::IndexHNSW* index) {
|
28
|
+
if (index->hnsw.cum_nneighbor_per_level.size() > 1) {
|
29
|
+
return index->hnsw.cum_nneighbor_per_level[1] / 2;
|
30
|
+
}
|
31
|
+
// Avoid runtime error, just return 0.
|
32
|
+
return 0;
|
33
|
+
}
|
34
|
+
|
35
|
+
int get_hnsw_M(const faiss::IndexBinaryHNSW* index) {
|
36
|
+
if (index->hnsw.cum_nneighbor_per_level.size() > 1) {
|
37
|
+
return index->hnsw.cum_nneighbor_per_level[1] / 2;
|
38
|
+
}
|
39
|
+
// Avoid runtime error, just return 0.
|
40
|
+
return 0;
|
41
|
+
}
|
42
|
+
|
43
|
+
} // namespace
|
44
|
+
|
45
|
+
// Reference for reverse_index_factory:
|
46
|
+
// https://github.com/facebookresearch/faiss/blob/838612c9d7f2f619811434ec9209c020f44107cb/contrib/factory_tools.py#L81
|
47
|
+
std::string reverse_index_factory(const faiss::Index* index) {
|
48
|
+
std::string prefix;
|
49
|
+
if (dynamic_cast<const faiss::IndexFlat*>(index)) {
|
50
|
+
return "Flat";
|
51
|
+
} else if (
|
52
|
+
const faiss::IndexIVF* ivf_index =
|
53
|
+
dynamic_cast<const faiss::IndexIVF*>(index)) {
|
54
|
+
const faiss::Index* quantizer = ivf_index->quantizer;
|
55
|
+
|
56
|
+
if (dynamic_cast<const faiss::IndexFlat*>(quantizer)) {
|
57
|
+
prefix = "IVF" + std::to_string(ivf_index->nlist);
|
58
|
+
} else if (
|
59
|
+
const faiss::MultiIndexQuantizer* miq =
|
60
|
+
dynamic_cast<const faiss::MultiIndexQuantizer*>(
|
61
|
+
quantizer)) {
|
62
|
+
prefix = "IMI" + std::to_string(miq->pq.M) + "x" +
|
63
|
+
std::to_string(miq->pq.nbits);
|
64
|
+
} else if (
|
65
|
+
const faiss::IndexHNSW* hnsw_index =
|
66
|
+
dynamic_cast<const faiss::IndexHNSW*>(quantizer)) {
|
67
|
+
prefix = "IVF" + std::to_string(ivf_index->nlist) + "_HNSW" +
|
68
|
+
std::to_string(get_hnsw_M(hnsw_index));
|
69
|
+
} else {
|
70
|
+
prefix = "IVF" + std::to_string(ivf_index->nlist) + "(" +
|
71
|
+
reverse_index_factory(quantizer) + ")";
|
72
|
+
}
|
73
|
+
|
74
|
+
if (dynamic_cast<const faiss::IndexIVFFlat*>(ivf_index)) {
|
75
|
+
return prefix + ",Flat";
|
76
|
+
} else if (
|
77
|
+
auto sq_index =
|
78
|
+
dynamic_cast<const faiss::IndexIVFScalarQuantizer*>(
|
79
|
+
ivf_index)) {
|
80
|
+
return prefix + "," + sq_types.at(sq_index->sq.qtype);
|
81
|
+
} else if (
|
82
|
+
const faiss::IndexIVFPQ* ivfpq_index =
|
83
|
+
dynamic_cast<const faiss::IndexIVFPQ*>(ivf_index)) {
|
84
|
+
return prefix + ",PQ" + std::to_string(ivfpq_index->pq.M) + "x" +
|
85
|
+
std::to_string(ivfpq_index->pq.nbits);
|
86
|
+
} else if (
|
87
|
+
const faiss::IndexIVFPQFastScan* ivfpqfs_index =
|
88
|
+
dynamic_cast<const faiss::IndexIVFPQFastScan*>(
|
89
|
+
ivf_index)) {
|
90
|
+
return prefix + ",PQ" + std::to_string(ivfpqfs_index->pq.M) + "x" +
|
91
|
+
std::to_string(ivfpqfs_index->pq.nbits) + "fs";
|
92
|
+
}
|
93
|
+
} else if (
|
94
|
+
const faiss::IndexPreTransform* pretransform_index =
|
95
|
+
dynamic_cast<const faiss::IndexPreTransform*>(index)) {
|
96
|
+
if (pretransform_index->chain.size() != 1) {
|
97
|
+
// Avoid runtime error, just return empty string for logging.
|
98
|
+
return "";
|
99
|
+
}
|
100
|
+
const faiss::VectorTransform* vt = pretransform_index->chain.at(0);
|
101
|
+
if (const faiss::OPQMatrix* opq_matrix =
|
102
|
+
dynamic_cast<const faiss::OPQMatrix*>(vt)) {
|
103
|
+
prefix = "OPQ" + std::to_string(opq_matrix->M) + "_" +
|
104
|
+
std::to_string(opq_matrix->d_out);
|
105
|
+
} else if (
|
106
|
+
const faiss::ITQTransform* itq_transform =
|
107
|
+
dynamic_cast<const faiss::ITQTransform*>(vt)) {
|
108
|
+
prefix = "ITQ" + std::to_string(itq_transform->itq.d_out);
|
109
|
+
} else if (
|
110
|
+
const faiss::PCAMatrix* pca_matrix =
|
111
|
+
dynamic_cast<const faiss::PCAMatrix*>(vt)) {
|
112
|
+
assert(pca_matrix->eigen_power == 0);
|
113
|
+
prefix = "PCA" +
|
114
|
+
std::string(pca_matrix->random_rotation ? "R" : "") +
|
115
|
+
std::to_string(pca_matrix->d_out);
|
116
|
+
} else {
|
117
|
+
// Avoid runtime error, just return empty string for logging.
|
118
|
+
return "";
|
119
|
+
}
|
120
|
+
return prefix + "," + reverse_index_factory(pretransform_index->index);
|
121
|
+
} else if (
|
122
|
+
const faiss::IndexHNSW* hnsw_index =
|
123
|
+
dynamic_cast<const faiss::IndexHNSW*>(index)) {
|
124
|
+
return "HNSW" + std::to_string(get_hnsw_M(hnsw_index));
|
125
|
+
} else if (
|
126
|
+
const faiss::IndexRefine* refine_index =
|
127
|
+
dynamic_cast<const faiss::IndexRefine*>(index)) {
|
128
|
+
return reverse_index_factory(refine_index->base_index) + ",Refine(" +
|
129
|
+
reverse_index_factory(refine_index->refine_index) + ")";
|
130
|
+
} else if (
|
131
|
+
const faiss::IndexPQFastScan* pqfs_index =
|
132
|
+
dynamic_cast<const faiss::IndexPQFastScan*>(index)) {
|
133
|
+
return std::string("PQ") + std::to_string(pqfs_index->pq.M) + "x" +
|
134
|
+
std::to_string(pqfs_index->pq.nbits) + "fs";
|
135
|
+
} else if (
|
136
|
+
const faiss::IndexPQ* pq_index =
|
137
|
+
dynamic_cast<const faiss::IndexPQ*>(index)) {
|
138
|
+
return std::string("PQ") + std::to_string(pq_index->pq.M) + "x" +
|
139
|
+
std::to_string(pq_index->pq.nbits);
|
140
|
+
} else if (
|
141
|
+
const faiss::IndexLSH* lsh_index =
|
142
|
+
dynamic_cast<const faiss::IndexLSH*>(index)) {
|
143
|
+
std::string result = "LSH";
|
144
|
+
if (lsh_index->rotate_data) {
|
145
|
+
result += "r";
|
146
|
+
}
|
147
|
+
if (lsh_index->train_thresholds) {
|
148
|
+
result += "t";
|
149
|
+
}
|
150
|
+
return result;
|
151
|
+
} else if (
|
152
|
+
const faiss::IndexScalarQuantizer* sq_index =
|
153
|
+
dynamic_cast<const faiss::IndexScalarQuantizer*>(index)) {
|
154
|
+
return sq_types.at(sq_index->sq.qtype);
|
155
|
+
} else if (
|
156
|
+
const faiss::IndexIDMap* idmap =
|
157
|
+
dynamic_cast<const faiss::IndexIDMap*>(index)) {
|
158
|
+
return std::string("IDMap,") + reverse_index_factory(idmap->index);
|
159
|
+
}
|
160
|
+
// Avoid runtime error, just return empty string for logging.
|
161
|
+
return "";
|
162
|
+
}
|
163
|
+
|
164
|
+
std::string reverse_index_factory(const faiss::IndexBinary* index) {
|
165
|
+
std::string prefix;
|
166
|
+
if (dynamic_cast<const faiss::IndexBinaryFlat*>(index)) {
|
167
|
+
return "BFlat";
|
168
|
+
} else if (
|
169
|
+
const faiss::IndexBinaryIVF* ivf_index =
|
170
|
+
dynamic_cast<const faiss::IndexBinaryIVF*>(index)) {
|
171
|
+
const faiss::IndexBinary* quantizer = ivf_index->quantizer;
|
172
|
+
|
173
|
+
if (dynamic_cast<const faiss::IndexBinaryFlat*>(quantizer)) {
|
174
|
+
return "BIVF" + std::to_string(ivf_index->nlist);
|
175
|
+
} else if (
|
176
|
+
const faiss::IndexBinaryHNSW* hnsw_index =
|
177
|
+
dynamic_cast<const faiss::IndexBinaryHNSW*>(
|
178
|
+
quantizer)) {
|
179
|
+
return "BIVF" + std::to_string(ivf_index->nlist) + "_HNSW" +
|
180
|
+
std::to_string(get_hnsw_M(hnsw_index));
|
181
|
+
}
|
182
|
+
// Add further cases for BinaryIVF here.
|
183
|
+
} else if (
|
184
|
+
const faiss::IndexBinaryHNSW* hnsw_index =
|
185
|
+
dynamic_cast<const faiss::IndexBinaryHNSW*>(index)) {
|
186
|
+
return "BHNSW" + std::to_string(get_hnsw_M(hnsw_index));
|
187
|
+
}
|
188
|
+
// Avoid runtime error, just return empty string for logging.
|
189
|
+
return "";
|
190
|
+
}
|
191
|
+
|
192
|
+
} // namespace faiss
|
@@ -0,0 +1,29 @@
|
|
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
|
+
// -*- c++ -*-
|
9
|
+
|
10
|
+
#pragma once
|
11
|
+
|
12
|
+
#include <faiss/IndexBinaryFlat.h>
|
13
|
+
#include <faiss/IndexBinaryHNSW.h>
|
14
|
+
#include <faiss/IndexBinaryIVF.h>
|
15
|
+
#include <faiss/IndexHNSW.h>
|
16
|
+
#include <faiss/IndexIDMap.h>
|
17
|
+
#include <faiss/IndexIVFFlat.h>
|
18
|
+
#include <faiss/IndexIVFPQFastScan.h>
|
19
|
+
#include <faiss/IndexLSH.h>
|
20
|
+
#include <faiss/IndexPQFastScan.h>
|
21
|
+
#include <faiss/IndexPreTransform.h>
|
22
|
+
#include <faiss/IndexRefine.h>
|
23
|
+
|
24
|
+
namespace faiss {
|
25
|
+
|
26
|
+
std::string reverse_index_factory(const faiss::Index* index);
|
27
|
+
std::string reverse_index_factory(const faiss::IndexBinary* index);
|
28
|
+
|
29
|
+
} // 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.
|
@@ -12,10 +12,19 @@
|
|
12
12
|
#include <cstdint>
|
13
13
|
|
14
14
|
#include <faiss/cppcontrib/detail/CoarseBitType.h>
|
15
|
+
#include <faiss/impl/platform_macros.h>
|
15
16
|
|
16
17
|
namespace faiss {
|
17
18
|
namespace cppcontrib {
|
18
19
|
|
20
|
+
bool isBigEndian() {
|
21
|
+
#ifdef FAISS_BIG_ENDIAN
|
22
|
+
return true;
|
23
|
+
#else
|
24
|
+
return false;
|
25
|
+
#endif
|
26
|
+
}
|
27
|
+
|
19
28
|
////////////////////////////////////////////////////////////////////////////////////
|
20
29
|
/// Index2LevelDecoder
|
21
30
|
////////////////////////////////////////////////////////////////////////////////////
|
@@ -72,9 +81,14 @@ struct Index2LevelDecoder {
|
|
72
81
|
const intptr_t coarseCentroidOffset = i % COARSE_SIZE;
|
73
82
|
const intptr_t fineCentroidIdx = i / FINE_SIZE;
|
74
83
|
const intptr_t fineCentroidOffset = i % FINE_SIZE;
|
75
|
-
|
76
|
-
|
77
|
-
|
84
|
+
intptr_t coarseCode, fineCode;
|
85
|
+
if (isBigEndian() && sizeof(coarse_storage_type) == 2) {
|
86
|
+
coarseCode = Swap2Bytes(coarse[coarseCentroidIdx]);
|
87
|
+
fineCode = Swap2Bytes(fine[fineCentroidIdx]);
|
88
|
+
} else {
|
89
|
+
coarseCode = coarse[coarseCentroidIdx];
|
90
|
+
fineCode = fine[fineCentroidIdx];
|
91
|
+
}
|
78
92
|
|
79
93
|
const float* const __restrict coarsePtr = pqCoarseCentroids +
|
80
94
|
(coarseCentroidIdx * COARSE_TABLE_BYTES + coarseCode) *
|
@@ -112,9 +126,14 @@ struct Index2LevelDecoder {
|
|
112
126
|
const intptr_t fineCentroidIdx = i / FINE_SIZE;
|
113
127
|
const intptr_t fineCentroidOffset = i % FINE_SIZE;
|
114
128
|
|
115
|
-
|
116
|
-
|
117
|
-
|
129
|
+
intptr_t coarseCode, fineCode;
|
130
|
+
if (isBigEndian() && sizeof(coarse_storage_type) == 2) {
|
131
|
+
coarseCode = Swap2Bytes(coarse[coarseCentroidIdx]);
|
132
|
+
fineCode = Swap2Bytes(fine[fineCentroidIdx]);
|
133
|
+
} else {
|
134
|
+
coarseCode = coarse[coarseCentroidIdx];
|
135
|
+
fineCode = fine[fineCentroidIdx];
|
136
|
+
}
|
118
137
|
const float* const __restrict coarsePtr = pqCoarseCentroids +
|
119
138
|
(coarseCentroidIdx * COARSE_TABLE_BYTES + coarseCode) *
|
120
139
|
COARSE_SIZE +
|
@@ -162,11 +181,18 @@ struct Index2LevelDecoder {
|
|
162
181
|
const intptr_t coarseCentroidOffset = i % COARSE_SIZE;
|
163
182
|
const intptr_t fineCentroidIdx = i / FINE_SIZE;
|
164
183
|
const intptr_t fineCentroidOffset = i % FINE_SIZE;
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
184
|
+
intptr_t coarseCode0, coarseCode1, fineCode0, fineCode1;
|
185
|
+
if (isBigEndian() && sizeof(coarse_storage_type) == 2) {
|
186
|
+
coarseCode0 = Swap2Bytes(coarse0[coarseCentroidIdx]);
|
187
|
+
fineCode0 = Swap2Bytes(fine0[fineCentroidIdx]);
|
188
|
+
coarseCode1 = Swap2Bytes(coarse1[coarseCentroidIdx]);
|
189
|
+
fineCode1 = Swap2Bytes(fine1[fineCentroidIdx]);
|
190
|
+
} else {
|
191
|
+
coarseCode0 = coarse0[coarseCentroidIdx];
|
192
|
+
fineCode0 = fine0[fineCentroidIdx];
|
193
|
+
coarseCode1 = coarse1[coarseCentroidIdx];
|
194
|
+
fineCode1 = fine1[fineCentroidIdx];
|
195
|
+
}
|
170
196
|
|
171
197
|
const float* const __restrict coarsePtr0 = pqCoarseCentroids0 +
|
172
198
|
(coarseCentroidIdx * COARSE_TABLE_BYTES + coarseCode0) *
|
@@ -222,11 +248,18 @@ struct Index2LevelDecoder {
|
|
222
248
|
const intptr_t coarseCentroidOffset = i % COARSE_SIZE;
|
223
249
|
const intptr_t fineCentroidIdx = i / FINE_SIZE;
|
224
250
|
const intptr_t fineCentroidOffset = i % FINE_SIZE;
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
251
|
+
intptr_t coarseCode0, coarseCode1, fineCode0, fineCode1;
|
252
|
+
if (isBigEndian() && sizeof(coarse_storage_type) == 2) {
|
253
|
+
coarseCode0 = Swap2Bytes(coarse0[coarseCentroidIdx]);
|
254
|
+
fineCode0 = Swap2Bytes(fine0[fineCentroidIdx]);
|
255
|
+
coarseCode1 = Swap2Bytes(coarse1[coarseCentroidIdx]);
|
256
|
+
fineCode1 = Swap2Bytes(fine1[fineCentroidIdx]);
|
257
|
+
} else {
|
258
|
+
coarseCode0 = coarse0[coarseCentroidIdx];
|
259
|
+
fineCode0 = fine0[fineCentroidIdx];
|
260
|
+
coarseCode1 = coarse1[coarseCentroidIdx];
|
261
|
+
fineCode1 = fine1[fineCentroidIdx];
|
262
|
+
}
|
230
263
|
|
231
264
|
const float* const __restrict coarsePtr0 = pqCoarseCentroids +
|
232
265
|
(coarseCentroidIdx * COARSE_TABLE_BYTES + coarseCode0) *
|
@@ -292,13 +325,23 @@ struct Index2LevelDecoder {
|
|
292
325
|
const intptr_t coarseCentroidOffset = i % COARSE_SIZE;
|
293
326
|
const intptr_t fineCentroidIdx = i / FINE_SIZE;
|
294
327
|
const intptr_t fineCentroidOffset = i % FINE_SIZE;
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
328
|
+
intptr_t coarseCode0, coarseCode1, fineCode0, fineCode1;
|
329
|
+
intptr_t coarseCode2, fineCode2;
|
330
|
+
if (isBigEndian() && sizeof(coarse_storage_type) == 2) {
|
331
|
+
coarseCode0 = Swap2Bytes(coarse0[coarseCentroidIdx]);
|
332
|
+
fineCode0 = Swap2Bytes(fine0[fineCentroidIdx]);
|
333
|
+
coarseCode1 = Swap2Bytes(coarse1[coarseCentroidIdx]);
|
334
|
+
fineCode1 = Swap2Bytes(fine1[fineCentroidIdx]);
|
335
|
+
coarseCode2 = Swap2Bytes(coarse2[coarseCentroidIdx]);
|
336
|
+
fineCode2 = Swap2Bytes(fine2[fineCentroidIdx]);
|
337
|
+
} else {
|
338
|
+
coarseCode0 = coarse0[coarseCentroidIdx];
|
339
|
+
fineCode0 = fine0[fineCentroidIdx];
|
340
|
+
coarseCode1 = coarse1[coarseCentroidIdx];
|
341
|
+
fineCode1 = fine1[fineCentroidIdx];
|
342
|
+
coarseCode2 = coarse2[coarseCentroidIdx];
|
343
|
+
fineCode2 = fine2[fineCentroidIdx];
|
344
|
+
}
|
302
345
|
|
303
346
|
const float* const __restrict coarsePtr0 = pqCoarseCentroids0 +
|
304
347
|
(coarseCentroidIdx * COARSE_TABLE_BYTES + coarseCode0) *
|
@@ -369,13 +412,23 @@ struct Index2LevelDecoder {
|
|
369
412
|
const intptr_t coarseCentroidOffset = i % COARSE_SIZE;
|
370
413
|
const intptr_t fineCentroidIdx = i / FINE_SIZE;
|
371
414
|
const intptr_t fineCentroidOffset = i % FINE_SIZE;
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
415
|
+
intptr_t coarseCode0, fineCode0, coarseCode1, fineCode1;
|
416
|
+
intptr_t coarseCode2, fineCode2;
|
417
|
+
if (isBigEndian() && sizeof(coarse_storage_type) == 2) {
|
418
|
+
coarseCode0 = Swap2Bytes(coarse0[coarseCentroidIdx]);
|
419
|
+
fineCode0 = Swap2Bytes(fine0[fineCentroidIdx]);
|
420
|
+
coarseCode1 = Swap2Bytes(coarse1[coarseCentroidIdx]);
|
421
|
+
fineCode1 = Swap2Bytes(fine1[fineCentroidIdx]);
|
422
|
+
coarseCode2 = Swap2Bytes(coarse2[coarseCentroidIdx]);
|
423
|
+
fineCode2 = Swap2Bytes(fine2[fineCentroidIdx]);
|
424
|
+
} else {
|
425
|
+
coarseCode0 = coarse0[coarseCentroidIdx];
|
426
|
+
fineCode0 = fine0[fineCentroidIdx];
|
427
|
+
coarseCode1 = coarse1[coarseCentroidIdx];
|
428
|
+
fineCode1 = fine1[fineCentroidIdx];
|
429
|
+
coarseCode2 = coarse2[coarseCentroidIdx];
|
430
|
+
fineCode2 = fine2[fineCentroidIdx];
|
431
|
+
}
|
379
432
|
|
380
433
|
const float* const __restrict coarsePtr0 = pqCoarseCentroids +
|
381
434
|
(coarseCentroidIdx * COARSE_TABLE_BYTES + coarseCode0) *
|