Similarity Metrics: Cosine Similarity, Dot Product and Euclidean Distance
~13 min read
Three ways to measure how 'close' two vectors are — cosine similarity (angle), dot product (angle + magnitude), and Euclidean distance (straight-line distance) — each suited to different situations.
Similarity Metrics: Cosine Similarity, Dot Product and Euclidean Distance is a Pro topic
Sign in, then upgrade to Pro or Power to unlock this topic and the full AI Engineering curriculum.
Key points
- •Cosine similarity measures only the ANGLE between vectors (ignores length) — the common default for text embeddings, ranging -1 to 1
- •Dot product = cosine similarity x both magnitudes — it DOES factor in vector length, is slightly cheaper to compute, and is the intended metric for some models
- •Euclidean distance is ordinary straight-line distance — unlike the other two, SMALLER means more similar, and it cares about both direction and magnitude
- •Cosine similarity is the safe general default for text; check your specific embedding model's docs, since some are trained for dot product instead
- •Fast similarity metrics narrow down candidates; a heavier cross-encoder re-ranking step (from the book's RAG workflow) can then refine that shortlist more accurately but more slowly