Distance is a modelling decision, not a fact. KNN, K-Means and vector search all inherit whichever ruler you hand them.
Euclidean cares about magnitude; cosine only about direction — which is why text embeddings (long vs short documents) almost always use cosine.
Unscaled features rig the vote: a column measured in grams out-shouts one in kilograms. Standardise before any distance-based model.
In high dimensions all points drift equally far apart (curse of dimensionality); distances lose contrast and neighbourhoods lose meaning.
In the Test Kitchen: park A and B on the same ray from the origin — Euclidean stays large while cosine hits 1.000.
Don't just read the recipe — taste it. Drag, click and break things below.
Two dishes, A and B, plotted by chilli and sweetness. Click to move whichever is nearer your cursor. Euclidean (purple) is the straight walk between them; Manhattan (amber) walks the counter-tops; cosine(teal arc) asks only "do they point the same way from bland (0,0)?" — double a recipe and cosine doesn't move. That choice changes who your neighbours are.
FIG L.10: DISTANCE METRICS — SAME TWO DISHES, THREE DIFFERENT ANSWERS. KNN & K-MEANS INHERIT THIS CHOICE
import numpy as np
a, b = np.array([2.5, 6.5]), np.array([7.0, 3.5])
eucl = np.linalg.norm(a - b) # 5.41 straight line
manh = np.abs(a - b).sum() # 7.50 city blocks
cos = a @ b / (np.linalg.norm(a)*np.linalg.norm(b))
print(eucl, manh, round(cos, 3)) # cosine: direction only
print(np.allclose(cos, (2*a) @ b / # scale a ×2 →
(np.linalg.norm(2*a)*np.linalg.norm(b)))) # True: cosine unchanged