normalize_vector

Function normalize_vector 

Source
pub fn normalize_vector(vec: &[f32]) -> Vec<f32>
Expand description

Normalize a vector to unit length (L2 norm = 1).

This ensures cosine similarity can be computed efficiently.

§Arguments

  • vec - The vector to normalize

§Panics

Panics if the input vector is all zeros (cannot normalize)