Skip to content

Euclidean Distance

A distance metric measuring the straight-line distance between two points in vector space, also known as L2 distance.

Euclidean distance, also called L2 distance, measures the straight-line distance between two points in vector space — the same notion of distance you would measure with a ruler if you could see the space. The closer two vectors are by this measure, the more similar the items they represent.

It is computed by taking the differences between the vectors coordinate by coordinate, squaring them, summing, and taking the square root. Because it accounts for magnitude as well as direction, Euclidean distance is the natural choice when the length of a vector carries meaning — for example in some image embeddings where the strength of a feature, not just its presence, is informative.

In very high-dimensional spaces, Euclidean distance is more affected by the curse of dimensionality than cosine similarity, since distances tend to flatten out as dimensions grow. This is one reason cosine similarity, which focuses only on direction, is often preferred for text. The right metric depends on what the embedding model was trained to use, so it is best to follow the model’s recommendation.