Calculate the Euclidean distance between two vectors in n-dimensional space.
Euclidean distance is the straight-line distance between two points in n-dimensional space, computed as the square root of the sum of squared differences across each dimension. It is the most common distance metric used in k-nearest neighbors, clustering algorithms, and vector similarity searches.
Euclidean Distance
d(a, b) = sqrt(sum((a_i - b_i)^2))
Use Euclidean distance when the magnitude of vectors matters (e.g., physical distance, raw feature values). Use cosine similarity when only the direction matters (e.g., text embeddings, TF-IDF vectors).
In very high dimensions, distances between points tend to converge (curse of dimensionality), making Euclidean distance less discriminative. Dimensionality reduction or alternative metrics may help.