liveBook · Manning

Unit normalization

As explained in AI-Powered Search

Unit normalization is the transformation of a vector so that its magnitude equals one.

Unit normalization transforms a vector so its magnitude, or length, equals one. For a vector, divide every component by the square root of the sum of its squared components. section 13.2.2

Normalizing both document and query vectors makes cosine similarity equal to their dot product. Index normalized document vectors and normalize each query vector at search time to avoid repeated magnitude and square-root calculations. section 13.2.2

Worked vector example

The vector [5.0, 3.0] becomes [0.8575, 0.5145], while [6.0, 2.0] becomes [0.9487, 0.3162]. Their dot product is 0.9762, matching their cosine similarity. section 13.2.2

vector_a = [5.0, 3.0]
vector_b = [6.0, 2.0]

unit_vector_a  #1
  = unit_normalize(vector_a)  #1
  = unit_normalize([5.0, 3.0])  #1
  = [5.0 / sqrt(5.0^2 + 3.0^2), 3.0 / sqrt(5.0^2 + 3.0^2)]  #1
  = [0.8575,  0.5145]  #1
  #1
unit_vector_b  #1
  = unit_normalize(vector_b)  #1
  = unit_normalize([6.0, 2.0])  #1
  = [6.0 / sqrt(6.0^2 + 2.0^2), 2.0 / sqrt(6.0^2 + 2.0^2)]  #1
  = [0.9487, 0.3162]  #1

cos(vector_a, vector_b)  #2
  = cos([5.0, 3.0], [6.0, 2.0])  #2
  = (5.0 x 6.0 + 3.0 x 2.0) /  #2
    (sqrt(5.0^2 + 3.0^2) x sqrt(6.0^2 + 2.0^2))  #2
  = 0.9762  #3

dot_product(unit_vector_a, unit_vector_b)  #4
  = dot_product([0.8575, 0.5145], [0.9487, 0.3162])  #4
  = (0.8575 x 0.9487) + (0.5145 x 0.3162)  #4
  = 0.9762  #3

Inspect the component-by-component normalization and the resulting dot-product calculation. section 13.2.2

How AI-Powered Search covers it

How deep it goes
Explains the normalization formula, worked values, and indexing strategy, but defers implementation-specific production details.
Examples
Calculates normalized forms of [5.0, 3.0] and [6.0, 2.0], then compares their dot product with cosine similarity.
What it assumes
Assumes vectors and dot products, while reviewing cosine similarity and vector magnitude through the normalization example.
What you can do after
Apply it by normalizing indexed vectors and query vectors, then scoring them with dot products.
How it connects
Connects unit normalization to cosine similarity, dot product, vector embeddings, and dense vector search.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI-Powered Search. The section links point to the parts of the book it draws on.