faiss 0.6.3 → 0.6.5
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/ext/faiss/extconf.rb +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +175 -0
- data/vendor/faiss/faiss/Clustering.cpp +150 -60
- data/vendor/faiss/faiss/Clustering.h +37 -0
- data/vendor/faiss/faiss/IVFlib.cpp +99 -0
- data/vendor/faiss/faiss/IVFlib.h +15 -0
- data/vendor/faiss/faiss/Index.cpp +44 -0
- data/vendor/faiss/faiss/Index.h +18 -13
- data/vendor/faiss/faiss/IndexBinary.cpp +8 -0
- data/vendor/faiss/faiss/IndexBinary.h +8 -0
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +23 -2
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +94 -144
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +18 -5
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +40 -14
- data/vendor/faiss/faiss/IndexBinaryIVF.h +8 -1
- data/vendor/faiss/faiss/IndexFastScan.cpp +33 -17
- data/vendor/faiss/faiss/IndexFastScan.h +6 -3
- data/vendor/faiss/faiss/IndexFlat.cpp +64 -4
- data/vendor/faiss/faiss/IndexFlat.h +33 -2
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +6 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +755 -99
- data/vendor/faiss/faiss/IndexHNSW.h +69 -7
- data/vendor/faiss/faiss/IndexIDMap.cpp +43 -6
- data/vendor/faiss/faiss/IndexIDMap.h +7 -0
- data/vendor/faiss/faiss/IndexIVF.cpp +297 -32
- data/vendor/faiss/faiss/IndexIVF.h +53 -1
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +46 -14
- data/vendor/faiss/faiss/IndexIVFFastScan.h +4 -2
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +33 -0
- data/vendor/faiss/faiss/IndexIVFFlat.h +16 -0
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +9 -1
- data/vendor/faiss/faiss/IndexIVFPQ.h +11 -0
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +1 -0
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +3 -20
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +50 -14
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +5 -2
- data/vendor/faiss/faiss/IndexIVFSQFastScan.cpp +855 -0
- data/vendor/faiss/faiss/IndexIVFSQFastScan.h +145 -0
- data/vendor/faiss/faiss/IndexNNDescent.cpp +0 -3
- data/vendor/faiss/faiss/IndexPiPNN.cpp +201 -0
- data/vendor/faiss/faiss/IndexPiPNN.h +83 -0
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +6 -3
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +10 -4
- data/vendor/faiss/faiss/IndexReplicas.cpp +20 -0
- data/vendor/faiss/faiss/IndexReplicas.h +9 -0
- data/vendor/faiss/faiss/IndexSQFastScan.cpp +648 -0
- data/vendor/faiss/faiss/IndexSQFastScan.h +129 -0
- data/vendor/faiss/faiss/IndexShards.cpp +13 -3
- data/vendor/faiss/faiss/IndexShards.h +5 -0
- data/vendor/faiss/faiss/IndexShardsIVF.cpp +4 -3
- data/vendor/faiss/faiss/SuperKMeans.cpp +87 -22
- data/vendor/faiss/faiss/SuperKMeans.h +12 -6
- data/vendor/faiss/faiss/VectorTransform.cpp +40 -1
- data/vendor/faiss/faiss/VectorTransform.h +3 -0
- data/vendor/faiss/faiss/clone_index.cpp +27 -0
- data/vendor/faiss/faiss/gpu/Dataset.h +112 -0
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +16 -13
- data/vendor/faiss/faiss/gpu/GpuCloner.h +4 -0
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +4 -5
- data/vendor/faiss/faiss/gpu/GpuDistance.h +2 -5
- data/vendor/faiss/faiss/gpu/GpuIndex.h +8 -18
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryCagra.h +26 -13
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +109 -63
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +11 -0
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +6 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuDatasetHeader.cpp +18 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +215 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +98 -0
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +11 -0
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +11 -0
- data/vendor/faiss/faiss/gpu_metal/MetalDistance.h +92 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +4 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndexBinaryFlat.h +69 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFPQ.h +38 -0
- data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +106 -0
- data/vendor/faiss/faiss/gpu_metal/MetalPythonBridge.h +10 -0
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +2 -0
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +1 -6
- data/vendor/faiss/faiss/impl/ClusteringHelpers.cpp +134 -45
- data/vendor/faiss/faiss/impl/ClusteringHelpers.h +36 -0
- data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +287 -134
- data/vendor/faiss/faiss/impl/DistanceComputer.cpp +63 -0
- data/vendor/faiss/faiss/impl/DistanceComputer.h +3 -29
- data/vendor/faiss/faiss/impl/HNSW.cpp +465 -125
- data/vendor/faiss/faiss/impl/HNSW.h +118 -7
- data/vendor/faiss/faiss/impl/IDSelector.h +44 -0
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +6 -19
- data/vendor/faiss/faiss/impl/NNDescent.cpp +12 -4
- data/vendor/faiss/faiss/impl/NSG.cpp +3 -2
- data/vendor/faiss/faiss/impl/Panorama.h +14 -4
- data/vendor/faiss/faiss/impl/PiPNN.cpp +822 -0
- data/vendor/faiss/faiss/impl/PiPNN.h +122 -0
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +58 -15
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +1 -1
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +1 -1
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +150 -60
- data/vendor/faiss/faiss/impl/RaBitQuantizer.h +62 -4
- data/vendor/faiss/faiss/impl/RaBitQuantizerMultiBit.cpp +2 -2
- data/vendor/faiss/faiss/impl/ResultHandler.h +9 -3
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +61 -30
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +7 -16
- data/vendor/faiss/faiss/impl/approx_topk/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/approx_topk/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHash_impl.h +5 -2
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryIVF_impl.h +89 -13
- data/vendor/faiss/faiss/impl/binary_hamming/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/rvv.cpp +0 -4
- data/vendor/faiss/faiss/impl/expanded_scanners.h +93 -1
- data/vendor/faiss/faiss/impl/fast_scan/FastScanDistancePostProcessing.h +4 -0
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops.h +61 -64
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops_512.h +13 -14
- data/vendor/faiss/faiss/impl/fast_scan/decompose_qbs.h +18 -129
- data/vendor/faiss/faiss/impl/fast_scan/dispatching.h +25 -19
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.cpp +5 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +0 -88
- data/vendor/faiss/faiss/impl/fast_scan/impl-riscv.cpp +0 -4
- data/vendor/faiss/faiss/impl/fast_scan/kernels_neon.h +155 -0
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd256.h +22 -1
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd512.h +3 -2
- data/vendor/faiss/faiss/impl/fast_scan/simd_result_handlers.h +41 -23
- data/vendor/faiss/faiss/impl/hnsw/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/hnsw/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/index_read.cpp +302 -29
- data/vendor/faiss/faiss/impl/index_write.cpp +126 -26
- data/vendor/faiss/faiss/impl/pipnn/HashPrune.cpp +159 -0
- data/vendor/faiss/faiss/impl/pipnn/HashPrune.h +69 -0
- data/vendor/faiss/faiss/impl/pipnn/Partition.cpp +587 -0
- data/vendor/faiss/faiss/impl/pipnn/Partition.h +93 -0
- data/vendor/faiss/faiss/impl/pipnn/kernels.cpp +326 -0
- data/vendor/faiss/faiss/impl/pipnn/kernels.h +92 -0
- data/vendor/faiss/faiss/impl/platform_macros.h +45 -0
- data/vendor/faiss/faiss/impl/polysemous_training/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +152 -43
- data/vendor/faiss/faiss/impl/pq_code_distance/PQDistanceComputer_impl.h +6 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx2.h +4 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx512.h +4 -1
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.cpp +23 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.h +6 -6
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-inl.h +131 -6
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-sve.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_rvv_kernel.h +89 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_scan_impl.h +21 -10
- data/vendor/faiss/faiss/impl/pq_code_distance/rvv.cpp +45 -18
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +2 -1
- data/vendor/faiss/faiss/impl/result_handler/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/result_handler/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer-avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer-avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer.cpp +6 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +7 -3
- data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +28 -52
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +59 -11
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +232 -79
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-impl.h +482 -103
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-spr.cpp +2 -149
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +3 -698
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +101 -72
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +203 -99
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-rvv.cpp +3185 -144
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq8_coefficients.h +48 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq8_rvv_kernel.h +546 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.cpp +2 -2
- data/vendor/faiss/faiss/impl/simd_dispatch.h +47 -22
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx2.h +14 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_dispatch.h +7 -8
- data/vendor/faiss/faiss/impl/sq_fastscan_utils.h +232 -0
- data/vendor/faiss/faiss/index_factory.cpp +84 -1
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +10 -5
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +10 -4
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +16 -4
- data/vendor/faiss/faiss/svs/IndexSVSVamana.h +11 -3
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.cpp +4 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.h +2 -1
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.cpp +9 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.h +2 -1
- data/vendor/faiss/faiss/utils/AlignedTable.h +6 -1
- data/vendor/faiss/faiss/utils/Heap.cpp +4 -3
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +16 -5
- data/vendor/faiss/faiss/utils/bf16.h +36 -0
- data/vendor/faiss/faiss/utils/distances.cpp +246 -28
- data/vendor/faiss/faiss/utils/distances.h +34 -0
- data/vendor/faiss/faiss/utils/distances_dispatch.h +36 -28
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +2 -5
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +1 -15
- data/vendor/faiss/faiss/utils/distances_fused/rvv.cpp +25 -0
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +0 -4
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_kernel-inl.h +2 -1
- data/vendor/faiss/faiss/utils/distances_simd.cpp +9 -0
- data/vendor/faiss/faiss/utils/fp16-fp16c.h +4 -0
- data/vendor/faiss/faiss/utils/fp16-inl.h +26 -52
- data/vendor/faiss/faiss/utils/hamming.cpp +15 -9
- data/vendor/faiss/faiss/utils/hamming.h +10 -1
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +14 -3
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512_vpopcnt.cpp +20 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512.h +34 -6
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512_vpopcnt.h +217 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-neon.h +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_impl.h +143 -1
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_rvv.cpp +0 -4
- data/vendor/faiss/faiss/utils/pq_code_distance.h +8 -4
- data/vendor/faiss/faiss/utils/prefetch.h +1 -26
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +26 -27
- data/vendor/faiss/faiss/utils/quantize_lut.h +11 -0
- data/vendor/faiss/faiss/utils/rabitq_simd.h +51 -16
- data/vendor/faiss/faiss/utils/simd_impl/distances_aarch64.cpp +9 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +231 -35
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +64 -5
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +64 -5
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv.cpp +428 -108
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv_kernel.h +68 -0
- data/vendor/faiss/faiss/utils/simd_impl/exhaustive_L2sqr_blas_cmax.h +93 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels.h +76 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_avx2.cpp +52 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_avx512.cpp +52 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_neon.cpp +48 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum-avx2.h +44 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum-avx512.h +43 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum.h +38 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp +54 -15
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +89 -55
- data/vendor/faiss/faiss/utils/simd_impl/{rabitq_avx512_spr.cpp → rabitq_avx512_vpopcnt.cpp} +70 -36
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_neon.cpp +297 -10
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_rvv.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_dispatch.h +2 -7
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels.h +6 -1
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx512.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_sve.cpp +30 -0
- data/vendor/faiss/faiss/utils/simd_levels.cpp +191 -70
- data/vendor/faiss/faiss/utils/simd_levels.h +100 -16
- data/vendor/faiss/faiss/utils/transpose/transpose-avx2-inl.h +0 -4
- data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +0 -4
- data/vendor/faiss/faiss/utils/utils.cpp +80 -0
- data/vendor/faiss/faiss/utils/utils.h +24 -0
- metadata +38 -5
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512_spr.cpp +0 -15
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512_spr.h +0 -171
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
#include <faiss/MetricType.h>
|
|
14
14
|
#include <faiss/impl/DistanceComputer.h>
|
|
15
15
|
#include <faiss/impl/Quantizer.h>
|
|
16
|
+
#include <faiss/impl/RaBitQUtils.h>
|
|
17
|
+
#include <faiss/impl/platform_macros.h>
|
|
16
18
|
|
|
17
19
|
namespace faiss {
|
|
18
20
|
|
|
@@ -20,6 +22,33 @@ struct IDSelector;
|
|
|
20
22
|
template <typename T, typename TI>
|
|
21
23
|
struct ResultHandlerUnordered;
|
|
22
24
|
|
|
25
|
+
/** Statistics for staged RaBitQ distance evaluation.
|
|
26
|
+
*
|
|
27
|
+
* These counters belong to the quantizer rather than to a particular ANN
|
|
28
|
+
* graph. They are currently populated by HNSW's staged search path.
|
|
29
|
+
*/
|
|
30
|
+
struct RaBitQStats {
|
|
31
|
+
uint64_t n_1bit = 0;
|
|
32
|
+
uint64_t n_refine = 0;
|
|
33
|
+
|
|
34
|
+
void reset() {
|
|
35
|
+
n_1bit = n_refine = 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
void add(const RaBitQStats& other) {
|
|
39
|
+
n_1bit += other.n_1bit;
|
|
40
|
+
n_refine += other.n_refine;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
void add_atomic(const RaBitQStats& other);
|
|
44
|
+
|
|
45
|
+
double refine_ratio() const {
|
|
46
|
+
return n_1bit ? double(n_refine) / double(n_1bit) : 0.0;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
FAISS_API extern RaBitQStats rabitq_stats;
|
|
51
|
+
|
|
23
52
|
// the reference implementation of the https://arxiv.org/pdf/2405.12497
|
|
24
53
|
// Jianyang Gao, Cheng Long, "RaBitQ: Quantizing High-Dimensional Vectors
|
|
25
54
|
// with a Theoretical Error Bound for Approximate Nearest Neighbor Search".
|
|
@@ -122,17 +151,46 @@ struct RaBitQDistanceComputer : FlatCodesDistanceComputer {
|
|
|
122
151
|
// Used with f_error to compute error bounds for two-stage filtering
|
|
123
152
|
float g_error = 0.0f;
|
|
124
153
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
154
|
+
/// Per-distance-computer counters, aggregated by the owning index.
|
|
155
|
+
RaBitQStats stats;
|
|
156
|
+
|
|
157
|
+
float symmetric_dis(idx_t i, idx_t j) override;
|
|
129
158
|
|
|
130
159
|
// Compute 1-bit distance estimate (fast)
|
|
131
160
|
virtual float distance_to_code_1bit(const uint8_t* code) = 0;
|
|
132
161
|
|
|
162
|
+
/// Compute four one-bit estimates in input order. Caller must call
|
|
163
|
+
/// set_query() first. Each pointer addresses one complete encoded row; rows
|
|
164
|
+
/// need not be contiguous or distinct. The output holds four floats.
|
|
165
|
+
/// Does not refine candidates, update thresholds, or increment stats. The
|
|
166
|
+
/// default calls the single estimate four times.
|
|
167
|
+
virtual void distance_to_code_1bit_batch_4(
|
|
168
|
+
const uint8_t* const* codes_in,
|
|
169
|
+
float* distances) {
|
|
170
|
+
for (size_t i = 0; i < 4; ++i) {
|
|
171
|
+
distances[i] = distance_to_code_1bit(codes_in[i]);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
133
175
|
// Compute full multi-bit distance (accurate)
|
|
134
176
|
virtual float distance_to_code_full(const uint8_t* code) = 0;
|
|
135
177
|
|
|
178
|
+
/// Apply the RaBitQ error bound without exposing the packed code layout to
|
|
179
|
+
/// ANN consumers. Precondition: nb_bits >= 2.
|
|
180
|
+
#ifndef SWIG
|
|
181
|
+
FAISS_ALWAYS_INLINE bool should_refine(
|
|
182
|
+
const uint8_t* code,
|
|
183
|
+
float estimate,
|
|
184
|
+
float threshold,
|
|
185
|
+
bool is_similarity) const {
|
|
186
|
+
const auto* factors =
|
|
187
|
+
reinterpret_cast<const rabitq_utils::SignBitFactorsWithError*>(
|
|
188
|
+
code + (d + 7) / 8);
|
|
189
|
+
return rabitq_utils::should_refine_candidate(
|
|
190
|
+
estimate, factors->f_error, g_error, threshold, is_similarity);
|
|
191
|
+
}
|
|
192
|
+
#endif
|
|
193
|
+
|
|
136
194
|
virtual void set_centroid(const float* centroid_in) {
|
|
137
195
|
centroid = centroid_in;
|
|
138
196
|
}
|
|
@@ -302,9 +302,9 @@ void quantize_ex_bits(
|
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
// Step 6: Handle negative dimensions (flip bits)
|
|
305
|
-
// For negative residuals, flip all bits: code' = ~code & max_code
|
|
305
|
+
// For negative or zero residuals, flip all bits: code' = ~code & max_code
|
|
306
306
|
for (size_t i = 0; i < d; i++) {
|
|
307
|
-
if (residual[i]
|
|
307
|
+
if (residual[i] <= 0) {
|
|
308
308
|
tmp_code[i] = (~tmp_code[i]) & max_code;
|
|
309
309
|
}
|
|
310
310
|
}
|
|
@@ -123,14 +123,20 @@ struct SingleQueryBlockResultHandler : BlockResultHandler<C, use_sel> {
|
|
|
123
123
|
using ResultHandlerT<C>::threshold;
|
|
124
124
|
|
|
125
125
|
explicit SingleResultHandler(SingleQueryBlockResultHandler& hr)
|
|
126
|
-
: the_handler(hr.the_handler) {
|
|
126
|
+
: the_handler(hr.the_handler) {
|
|
127
|
+
threshold = the_handler.threshold;
|
|
128
|
+
}
|
|
127
129
|
|
|
128
130
|
/// begin results for query # i
|
|
129
|
-
void begin(const size_t /* qid */) {
|
|
131
|
+
void begin(const size_t /* qid */) {
|
|
132
|
+
threshold = the_handler.threshold;
|
|
133
|
+
}
|
|
130
134
|
|
|
131
135
|
/// add one result for query i
|
|
132
136
|
bool add_result(T dis, TI idx) final {
|
|
133
|
-
|
|
137
|
+
bool updated = the_handler.add_result(dis, idx);
|
|
138
|
+
threshold = the_handler.threshold;
|
|
139
|
+
return updated;
|
|
134
140
|
}
|
|
135
141
|
|
|
136
142
|
/// series of results for query i is done
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
// -*- c++ -*-
|
|
9
9
|
|
|
10
|
+
#include <cmath>
|
|
10
11
|
#include <cstring>
|
|
11
12
|
#include <memory>
|
|
12
13
|
|
|
@@ -425,18 +426,62 @@ const LloydMaxTable kLloydMaxTables[] = {
|
|
|
425
426
|
{kLloydMaxCentroids8, kLloydMaxBoundaries8}, // 8
|
|
426
427
|
};
|
|
427
428
|
|
|
428
|
-
|
|
429
|
+
// The tables are Lloyd-Max optimal for N(0, 1) input. Callers whose input has
|
|
430
|
+
// a different standard deviation pass it as `scale` to stretch the table.
|
|
431
|
+
void populate_lloyd_max_trained(
|
|
432
|
+
size_t mse_bits,
|
|
433
|
+
std::vector<float>& trained,
|
|
434
|
+
float scale = 1.0f) {
|
|
429
435
|
FAISS_THROW_IF_NOT(mse_bits >= 1 && mse_bits <= 8);
|
|
430
436
|
FAISS_THROW_IF_NOT(kLloydMaxTables[mse_bits].centroids);
|
|
431
437
|
size_t k = size_t(1) << mse_bits;
|
|
432
438
|
const auto& t = kLloydMaxTables[mse_bits];
|
|
433
439
|
trained.resize(k + (k - 1));
|
|
434
|
-
|
|
435
|
-
|
|
440
|
+
for (size_t i = 0; i < k; i++) {
|
|
441
|
+
trained[i] = t.centroids[i] * scale;
|
|
442
|
+
}
|
|
443
|
+
for (size_t i = 0; i + 1 < k; i++) {
|
|
444
|
+
trained[k + i] = t.boundaries[i] * scale;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// Component scale of a unit-norm vector in R^d.
|
|
449
|
+
float unit_norm_component_scale(size_t d) {
|
|
450
|
+
FAISS_THROW_IF_NOT(d > 0);
|
|
451
|
+
return 1.0f / std::sqrt(static_cast<float>(d));
|
|
436
452
|
}
|
|
437
453
|
|
|
438
454
|
} // namespace
|
|
439
455
|
|
|
456
|
+
void ScalarQuantizer::SQDistanceComputer::query_to_codes_batch_4(
|
|
457
|
+
const uint8_t* code_0,
|
|
458
|
+
const uint8_t* code_1,
|
|
459
|
+
const uint8_t* code_2,
|
|
460
|
+
const uint8_t* code_3,
|
|
461
|
+
float& dis0,
|
|
462
|
+
float& dis1,
|
|
463
|
+
float& dis2,
|
|
464
|
+
float& dis3) const {
|
|
465
|
+
dis0 = query_to_code(code_0);
|
|
466
|
+
dis1 = query_to_code(code_1);
|
|
467
|
+
dis2 = query_to_code(code_2);
|
|
468
|
+
dis3 = query_to_code(code_3);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
namespace scalar_quantizer {
|
|
472
|
+
|
|
473
|
+
void IVFCoarseDistanceScanner::set_list(idx_t list_no_in, float coarse_dis_in) {
|
|
474
|
+
this->list_no = list_no_in;
|
|
475
|
+
this->coarse_dis = coarse_dis_in;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
float IVFCoarseDistanceScanner::distance_to_code(
|
|
479
|
+
const uint8_t* /*code*/) const {
|
|
480
|
+
return coarse_dis;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
} // namespace scalar_quantizer
|
|
484
|
+
|
|
440
485
|
/*******************************************************************
|
|
441
486
|
* ScalarQuantizer implementation
|
|
442
487
|
********************************************************************/
|
|
@@ -588,19 +633,24 @@ void ScalarQuantizer::train(size_t n, const float* x) {
|
|
|
588
633
|
populate_lloyd_max_trained(bits, trained);
|
|
589
634
|
break;
|
|
590
635
|
case QT_1bit_tqmse:
|
|
591
|
-
populate_lloyd_max_trained(
|
|
636
|
+
populate_lloyd_max_trained(
|
|
637
|
+
1, trained, unit_norm_component_scale(d));
|
|
592
638
|
break;
|
|
593
639
|
case QT_2bit_tqmse:
|
|
594
|
-
populate_lloyd_max_trained(
|
|
640
|
+
populate_lloyd_max_trained(
|
|
641
|
+
2, trained, unit_norm_component_scale(d));
|
|
595
642
|
break;
|
|
596
643
|
case QT_3bit_tqmse:
|
|
597
|
-
populate_lloyd_max_trained(
|
|
644
|
+
populate_lloyd_max_trained(
|
|
645
|
+
3, trained, unit_norm_component_scale(d));
|
|
598
646
|
break;
|
|
599
647
|
case QT_4bit_tqmse:
|
|
600
|
-
populate_lloyd_max_trained(
|
|
648
|
+
populate_lloyd_max_trained(
|
|
649
|
+
4, trained, unit_norm_component_scale(d));
|
|
601
650
|
break;
|
|
602
651
|
case QT_8bit_tqmse:
|
|
603
|
-
populate_lloyd_max_trained(
|
|
652
|
+
populate_lloyd_max_trained(
|
|
653
|
+
8, trained, unit_norm_component_scale(d));
|
|
604
654
|
break;
|
|
605
655
|
case QT_2bit_tq:
|
|
606
656
|
case QT_3bit_tq:
|
|
@@ -614,7 +664,6 @@ void ScalarQuantizer::train(size_t n, const float* x) {
|
|
|
614
664
|
trained.push_back(seed_f[0]);
|
|
615
665
|
trained.push_back(seed_f[1]);
|
|
616
666
|
trained.push_back(static_cast<float>(turboq_refine.qjl_type));
|
|
617
|
-
turboq_refine.init_projection(d);
|
|
618
667
|
break;
|
|
619
668
|
}
|
|
620
669
|
default:
|
|
@@ -622,29 +671,11 @@ void ScalarQuantizer::train(size_t n, const float* x) {
|
|
|
622
671
|
}
|
|
623
672
|
}
|
|
624
673
|
|
|
625
|
-
void ScalarQuantizer::TurboQuantRefine::init_projection(size_t d) {
|
|
626
|
-
if (use_fwht()) {
|
|
627
|
-
padded_d = 1;
|
|
628
|
-
while (padded_d < d) {
|
|
629
|
-
padded_d <<= 1;
|
|
630
|
-
}
|
|
631
|
-
fwht_signs.resize(padded_d);
|
|
632
|
-
RandomGenerator rng(seed);
|
|
633
|
-
for (size_t i = 0; i < padded_d; i++) {
|
|
634
|
-
fwht_signs[i] = (rng.rand_int(2) == 0) ? 1.0f : -1.0f;
|
|
635
|
-
}
|
|
636
|
-
} else {
|
|
637
|
-
rr_matrix.resize(d * d);
|
|
638
|
-
float_randn(rr_matrix.data(), d * d, seed);
|
|
639
|
-
matrix_qr(static_cast<int>(d), static_cast<int>(d), rr_matrix.data());
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
|
|
643
674
|
ScalarQuantizer::SQuantizer* ScalarQuantizer::select_quantizer() const {
|
|
644
675
|
// A SIMD level's factory returns nullptr when the dimension is
|
|
645
676
|
// incompatible (e.g. AVX-512 needs d % 16 == 0); the dispatcher then falls
|
|
646
677
|
// back to the next-lower level (AVX-512 -> AVX2 -> scalar).
|
|
647
|
-
return with_simd_level_fallback<
|
|
678
|
+
return with_simd_level_fallback<AVAILABLE_SIMD_LEVELS_BASE_WITH_SPR>(
|
|
648
679
|
[&]<SIMDLevel SL>() -> SQuantizer* {
|
|
649
680
|
return scalar_quantizer::sq_select_quantizer<SL>(
|
|
650
681
|
qtype, d, trained);
|
|
@@ -681,7 +712,7 @@ void ScalarQuantizer::decode(const uint8_t* codes, float* x, size_t n) const {
|
|
|
681
712
|
ScalarQuantizer::SQDistanceComputer* ScalarQuantizer::get_distance_computer(
|
|
682
713
|
MetricType metric) const {
|
|
683
714
|
FAISS_THROW_IF_NOT(metric == METRIC_L2 || metric == METRIC_INNER_PRODUCT);
|
|
684
|
-
return with_simd_level_fallback<
|
|
715
|
+
return with_simd_level_fallback<AVAILABLE_SIMD_LEVELS_BASE_WITH_SPR>(
|
|
685
716
|
[&]<SIMDLevel SL>() -> SQDistanceComputer* {
|
|
686
717
|
return scalar_quantizer::sq_select_distance_computer<SL>(
|
|
687
718
|
metric, qtype, d, trained);
|
|
@@ -694,7 +725,7 @@ InvertedListScanner* ScalarQuantizer::select_InvertedListScanner(
|
|
|
694
725
|
bool store_pairs,
|
|
695
726
|
const IDSelector* sel,
|
|
696
727
|
bool by_residual) const {
|
|
697
|
-
return with_simd_level_fallback<
|
|
728
|
+
return with_simd_level_fallback<AVAILABLE_SIMD_LEVELS_BASE_WITH_SPR>(
|
|
698
729
|
[&]<SIMDLevel SL>() -> InvertedListScanner* {
|
|
699
730
|
return scalar_quantizer::sq_select_InvertedListScanner<SL>(
|
|
700
731
|
qtype,
|
|
@@ -133,12 +133,7 @@ struct ScalarQuantizer : Quantizer {
|
|
|
133
133
|
float& dis0,
|
|
134
134
|
float& dis1,
|
|
135
135
|
float& dis2,
|
|
136
|
-
float& dis3) const
|
|
137
|
-
dis0 = query_to_code(code_0);
|
|
138
|
-
dis1 = query_to_code(code_1);
|
|
139
|
-
dis2 = query_to_code(code_2);
|
|
140
|
-
dis3 = query_to_code(code_3);
|
|
141
|
-
}
|
|
136
|
+
float& dis3) const;
|
|
142
137
|
|
|
143
138
|
float distance_to_code(const uint8_t* code) final {
|
|
144
139
|
return query_to_code(code);
|
|
@@ -177,18 +172,9 @@ struct ScalarQuantizer : Quantizer {
|
|
|
177
172
|
return s;
|
|
178
173
|
}
|
|
179
174
|
|
|
175
|
+
/// The selected projection is built from `trained` by the quantizer.
|
|
180
176
|
uint8_t qjl_type = 0;
|
|
181
177
|
uint64_t seed = 42;
|
|
182
|
-
size_t padded_d = 0;
|
|
183
|
-
std::vector<float> fwht_signs;
|
|
184
|
-
std::vector<float> rr_matrix;
|
|
185
|
-
size_t nb_bits_lo = 0;
|
|
186
|
-
size_t n_hi_dims = 0;
|
|
187
|
-
|
|
188
|
-
void init_projection(size_t d);
|
|
189
|
-
bool use_fwht() const {
|
|
190
|
-
return qjl_type == 0;
|
|
191
|
-
}
|
|
192
178
|
|
|
193
179
|
struct DistanceComputer : SQDistanceComputer {
|
|
194
180
|
virtual void configure(uint8_t qb, bool int_qjl) = 0;
|
|
@@ -199,6 +185,11 @@ struct ScalarQuantizer : Quantizer {
|
|
|
199
185
|
};
|
|
200
186
|
};
|
|
201
187
|
|
|
188
|
+
static_assert(
|
|
189
|
+
sizeof(TurboQuantRefine) <= 16,
|
|
190
|
+
"keep this a small config struct -- do not add projection buffers "
|
|
191
|
+
"here (T287092602)");
|
|
192
|
+
|
|
202
193
|
TurboQuantRefine turboq_refine;
|
|
203
194
|
|
|
204
195
|
SQDistanceComputer* get_distance_computer(
|
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
// Explicit template instantiations of HeapWithBucketsCMaxFloat and
|
|
9
9
|
// accum_and_*_tab for SIMDLevel::AVX2.
|
|
10
10
|
|
|
11
|
-
#ifdef COMPILE_SIMD_AVX2
|
|
12
|
-
|
|
13
11
|
#include <faiss/impl/approx_topk/rq_beam_search_tab-inl.h>
|
|
14
12
|
#include <faiss/impl/approx_topk/simdlib256-inl.h>
|
|
15
13
|
#include <faiss/impl/simdlib/simdlib_avx2.h>
|
|
@@ -64,5 +62,3 @@ INSTANTIATE_ACCUM_TAB(8)
|
|
|
64
62
|
#undef INSTANTIATE_ACCUM_TAB
|
|
65
63
|
|
|
66
64
|
} // namespace faiss
|
|
67
|
-
|
|
68
|
-
#endif // COMPILE_SIMD_AVX2
|
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
// Explicit template instantiations of HeapWithBucketsCMaxFloat and
|
|
9
9
|
// accum_and_*_tab for SIMDLevel::ARM_NEON.
|
|
10
10
|
|
|
11
|
-
#ifdef COMPILE_SIMD_ARM_NEON
|
|
12
|
-
|
|
13
11
|
#include <faiss/impl/approx_topk/rq_beam_search_tab-inl.h>
|
|
14
12
|
#include <faiss/impl/approx_topk/simdlib256-inl.h>
|
|
15
13
|
#include <faiss/impl/simdlib/simdlib_neon.h>
|
|
@@ -64,5 +62,3 @@ INSTANTIATE_ACCUM_TAB(8)
|
|
|
64
62
|
#undef INSTANTIATE_ACCUM_TAB
|
|
65
63
|
|
|
66
64
|
} // namespace faiss
|
|
67
|
-
|
|
68
|
-
#endif // COMPILE_SIMD_ARM_NEON
|
|
@@ -139,11 +139,14 @@ void search_single_query_template(
|
|
|
139
139
|
} while (fe.next());
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
// A hash type with internal linkage makes the functions of the set local.
|
|
143
|
+
struct ShortlistHash : std::hash<idx_t> {};
|
|
144
|
+
|
|
142
145
|
template <class HammingComputer, class SearchResults>
|
|
143
146
|
static void verify_shortlist(
|
|
144
147
|
const IndexBinaryFlat* index,
|
|
145
148
|
const uint8_t* q,
|
|
146
|
-
const std::unordered_set<idx_t>& shortlist,
|
|
149
|
+
const std::unordered_set<idx_t, ShortlistHash>& shortlist,
|
|
147
150
|
SearchResults& res) {
|
|
148
151
|
size_t code_size = index->code_size;
|
|
149
152
|
|
|
@@ -164,7 +167,7 @@ void search_1_query_multihash(
|
|
|
164
167
|
size_t& n0,
|
|
165
168
|
size_t& nlist,
|
|
166
169
|
size_t& ndis) {
|
|
167
|
-
std::unordered_set<idx_t> shortlist;
|
|
170
|
+
std::unordered_set<idx_t, ShortlistHash> shortlist;
|
|
168
171
|
int b = index.b;
|
|
169
172
|
|
|
170
173
|
BitstringReader br(xi, index.code_size);
|
|
@@ -39,17 +39,50 @@ namespace faiss {
|
|
|
39
39
|
|
|
40
40
|
namespace {
|
|
41
41
|
|
|
42
|
+
// Whether the computer can measure a whole batch of codes in one call.
|
|
42
43
|
template <class HammingComputer>
|
|
43
|
-
|
|
44
|
+
constexpr bool has_hamming_batch =
|
|
45
|
+
requires(const uint8_t* tile, const uint8_t* codes, int32_t* dis) {
|
|
46
|
+
HammingComputer::batch_size;
|
|
47
|
+
HammingComputer::get_code_size();
|
|
48
|
+
HammingComputer::build_batch_query(tile, nullptr);
|
|
49
|
+
HammingComputer::hamming_batch(tile, codes, dis);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// The query repeated batch_size times, which is what hamming_batch() XORs
|
|
53
|
+
// against. Empty for a computer that does not batch, so those scanners carry
|
|
54
|
+
// neither the buffer nor its alignment.
|
|
55
|
+
template <class HammingComputer>
|
|
56
|
+
struct BatchQueryTile {};
|
|
57
|
+
|
|
58
|
+
template <class HammingComputer>
|
|
59
|
+
requires has_hamming_batch<HammingComputer>
|
|
60
|
+
struct BatchQueryTile<HammingComputer> {
|
|
61
|
+
alignas(64) uint8_t batch_query
|
|
62
|
+
[HammingComputer::batch_size * HammingComputer::get_code_size()];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
template <class HammingComputer>
|
|
66
|
+
struct IVFBinaryScannerL2 : BinaryInvertedListScanner,
|
|
67
|
+
BatchQueryTile<HammingComputer> {
|
|
44
68
|
HammingComputer hc;
|
|
45
69
|
size_t code_size;
|
|
46
70
|
bool store_pairs;
|
|
47
71
|
|
|
48
72
|
IVFBinaryScannerL2(size_t code_size_, bool store_pairs_)
|
|
49
|
-
: code_size(code_size_), store_pairs(store_pairs_) {
|
|
73
|
+
: code_size(code_size_), store_pairs(store_pairs_) {
|
|
74
|
+
if constexpr (has_hamming_batch<HammingComputer>) {
|
|
75
|
+
// The batch kernel reads a fixed stride, so a caller that pairs
|
|
76
|
+
// this computer with another code size would read past the codes.
|
|
77
|
+
FAISS_THROW_IF_NOT(code_size == HammingComputer::get_code_size());
|
|
78
|
+
}
|
|
79
|
+
}
|
|
50
80
|
|
|
51
81
|
void set_query(const uint8_t* query_vector) override {
|
|
52
82
|
hc.set(query_vector, code_size);
|
|
83
|
+
if constexpr (has_hamming_batch<HammingComputer>) {
|
|
84
|
+
HammingComputer::build_batch_query(query_vector, this->batch_query);
|
|
85
|
+
}
|
|
53
86
|
}
|
|
54
87
|
|
|
55
88
|
idx_t list_no = 0;
|
|
@@ -61,6 +94,31 @@ struct IVFBinaryScannerL2 : BinaryInvertedListScanner {
|
|
|
61
94
|
return hc.hamming(code);
|
|
62
95
|
}
|
|
63
96
|
|
|
97
|
+
// Measures whole batches while at least batch_size codes remain, then
|
|
98
|
+
// leaves codes and j on the first code the caller must measure singly.
|
|
99
|
+
// bound is read per lane, so a caller that raises its heap top inside
|
|
100
|
+
// accept prunes the rest of the batch.
|
|
101
|
+
template <class Accept>
|
|
102
|
+
void scan_batch_prefix(
|
|
103
|
+
size_t n,
|
|
104
|
+
const uint8_t* __restrict& codes,
|
|
105
|
+
size_t& j,
|
|
106
|
+
const uint32_t& bound,
|
|
107
|
+
Accept&& accept) const {
|
|
108
|
+
if constexpr (has_hamming_batch<HammingComputer>) {
|
|
109
|
+
constexpr size_t B = HammingComputer::batch_size;
|
|
110
|
+
int32_t batch[B];
|
|
111
|
+
for (; j + B <= n; j += B, codes += B * code_size) {
|
|
112
|
+
HammingComputer::hamming_batch(this->batch_query, codes, batch);
|
|
113
|
+
for (size_t t = 0; t < B; t++) {
|
|
114
|
+
if (static_cast<uint32_t>(batch[t]) < bound) {
|
|
115
|
+
accept(batch[t], j + t);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
64
122
|
size_t scan_codes(
|
|
65
123
|
size_t n,
|
|
66
124
|
const uint8_t* __restrict codes,
|
|
@@ -70,15 +128,25 @@ struct IVFBinaryScannerL2 : BinaryInvertedListScanner {
|
|
|
70
128
|
size_t k) const override {
|
|
71
129
|
using C = CMax<int32_t, idx_t>;
|
|
72
130
|
|
|
131
|
+
uint32_t bound = static_cast<uint32_t>(simi[0]);
|
|
132
|
+
|
|
73
133
|
size_t nup = 0;
|
|
74
|
-
|
|
134
|
+
size_t j = 0;
|
|
135
|
+
|
|
136
|
+
auto accept = [&](int32_t dis, size_t at) {
|
|
137
|
+
idx_t id = store_pairs ? lo_build(list_no, at) : ids[at];
|
|
138
|
+
heap_replace_top<C>(k, simi, idxi, dis, id);
|
|
139
|
+
bound = static_cast<uint32_t>(simi[0]);
|
|
140
|
+
nup++;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
scan_batch_prefix(n, codes, j, bound, accept);
|
|
144
|
+
|
|
145
|
+
for (; j < n; j++, codes += code_size) {
|
|
75
146
|
uint32_t dis = hc.hamming(codes);
|
|
76
|
-
if (dis <
|
|
77
|
-
|
|
78
|
-
heap_replace_top<C>(k, simi, idxi, dis, id);
|
|
79
|
-
nup++;
|
|
147
|
+
if (dis < bound) {
|
|
148
|
+
accept(static_cast<int32_t>(dis), j);
|
|
80
149
|
}
|
|
81
|
-
codes += code_size;
|
|
82
150
|
}
|
|
83
151
|
return nup;
|
|
84
152
|
}
|
|
@@ -89,13 +157,21 @@ struct IVFBinaryScannerL2 : BinaryInvertedListScanner {
|
|
|
89
157
|
const idx_t* __restrict ids,
|
|
90
158
|
int radius,
|
|
91
159
|
RangeQueryResult& result) const override {
|
|
92
|
-
|
|
160
|
+
const uint32_t bound = static_cast<uint32_t>(radius);
|
|
161
|
+
size_t j = 0;
|
|
162
|
+
|
|
163
|
+
auto accept = [&](int32_t dis, size_t at) {
|
|
164
|
+
int64_t id = store_pairs ? lo_build(list_no, at) : ids[at];
|
|
165
|
+
result.add(static_cast<uint32_t>(dis), id);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
scan_batch_prefix(n, codes, j, bound, accept);
|
|
169
|
+
|
|
170
|
+
for (; j < n; j++, codes += code_size) {
|
|
93
171
|
uint32_t dis = hc.hamming(codes);
|
|
94
|
-
if (dis <
|
|
95
|
-
|
|
96
|
-
result.add(dis, id);
|
|
172
|
+
if (dis < bound) {
|
|
173
|
+
accept(static_cast<int32_t>(dis), j);
|
|
97
174
|
}
|
|
98
|
-
codes += code_size;
|
|
99
175
|
}
|
|
100
176
|
}
|
|
101
177
|
};
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
#ifdef COMPILE_SIMD_AVX2
|
|
9
|
-
|
|
10
8
|
#define THE_SIMD_LEVEL SIMDLevel::AVX2
|
|
11
9
|
|
|
12
10
|
// NOLINTNEXTLINE(facebook-hte-InlineHeader,facebook-unused-include-check)
|
|
@@ -22,5 +20,3 @@
|
|
|
22
20
|
#include <faiss/impl/binary_hamming/IndexIVFSpectralHash_impl.h> // IWYU pragma: keep
|
|
23
21
|
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
24
22
|
#include <faiss/impl/binary_hamming/IndexPQ_impl.h>
|
|
25
|
-
|
|
26
|
-
#endif // COMPILE_SIMD_AVX2
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
#ifdef COMPILE_SIMD_AVX512
|
|
9
|
-
|
|
10
8
|
#define THE_SIMD_LEVEL SIMDLevel::AVX512
|
|
11
9
|
|
|
12
10
|
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
@@ -22,5 +20,3 @@
|
|
|
22
20
|
#include <faiss/impl/binary_hamming/IndexIVFSpectralHash_impl.h>
|
|
23
21
|
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
24
22
|
#include <faiss/impl/binary_hamming/IndexPQ_impl.h>
|
|
25
|
-
|
|
26
|
-
#endif // COMPILE_SIMD_AVX512
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
#ifdef COMPILE_SIMD_ARM_NEON
|
|
9
|
-
|
|
10
8
|
#define THE_SIMD_LEVEL SIMDLevel::ARM_NEON
|
|
11
9
|
|
|
12
10
|
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
@@ -22,5 +20,3 @@
|
|
|
22
20
|
#include <faiss/impl/binary_hamming/IndexIVFSpectralHash_impl.h>
|
|
23
21
|
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
24
22
|
#include <faiss/impl/binary_hamming/IndexPQ_impl.h>
|
|
25
|
-
|
|
26
|
-
#endif // COMPILE_SIMD_ARM_NEON
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
#ifdef COMPILE_SIMD_RISCV_RVV
|
|
9
|
-
|
|
10
8
|
#define THE_SIMD_LEVEL SIMDLevel::RISCV_RVV
|
|
11
9
|
|
|
12
10
|
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
@@ -22,5 +20,3 @@
|
|
|
22
20
|
#include <faiss/impl/binary_hamming/IndexIVFSpectralHash_impl.h>
|
|
23
21
|
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
24
22
|
#include <faiss/impl/binary_hamming/IndexPQ_impl.h>
|
|
25
|
-
|
|
26
|
-
#endif // COMPILE_SIMD_RISCV_RVV
|