Skip to main content

Module simd

Module simd 

Source
Expand description

Vector operations with SIMD acceleration.

Multiple backends are supported via feature flags:

FeatureBackendPerformanceNotes
innr (default)innr crate4-8xPure Rust, good baseline
simsimdSimSIMDUp to 200xC bindings, best on modern CPUs
(none)Portable1xFallback, no dependencies

§Feature Priority

If multiple features are enabled, priority is: simsimd > innr > fallback

§Usage

For normalized embeddings, prefer dot() over cosine().

use vicinity::simd::{dot, cosine, norm};

let a = [1.0_f32, 0.0, 0.0];
let b = [0.707, 0.707, 0.0];

let d = dot(&a, &b);
let c = cosine(&a, &b);
let n = norm(&a);

Functions§

cosine
Cosine similarity between two vectors.
dot
Dot product of two vectors: Σ(a[i] * b[i]).
dot_portable
Portable (non-SIMD) dot product.
l2_distance
L2 (Euclidean) distance: sqrt(Σ(a[i] - b[i])²).
l2_distance_squared
Squared L2 distance: Σ(a[i] - b[i])².
norm
L2 norm (Euclidean norm) of a vector: sqrt(Σ(v[i]²)).
sparse_dot
Sparse dot product using sorted index arrays.
sparse_dot_portable
Portable implementation of sparse dot product.