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
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
|
+
#include <functional>
|
|
10
11
|
#include <optional>
|
|
11
12
|
#include <queue>
|
|
13
|
+
#include <utility>
|
|
12
14
|
#include <vector>
|
|
13
15
|
|
|
14
16
|
#include <omp.h>
|
|
@@ -152,8 +154,14 @@ struct HNSW {
|
|
|
152
154
|
/// use bounded queue during exploration
|
|
153
155
|
bool search_bounded_queue = true;
|
|
154
156
|
|
|
155
|
-
///
|
|
156
|
-
|
|
157
|
+
/// Specialized level-0 search implementations. This state is derived from
|
|
158
|
+
/// the owning IndexHNSW subtype after construction or deserialization.
|
|
159
|
+
enum Search_method_t : uint8_t {
|
|
160
|
+
SM_DEFAULT,
|
|
161
|
+
SM_PANORAMA,
|
|
162
|
+
SM_RABITQ,
|
|
163
|
+
};
|
|
164
|
+
Search_method_t search_method = SM_DEFAULT;
|
|
157
165
|
|
|
158
166
|
/// distance comparison semantics: when true, distances are treated as
|
|
159
167
|
/// similarity scores (larger is better). Default false matches the
|
|
@@ -204,14 +212,27 @@ struct HNSW {
|
|
|
204
212
|
VisitedTable& vt,
|
|
205
213
|
bool keep_max_size_level0 = false);
|
|
206
214
|
|
|
207
|
-
/**
|
|
208
|
-
*
|
|
209
|
-
|
|
215
|
+
/** Deterministic build, phase A: write pt_id's forward links against an
|
|
216
|
+
* immutable snapshot, touching only pt_id's own slots. Reciprocal edges
|
|
217
|
+
* are collected in `pt_reverse_edges` for phase B, not applied. Requires
|
|
218
|
+
* entry_point set. */
|
|
219
|
+
void compute_forward_links_deterministic(
|
|
210
220
|
DistanceComputer& ptdis,
|
|
211
221
|
int pt_level,
|
|
212
|
-
|
|
213
|
-
LockVector& locks,
|
|
222
|
+
storage_idx_t pt_id,
|
|
214
223
|
VisitedTable& vt,
|
|
224
|
+
std::vector<std::pair<storage_idx_t, int>>& pt_reverse_edges,
|
|
225
|
+
bool keep_max_size_level0 = false);
|
|
226
|
+
|
|
227
|
+
/** Deterministic build, phase B: merge `incoming` into `node` and
|
|
228
|
+
* re-prune in a total order (distance, ties by id) so the result is
|
|
229
|
+
* order-independent. Touches only `node`'s slots; `incoming` is sorted
|
|
230
|
+
* and deduplicated in place. */
|
|
231
|
+
void merge_reverse_links_deterministic(
|
|
232
|
+
DistanceComputer& dis,
|
|
233
|
+
storage_idx_t node,
|
|
234
|
+
int level,
|
|
235
|
+
std::vector<storage_idx_t>& incoming,
|
|
215
236
|
bool keep_max_size_level0 = false);
|
|
216
237
|
|
|
217
238
|
/// Search interface for 1 point, single thread
|
|
@@ -257,6 +278,94 @@ struct HNSW {
|
|
|
257
278
|
void permute_entries(const idx_t* map);
|
|
258
279
|
};
|
|
259
280
|
|
|
281
|
+
/** Deterministic, lock-free HNSW graph build. This is the only graph build
|
|
282
|
+
* that add() uses, and it is shared by IndexHNSW and
|
|
283
|
+
* IndexBinaryHNSW. The callbacks let both share the algorithm:
|
|
284
|
+
* `make_distance_computer()` returns a fresh DistanceComputer per thread
|
|
285
|
+
* (caller-owned) and `set_query(dc, pt_id)` points it at pt_id's vector. */
|
|
286
|
+
void hnsw_add_vertices_deterministic(
|
|
287
|
+
HNSW& hnsw,
|
|
288
|
+
size_t n0,
|
|
289
|
+
size_t n,
|
|
290
|
+
int d,
|
|
291
|
+
bool init_level0,
|
|
292
|
+
bool keep_max_size_level0,
|
|
293
|
+
bool preset_levels,
|
|
294
|
+
bool verbose,
|
|
295
|
+
const std::function<DistanceComputer*()>& make_distance_computer,
|
|
296
|
+
const std::function<void(DistanceComputer&, HNSW::storage_idx_t)>&
|
|
297
|
+
set_query);
|
|
298
|
+
|
|
299
|
+
/// Parameters of add_level_0_links_from_sample() of IndexHNSW and
|
|
300
|
+
/// IndexBinaryHNSW.
|
|
301
|
+
struct HNSWLevel0LinkParameters {
|
|
302
|
+
/// The search that the new links are for. nullptr: the search settings
|
|
303
|
+
/// of the index, which the IVF assignment with a coarse quantizer uses.
|
|
304
|
+
const SearchParametersHNSW* search_params = nullptr;
|
|
305
|
+
/// A sink receives at least this factor times the mean number of
|
|
306
|
+
/// vectors per node.
|
|
307
|
+
float min_mean_factor = 3.0f;
|
|
308
|
+
/// For at least this fraction of the vectors that the search sends to a
|
|
309
|
+
/// sink, an exact search finds a nearer node.
|
|
310
|
+
float min_closer_fraction = 0.5f;
|
|
311
|
+
/// Maximum number of level-0 links added to one sink in one round.
|
|
312
|
+
int max_links_per_sink = 32;
|
|
313
|
+
/// Maximum number of rounds that find sinks and add links.
|
|
314
|
+
int max_rounds = 3;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
struct HNSWLevel0LinkStats {
|
|
318
|
+
/// Sinks found in the first round.
|
|
319
|
+
size_t n_sinks_found = 0;
|
|
320
|
+
/// Sinks found after the last round.
|
|
321
|
+
size_t n_sinks_remaining = 0;
|
|
322
|
+
/// Level-0 links written into free slots.
|
|
323
|
+
size_t n_links_added = 0;
|
|
324
|
+
/// Level-0 links that replaced a link.
|
|
325
|
+
size_t n_links_replaced = 0;
|
|
326
|
+
/// Rounds that changed links.
|
|
327
|
+
int n_rounds = 0;
|
|
328
|
+
/// Exact searches with the storage, in all rounds.
|
|
329
|
+
size_t n_exact_searches = 0;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
/** The two searches of the sample vectors that
|
|
333
|
+
* hnsw_add_level_0_links_from_sample() compares. IndexHNSW and IndexBinaryHNSW
|
|
334
|
+
* implement them for their vector types. */
|
|
335
|
+
struct HNSWLinkSampleSearch {
|
|
336
|
+
/// number of sample vectors
|
|
337
|
+
idx_t n = 0;
|
|
338
|
+
|
|
339
|
+
virtual ~HNSWLinkSampleSearch() = default;
|
|
340
|
+
|
|
341
|
+
/// HNSW search (k = 1) of the m sample vectors `ids` (null: the first m).
|
|
342
|
+
virtual void search(
|
|
343
|
+
const SearchParametersHNSW* params,
|
|
344
|
+
size_t m,
|
|
345
|
+
const idx_t* ids,
|
|
346
|
+
idx_t* labels) const = 0;
|
|
347
|
+
|
|
348
|
+
/** Exact search (k = 1) of the m sample vectors `ids`. nearer[j] is 1 when
|
|
349
|
+
* exact[j] is nearer than found[j] by more than rounding differences. */
|
|
350
|
+
virtual void search_exact(
|
|
351
|
+
size_t m,
|
|
352
|
+
const idx_t* ids,
|
|
353
|
+
const idx_t* found,
|
|
354
|
+
idx_t* exact,
|
|
355
|
+
uint8_t* nearer) const = 0;
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
/** add_level_0_links_from_sample() of IndexHNSW and IndexBinaryHNSW.
|
|
359
|
+
* `dis` computes distances between nodes. `similarity` is true when a larger
|
|
360
|
+
* distance is nearer. */
|
|
361
|
+
HNSWLevel0LinkStats hnsw_add_level_0_links_from_sample(
|
|
362
|
+
HNSW& hnsw,
|
|
363
|
+
size_t ntotal,
|
|
364
|
+
DistanceComputer& dis,
|
|
365
|
+
bool similarity,
|
|
366
|
+
const HNSWLinkSampleSearch& sample,
|
|
367
|
+
const HNSWLevel0LinkParameters& params);
|
|
368
|
+
|
|
260
369
|
struct HNSWStats {
|
|
261
370
|
size_t n1 = 0; /// number of vectors searched
|
|
262
371
|
size_t n2 =
|
|
@@ -276,6 +385,8 @@ struct HNSWStats {
|
|
|
276
385
|
ndis += other.ndis;
|
|
277
386
|
nhops += other.nhops;
|
|
278
387
|
}
|
|
388
|
+
|
|
389
|
+
void combine_atomic(const HNSWStats& other);
|
|
279
390
|
};
|
|
280
391
|
|
|
281
392
|
// global var that collects them all
|
|
@@ -23,6 +23,50 @@ struct IDSelector {
|
|
|
23
23
|
virtual ~IDSelector() {}
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
/** Scan context handed to IDSelectorWithContext::is_member_with_context: the
|
|
27
|
+
* contiguous id block being scanned and the position of the id under test. */
|
|
28
|
+
struct IDScanContext {
|
|
29
|
+
/// the contiguous block of ids being scanned
|
|
30
|
+
const idx_t* ids;
|
|
31
|
+
/// number of entries in `ids`
|
|
32
|
+
size_t list_size;
|
|
33
|
+
/// index of the tested id within `ids` (i.e. ids[j] == id)
|
|
34
|
+
size_t j;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** IDSelector that also receives the surrounding scan context on each
|
|
38
|
+
* membership test, letting an implementation exploit locality across a scan
|
|
39
|
+
* (for example, prefetching data for an entry it will be asked about soon).
|
|
40
|
+
* The policy is entirely up to the implementation. */
|
|
41
|
+
struct IDSelectorWithContext : IDSelector {
|
|
42
|
+
virtual bool is_member_with_context(idx_t id, const IDScanContext& ctx)
|
|
43
|
+
const = 0;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** Routes each per-candidate membership test to is_member_with_context() when
|
|
47
|
+
* the selector implements IDSelectorWithContext, else to plain is_member().
|
|
48
|
+
* Construct one per inverted-list scan: the dynamic_cast is the only RTTI cost
|
|
49
|
+
* and the per-candidate cost is a single predicted branch (cf. the
|
|
50
|
+
* IDSelectorRange dynamic_cast in IndexIVF.cpp). The scan context is only
|
|
51
|
+
* meaningful when the scan exposes a real id array (i.e. !store_pairs); when
|
|
52
|
+
* store_pairs the context path is disabled and every test falls back to
|
|
53
|
+
* is_member. */
|
|
54
|
+
struct IDSelectorContextDispatch {
|
|
55
|
+
const IDSelector* sel;
|
|
56
|
+
const IDSelectorWithContext* ctx_sel;
|
|
57
|
+
|
|
58
|
+
IDSelectorContextDispatch(const IDSelector* sel, bool store_pairs)
|
|
59
|
+
: sel(sel),
|
|
60
|
+
ctx_sel((sel != nullptr && !store_pairs)
|
|
61
|
+
? dynamic_cast<const IDSelectorWithContext*>(sel)
|
|
62
|
+
: nullptr) {}
|
|
63
|
+
|
|
64
|
+
bool is_member(idx_t id, const IDScanContext& ctx) const {
|
|
65
|
+
return ctx_sel ? ctx_sel->is_member_with_context(id, ctx)
|
|
66
|
+
: sel->is_member(id);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
26
70
|
/** ids between [imin, imax) */
|
|
27
71
|
struct IDSelectorRange : IDSelector {
|
|
28
72
|
idx_t imin, imax;
|
|
@@ -23,12 +23,9 @@
|
|
|
23
23
|
#include <faiss/utils/utils.h>
|
|
24
24
|
|
|
25
25
|
#include <faiss/impl/approx_topk/approx_topk.h>
|
|
26
|
+
#include <faiss/impl/platform_macros.h>
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
#ifdef COMPILE_SIMD_AVX2
|
|
30
|
-
#include <xmmintrin.h>
|
|
31
|
-
#endif
|
|
28
|
+
#include <faiss/utils/prefetch.h>
|
|
32
29
|
|
|
33
30
|
extern "C" {
|
|
34
31
|
// LU decomposition of a general matrix
|
|
@@ -602,7 +599,7 @@ void LocalSearchQuantizer::icm_encode_step(
|
|
|
602
599
|
|
|
603
600
|
// Resolve SIMD level once, not per iteration of the n × n_iters × M loop.
|
|
604
601
|
with_simd_level_256bit([&]<SIMDLevel SL>() {
|
|
605
|
-
#pragma omp parallel for schedule(
|
|
602
|
+
#pragma omp parallel for schedule(FAISS_OMP_DYNAMIC)
|
|
606
603
|
for (int64_t i = 0; i < static_cast<int64_t>(n); i++) {
|
|
607
604
|
std::vector<float> objs(K);
|
|
608
605
|
|
|
@@ -622,23 +619,13 @@ void LocalSearchQuantizer::icm_encode_step(
|
|
|
622
619
|
continue;
|
|
623
620
|
}
|
|
624
621
|
|
|
625
|
-
#ifdef COMPILE_SIMD_AVX2
|
|
626
|
-
// TODO: add platform-independent compiler-independent
|
|
627
|
-
// prefetch utilities.
|
|
628
622
|
if (other_m + 1 < M) {
|
|
629
623
|
// do a single prefetch
|
|
630
624
|
int32_t code2 = codes[i * M + other_m + 1];
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
size_t binary_idx = (other_m + 1) * M * K * K +
|
|
635
|
-
m * K * K + code2 * K + code;
|
|
636
|
-
_mm_prefetch(
|
|
637
|
-
(const char*)(binaries + binary_idx),
|
|
638
|
-
_MM_HINT_T0);
|
|
639
|
-
}
|
|
625
|
+
size_t binary_idx = (other_m + 1) * M * K * K +
|
|
626
|
+
m * K * K + code2 * K;
|
|
627
|
+
prefetch_L1(binaries + binary_idx);
|
|
640
628
|
}
|
|
641
|
-
#endif
|
|
642
629
|
|
|
643
630
|
for (size_t code = 0; code < K; code++) {
|
|
644
631
|
int32_t code2 = codes[i * M + other_m];
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
#include <faiss/impl/AuxIndexStructures.h>
|
|
15
15
|
#include <faiss/impl/DistanceComputer.h>
|
|
16
16
|
#include <faiss/impl/VisitedTable.h>
|
|
17
|
+
#include <faiss/impl/platform_macros.h>
|
|
17
18
|
|
|
18
19
|
namespace faiss {
|
|
19
20
|
|
|
@@ -200,7 +201,7 @@ void NNDescent::join(DistanceComputer& qdis) {
|
|
|
200
201
|
idx_t check_period = InterruptCallback::get_period_hint(d * search_L);
|
|
201
202
|
for (idx_t i0 = 0; i0 < (idx_t)ntotal; i0 += check_period) {
|
|
202
203
|
idx_t i1 = std::min(i0 + check_period, (idx_t)ntotal);
|
|
203
|
-
#pragma omp parallel for default(shared) schedule(
|
|
204
|
+
#pragma omp parallel for default(shared) schedule(FAISS_OMP_DYNAMIC, 100)
|
|
204
205
|
for (idx_t n = i0; n < i1; n++) {
|
|
205
206
|
graph[n].join([&](int i, int j) {
|
|
206
207
|
if (i != j) {
|
|
@@ -264,6 +265,8 @@ void NNDescent::update() {
|
|
|
264
265
|
auto& nn_new = node.nn_new;
|
|
265
266
|
auto& nn_old = node.nn_old;
|
|
266
267
|
|
|
268
|
+
// other.pool.back() below is read without other.lock: in this
|
|
269
|
+
// phase no thread reorders or resizes a pool. Lock guards rnn_*.
|
|
267
270
|
for (int l = 0; l < node.M; ++l) {
|
|
268
271
|
auto& nn = node.pool[l];
|
|
269
272
|
auto& other = graph[nn.id]; // the other side of the edge
|
|
@@ -283,7 +286,6 @@ void NNDescent::update() {
|
|
|
283
286
|
}
|
|
284
287
|
}
|
|
285
288
|
nn.flag = false;
|
|
286
|
-
|
|
287
289
|
} else { // the node is old
|
|
288
290
|
// push the neighbor into nn_old
|
|
289
291
|
nn_old.push_back(nn.id);
|
|
@@ -300,11 +302,17 @@ void NNDescent::update() {
|
|
|
300
302
|
}
|
|
301
303
|
}
|
|
302
304
|
}
|
|
303
|
-
// make heap to join later (in join() function)
|
|
304
|
-
std::make_heap(node.pool.begin(), node.pool.end());
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
+
// Restore the max-heap invariant for the next join()'s insert(). Must
|
|
309
|
+
// stay a separate region: re-heapifying during Step 3 would race with
|
|
310
|
+
// its unlocked other.pool.back() reads.
|
|
311
|
+
#pragma omp parallel for
|
|
312
|
+
for (int n = 0; n < ntotal; ++n) {
|
|
313
|
+
std::make_heap(graph[n].pool.begin(), graph[n].pool.end());
|
|
314
|
+
}
|
|
315
|
+
|
|
308
316
|
// Step 4.
|
|
309
317
|
// Combine the forward and the reverse links
|
|
310
318
|
// R = 0 means no reverse links are used.
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
#include <faiss/impl/DistanceComputer.h>
|
|
17
17
|
#include <faiss/impl/VisitedTable.h>
|
|
18
|
+
#include <faiss/impl/platform_macros.h>
|
|
18
19
|
|
|
19
20
|
namespace faiss {
|
|
20
21
|
|
|
@@ -352,7 +353,7 @@ void NSG::link(
|
|
|
352
353
|
std::unique_ptr<DistanceComputer> dis(
|
|
353
354
|
storage_distance_computer(storage));
|
|
354
355
|
|
|
355
|
-
#pragma omp for schedule(
|
|
356
|
+
#pragma omp for schedule(FAISS_OMP_DYNAMIC, 100)
|
|
356
357
|
for (int i = 0; i < ntotal; i++) {
|
|
357
358
|
storage->reconstruct(i, vec.get());
|
|
358
359
|
dis->set_query(vec.get());
|
|
@@ -375,7 +376,7 @@ void NSG::link(
|
|
|
375
376
|
std::unique_ptr<DistanceComputer> dis(
|
|
376
377
|
storage_distance_computer(storage));
|
|
377
378
|
|
|
378
|
-
#pragma omp for schedule(
|
|
379
|
+
#pragma omp for schedule(FAISS_OMP_DYNAMIC, 100)
|
|
379
380
|
for (int i = 0; i < ntotal; ++i) {
|
|
380
381
|
add_reverse_links(i, locks, *dis, graph);
|
|
381
382
|
}
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
#include <faiss/impl/IDSelector.h>
|
|
15
15
|
#include <faiss/impl/PanoramaStats.h>
|
|
16
16
|
#include <faiss/utils/distances.h>
|
|
17
|
+
#include <faiss/utils/simd_levels.h>
|
|
17
18
|
|
|
18
19
|
#include <algorithm>
|
|
19
20
|
#include <cstddef>
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
#include <cstring>
|
|
22
23
|
#include <vector>
|
|
23
24
|
|
|
24
|
-
#if
|
|
25
|
+
#if FAISS_SIMD_TU(AVX2) && defined(__BMI2__)
|
|
25
26
|
#include <immintrin.h>
|
|
26
27
|
#endif
|
|
27
28
|
|
|
@@ -154,7 +155,7 @@ inline size_t compact_active_kernel(
|
|
|
154
155
|
size_t next_active = 0;
|
|
155
156
|
size_t i = 0;
|
|
156
157
|
|
|
157
|
-
#if
|
|
158
|
+
#if FAISS_SIMD_TU(AVX2) && defined(__BMI2__)
|
|
158
159
|
for (; i + 8 <= num_active; i += 8) {
|
|
159
160
|
uint64_t bytes;
|
|
160
161
|
memcpy(&bytes, &active_byteset[i], 8);
|
|
@@ -235,7 +236,8 @@ inline auto with_bool(bool value, Lambda&& fn) {
|
|
|
235
236
|
* accelerating the refinement stage.
|
|
236
237
|
*/
|
|
237
238
|
struct Panorama {
|
|
238
|
-
static constexpr size_t kDefaultBatchSize =
|
|
239
|
+
static constexpr size_t kDefaultBatchSize = 1024;
|
|
240
|
+
static constexpr size_t kLegacyBatchSize = 128;
|
|
239
241
|
|
|
240
242
|
size_t d = 0;
|
|
241
243
|
size_t code_size = 0;
|
|
@@ -322,12 +324,20 @@ struct Panorama {
|
|
|
322
324
|
size_t batch_offset = batch_no * batch_size * code_size;
|
|
323
325
|
const uint8_t* storage_base = codes_base + batch_offset;
|
|
324
326
|
|
|
327
|
+
// Honor IDSelectorWithContext: the scan-order position within the whole
|
|
328
|
+
// list is global_idx, so a lookahead crosses batch boundaries correctly
|
|
329
|
+
// (ids is the full list, length list_size).
|
|
330
|
+
IDSelectorContextDispatch sel_dispatch(
|
|
331
|
+
sel, /*store_pairs=*/ids == nullptr);
|
|
332
|
+
|
|
325
333
|
// Initialize active set with ID-filtered vectors.
|
|
326
334
|
size_t num_active = 0;
|
|
327
335
|
for (size_t i = 0; i < curr_batch_size; i++) {
|
|
328
336
|
size_t global_idx = batch_start + i;
|
|
329
337
|
idx_t id = (ids == nullptr) ? global_idx : ids[global_idx];
|
|
330
|
-
bool include = !use_sel ||
|
|
338
|
+
bool include = !use_sel ||
|
|
339
|
+
sel_dispatch.is_member(
|
|
340
|
+
id, IDScanContext{ids, list_size, global_idx});
|
|
331
341
|
|
|
332
342
|
active_indices[num_active] = i;
|
|
333
343
|
float cum_sum = batch_cum_sums[i];
|