Euclidean distance measures the straight-line distance between two points in space. For embedding vectors, smaller Euclidean distance means the vectors are closer together — and potentially more semantically similar.
The formula generalizes the Pythagorean theorem to multiple dimensions: take the squared difference in each dimension, sum them all, and take the square root.
Measures absolute distance between vector endpoints. Sensitive to magnitude — long and short vectors of the same meaning can be "far apart."
Best when magnitude carries meaningful information, or for clustering algorithms like K-Means.
Measures the angle between vectors. Invariant to magnitude — a short sentence and a long paragraph about the same topic can score near 1.0.
Best for comparing text embeddings of different-length inputs. Standard choice for semantic search.
L2 normalization scales all vectors to unit length (magnitude = 1) before storage. After normalization, all vectors lie on the surface of a unit hypersphere. In this state, Euclidean distance and cosine similarity produce the same ranking — the metrics become equivalent. This lets you use the faster metric depending on your vector database's optimizations.
Clustering — K-Means and other centroid-based algorithms minimize Euclidean distance. Works well for partitioning embeddings into topic clusters.
Magnitude-meaningful embeddings — Some embedding schemes encode intensity or confidence in the vector magnitude. Euclidean distance preserves this signal; cosine similarity ignores it.
Post-normalization — After L2 normalization, Euclidean distance gives the same ranking as cosine similarity and may be faster for specific database implementations.
Ask the AI assistant about Euclidean distance, L2 normalization, or when to choose it over cosine similarity.