Module 3: Similarity and Distance
2. Euclidean Distance: The Straight Line
Overview
Euclidean distance is the "straight line" distance between two points. It's the most intuitive metric: if you have two points on a map, the Euclidean distance is the length of the straight line connecting them.
Formula
In 2D:
distance([x₁, y₁], [x₂, y₂]) = √((x₂ - x₁)² + (y₂ - y₁)²)
In 3D:
distance([x₁, y₁, z₁], [x₂, y₂, z₂]) = √((x₂ - x₁)² + (y₂ - y₁)² + (z₂ - z₁)²)
In ND (the generalization):
distance(A, B) = √(∑(bᵢ - aᵢ)²)
Examples
Example 1 (2D):
A = [3, 2]
B = [6, 6]
distance = √((6-3)² + (6-2)²)
= √(9 + 16)
= √25 = 5
Example 2 (3D):
A = [1, 2, 3]
B = [4, 6, 8]
distance = √((4-1)² + (6-2)² + (8-3)²)
= √(9 + 16 + 25)
= √50 ≈ 7.07
Example 3 (1536D - conceptual):
A = [a₁, a₂, ..., a₁₅₃₆]
B = [b₁, b₂, ..., b₁₅₃₆]
distance = √((b₁-a₁)² + (b₂-a₂)² + ... + (b₁₅₃₆-a₁₅₃₆)²)
Advantages and disadvantages
Advantages:
- ✅ Intuitive (a straight line)
- ✅ It preserves geometric properties
- ✅ Useful when magnitude matters
Disadvantages:
- ❌ In high dimensions, all the distances are similar
- ❌ Sensitive to magnitude (large vectors → large distances)
- ❌ Not optimal for embeddings
Next capsule: 03-manhattan-distance.md — A path along a grid.