HomeLearnCoursesHackathonsAccount
Vector Databases & Embeddings
Measuring Similarity: Cosine, Dot Product, and Euclidean Distance · 1/2

Three ways to compare two vectors

Once you have vectors, you need a way to score how similar two of them are, and there isn't just one way to do this. Cosine similarity measures the angle between two vectors, ignoring their magnitude entirely, and returns a value that's high when the vectors point in a similar direction regardless of length. Dot product multiplies corresponding components and sums the results; it's sensitive to both angle and magnitude, so a longer vector can produce a higher score even at the same angle. Euclidean distance measures the straight-line distance between the two points, treating them as literal points in space rather than as directions from the origin.

These aren't interchangeable, and picking one is not a stylistic choice, it changes what 'similar' means in practice. Cosine similarity answers 'do these point in the same direction', which tends to map well onto semantic similarity because it factors out how 'intense' or 'long' a vector happens to be. Dot product answers 'do these point the same way and are they both large', which can be useful when magnitude itself carries information, for example when a model's training objective was explicitly aligned with dot product scoring. Euclidean distance answers 'how far apart are these points', which is intuitive but can be misleading in high dimensions where distances tend to compress together, a phenomenon sometimes called the curse of dimensionality.