normalize

Returns a copy of vector scaled to unit length.

This is the only place a broken embedder can be caught, so it is strict: empty, zero-magnitude and non-finite vectors are all rejected here rather than allowed downstream.

The non-finite case is the dangerous one. A single Infinity or NaN component normalizes to a vector of NaN, every similarity computed from it is NaN, and NaN < threshold is false — so a poisoned vector does not score badly, it skips the threshold entirely and is served as a hit. Worse, sorting puts NaN ahead of a perfect 1.0, so one bad entry outranks every real match in its scope for as long as it lives.

Throws

if vector is empty, has zero magnitude, or contains a non-finite component.