Expand description
Element-wise vector math nodes (type_system_alignment.md §8.2).
These are the first compute-shaped (rather than I/O-shaped)
consumers of the typed-vector family: perturbing query vectors,
computing ground-truth distances in evaluations, normalizing
embeddings. On jit builds the f32 hot loops execute through
the cranelift-SIMD kernels (compile::jit::simd — F32X4
chunked with scalar tails); without jit, or if host ISA
construction fails, the scalar reference loops below run
instead. SIMD accumulation reassociates float addition, so dot
products may differ from the scalar reference in the final
ulps — both orders are equally valid IEEE 754 sums.
Length mismatches panic with both lengths named: silently truncating to the shorter operand would corrupt distance semantics (“never ignore silently”).
Structs§
- HashVec
hash_vec(seed, dim)— deterministic synthetic f32 vector: elementiis the SplitMix64 hash of(seed, i)mapped into[-1, 1). The canonical generator for synthetic embeddings — equal seeds always produce the identical vector, so dataset- free vector workloads stay replayable. Pairs withvec_normfor unit vectors.- LidMle
lid_mle(distances, k)— Levina–Bickel maximum-likelihood estimate of the local intrinsic dimensionality at one query point, from its sorted ground-truth nearest-neighbor distances.- VecAdd
vec_add(a, b)— element-wise sum of two f32 vectors. Panics when the lengths differ.- VecCosine
vec_cosine(a, b)— cosine similarity of two f32 vectors:dot(a,b) / (|a| * |b|). Returns 0.0 when either vector has zero magnitude (the conventional degenerate-case value: no direction, no similarity). Panics when the lengths differ.- VecDot
vec_dot(a, b)— dot product of two f32 vectors, widened to f64 on the output wire. Panics when the lengths differ.- VecL2
vec_l2(a, b)— Euclidean (L2) distance between two f32 vectors. Panics when the lengths differ.- VecNorm
vec_norm(a)— scale an f32 vector to unit L2 magnitude. A zero vector passes through unchanged (there is no direction to normalize onto, and emitting NaNs would poison downstream distance math silently).- VecScale
vec_scale(a, k)— multiply every element of an f32 vector by scalark(applied at f32 precision).- Xxhash3
Vec xxhash3_vec(seed, dim)— deterministic synthetic f32 vector using xxHash3.
Functions§
- add_f32
a + belement-wise, as a new vector.- add_
f32_ into a + belement-wise intoout, which is cleared first.- check_
lens - Panics with both lengths named when two operands differ in length.
- cosine_
f32 - The cosine similarity of
vec_cosine. - dot_f32
- The dot product, through the SIMD kernel where the host has one.
- dot_
scalar - The scalar dot product: the reference the SIMD kernel is checked against.
- hash_
vec_ into - The vector of
hash_vecintoout, which is cleared first. - l2sq_
f32 - The squared L2 distance, through the SIMD kernel where the host has one.
- l2sq_
scalar - The scalar squared L2 distance: the reference the SIMD kernel is checked against.
- lid_
mle_ of - The estimate of
lid_mle. - norm_
f32_ into ascaled to unit L2 magnitude intoout;aitself when its magnitude is zero.- scale_
f32 a * kelement-wise, as a new vector.- scale_
f32_ into a * kelement-wise intoout, which is cleared first.- xxhash3_
vec_ into - The vector of
xxhash3_vecintoout, which is cleared first.