Example in 2D
Suppose point A = (-3, -1) and point B = (3, 2). The horizontal gap Δx is 6 and the vertical gap Δy is 3. Using the Pythagorean theorem, the squared distance is:Euclidean distance vs. cosine similarity
Use this table to quickly compare the two similarity/distance concepts:| Concept | What it measures | Sensitive to | Typical use cases |
|---|---|---|---|
| Euclidean distance | Straight-line distance between points | Magnitude and absolute position | Physical measurements, clustering with k-means, low-dimensional spatial data |
| Cosine similarity | Angle between vectors (direction) | Direction, not magnitude | Text embeddings, document similarity, high-dimensional normalized embeddings |
- Euclidean distance measures actual positions in space (absolute differences).
- Cosine similarity measures the angle between vectors (direction), ignoring magnitude.
- Two vectors can point in the same direction but be far apart in magnitude; cosine similarity may treat them as similar while Euclidean distance will not.
When to use Euclidean distance
- Use Euclidean distance when magnitude matters: comparing prices, physical measurements, or sensor readings where absolute differences are meaningful.
- Clustering: k-means typically uses (squared) Euclidean distance by default, so many clustering pipelines rely on it for grouping similar datapoints (e.g., user behavior segments, product grouping).
- Low-dimensional spatial data: for 2D or 3D Cartesian coordinates (local maps, geometry), Euclidean distance is the natural choice.
Euclidean distance is the straight-line distance between two points: smaller distance means more similar, larger distance means less similar.
Caveat: high-dimensional data and the curse of dimensionality
When working with very high-dimensional embeddings (hundreds or thousands of dimensions, as is common for text embeddings), Euclidean distance can lose discriminative power. In very high-dimensional spaces, many points tend to appear similarly distant from one another, which reduces the usefulness of Euclidean measures for distinguishing nearest neighbors. This is why cosine similarity or other normalized measures are often preferred for high-dimensional text embeddings.
Be cautious using Euclidean distance for high-dimensional embeddings: the curse of dimensionality can make distances less meaningful. Consider cosine similarity or other normalized measures for many text-embedding tasks.
Summary
- Euclidean distance = straight-line distance between two points.
- Smaller distance → more similar; larger distance → less similar.
- Best for magnitude-sensitive comparisons, low-dimensional spatial data, and algorithms like k-means.
- Avoid relying solely on Euclidean distance for very high-dimensional text embeddings.
Links and references
- K-Means Clustering — scikit-learn
- Great-circle distance / Haversine formula — Wikipedia
- Cosine similarity — Wikipedia