Euclidean Distance

intermediate
Core ConceptsLast updated: 2025-01-15
Also known as: L2 distance

What is Euclidean Distance?


Euclidean distance, also known as L2 distance, measures the straight-line distance between two points (vectors) in a multi-dimensional space. It's calculated as the square root of the sum of squared differences across all dimensions. In the context of embeddings, Euclidean distance quantifies how far apart two vectors are in the embedding space, with smaller distances indicating greater similarity.


The metric is intuitive as it corresponds to the geometric notion of distance we experience in physical space. For embeddings, Euclidean distance considers both the direction and magnitude of vectors, making it sensitive to both semantic differences and the overall scale of the embeddings. This differs from cosine similarity, which focuses purely on directional similarity and is magnitude-independent.


Euclidean distance is supported by most vector databases as an alternative distance metric to cosine similarity. The choice between them affects retrieval behavior: Euclidean distance may be preferred when vector magnitude carries meaningful information, while cosine similarity is often better for normalized embeddings where only directional similarity matters. Some embedding models and applications perform better with one metric over the other, making it a parameter worth experimenting with when optimizing retrieval systems.


Related Terms