Expand description
Vector operations with SIMD acceleration.
Multiple backends are supported via feature flags:
| Feature | Backend | Performance | Notes |
|---|---|---|---|
innr (default) | innr crate | 4-8x | Pure Rust, good baseline |
simsimd | SimSIMD | Up to 200x | C bindings, best on modern CPUs |
| (none) | Portable | 1x | Fallback, 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.