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
