Normalize Once, Compare Fast

Normalization

Part of: Embeddings & Semantic Search

Say you have got 10,000 movies and a user picks one. You want the closest matches, fast. Computing cosine the naive way recalculates two square-root magnitudes for every comparison. That is wasteful, and it gets brutal at a million vectors. Production search engines all use the same trick. What it is To normalize a vector, divide every component by its magnitude. The result points the exact same direction but has length 1. A vector with length exactly 1 is called a unit vector . Take [3, 4]. Its magnitude is 5. Normalized, it becomes [0.6, 0.8]. Check the length: sqrt(0.6² + 0.8²) = sqrt(0.36 + 0.64) = sqrt(1) = 1. Same direction, length rescaled to one. How it works (and why it speeds things up) Recall cosine is dot(a, b) / (mag(a) mag(b)). If both vectors are already normalized, both magnitudes are 1, so dividing by them changes nothing. The whole formula collapses: That is the payoff. Normalize your entire database once, up front, at index time. After that, every query is a plain dot product, no square roots in the hot loop, no per-comparison magnitude work. For a million-vector index, that is the difference between a fast search and a slow one. This is precisely why real vector

Challenge: Pre-Normalize the Index