Distance helpers

Updated Oct 20, 2025

chutoro-core also ships scalar Euclidean and cosine distance helpers. Both validate inputs for finite values, matching dimensions, and positive lengths before computing the distance. The functions return the Distance newtype, which dereferences to f32 and exposes the raw value through value().

Use CosineNorms::from_vectors or CosineNorms::new to pre-compute validated L2 norms for cosine distance. Reuse the cached norms across repeated queries to avoid redundant work; the cosine helper verifies cached values before it performs the final calculation.