Distance Metrics Comparison
Understanding when to use each metric for optimal similarity search.
Text/Embeddings
Cosine
Clustering
Euclidean
Sparse Data
Manhattan
Normalized
Dot Product
| Metric | Range | Best For | Considers Magnitude? |
|---|---|---|---|
| Euclidean (L2) | [0, ∞) | General purpose, clustering | Yes |
| Cosine Similarity | [-1, 1] | Text, embeddings, NLP | No |
| Manhattan (L1) | [0, ∞) | High-dimensional, sparse data | Yes |
| Dot Product | (-∞, ∞) | Normalized vectors, recommendations | Yes |
| Chebyshev (L∞) | [0, ∞) | When max deviation matters | Yes |
| Hamming | [0, n] | Binary vectors, hashes | N/A |
Euclidean Distance (L2)
d(A, B) = √(Σ(aᵢ - bᵢ)²)
The "straight line" distance between two points in space. Most intuitive metric.
Use When
- Actual distance matters
- Clustering algorithms (K-means)
- Low to medium dimensions
- Vectors are similarly scaled
Avoid When
- Very high dimensions (curse of dimensionality)
- Only direction matters
- Vectors have different scales
Cosine Similarity
cos(θ) = (A · B) / (|A| × |B|)
Measures the angle between vectors, ignoring their magnitude. Values range from -1 (opposite) to 1 (identical direction).
Use When
- Text similarity / NLP
- Embedding comparisons
- Document similarity
- Recommendation systems
Avoid When
- Magnitude is meaningful
- Physical distance matters
- Zero vectors present
Manhattan Distance (L1)
d(A, B) = Σ|aᵢ - bᵢ|
Sum of absolute differences. Like walking on a grid (city blocks).
Use When
- High-dimensional data
- Sparse vectors
- Robust to outliers needed
- Grid-based movement
Avoid When
- Direct distance is important
- Rotation invariance needed
Dot Product (Inner Product)
A · B = Σ(aᵢ × bᵢ)
Simple sum of element-wise products. Fast to compute, equals cosine similarity for normalized vectors.
Use When
- Vectors are normalized
- Speed is critical
- Recommendation systems
- Neural network outputs
Avoid When
- Vectors are not normalized
- Bounded results needed
Try It Yourself
Compare all distance metrics for any two vectors using our interactive calculator.
Open Distance Calculator →