androidengineers.Book a session

Quantitative foundations · Vectors and uncertainty

Vectors, dot products, and cosine similarity

articleSelf-paced

A vector is an ordered list of numbers. Its dimension is the number of components. A dot product multiplies corresponding components and adds the results; both vectors must have the same dimension. A norm measures magnitude.

Cosine similarity divides the dot product by the product of the norms. It compares direction and is undefined for a zero vector unless your application defines a fallback. In an embedding system, similar directions can indicate related meaning, but the score is not proof of factual correctness.

For vectors (1, 0) and (0, 1), the dot product is zero and cosine similarity is zero. For (1, 0) and (2, 0), cosine similarity is one despite different magnitudes. This explains why normalization changes some comparisons but not others.

Exercise: implement dot product and cosine similarity with explicit dimension and zero-vector checks. Test the two examples and opposite directions.

Check: dimension mismatches are rejected and similarity is never described as an authorization or truth score.

YOUR LEARNING JOURNEY

0 of 118 available lessons completed

Progress saved in this browser. No account needed.
Vectors, dot products, and cosine similarity | Agentic AI | Android Engineers