Back

Metric Playground

Drag the query point and switch metrics to see how the nearest neighbors change.

Top-5 Nearest Neighbors(lower = closer)

#1P1842.1
#2P1074.0
#3P17111.6
#4P14122.8
#5P13126.9
Metric
L2
Shows
Euclidean dist

L2 (Euclidean Distance)

Measures the straight-line distance between two points. The concentric circles show equidistant zones — all points on the same circle are equally "far" from the query.

What is a metric?

A metric is just a function that takes two vectors and returns a single number telling you how similar (or different) they are. Vector search is, at its core, "find the K vectors with the best metric score against my query." Everything else — indexes, clusters, graphs — is just bookkeeping to avoid computing this score against every vector in the database.

The metric you choose defines what "similar" means for your data. Two embeddings can be "near" under one metric and "far" under another — same data, different answer. That's why this choice happens before you ever build an index.

The three you'll see in practice

  • L2 (Euclidean): straight-line distance. Lower is better. Use when both direction and magnitude matter — image embeddings, geographic coordinates, raw sensor readings. The default for most CV models.
  • Cosine: angle between vectors, ignoring length. Higher is better. Use when only direction matters — text embeddings (BERT, OpenAI, etc.), recommendation systems where vector "popularity" shouldn't dominate.
  • Inner Product (IP): dot product, rewards both alignment AND magnitude. Higher is better. Use with models that explicitly normalize for IP (DPR, many retrieval models). Mathematically identical to Cosine when vectors are unit-length.

Two practical rules

  • Match the metric to the model. Embedding models are trained with a specific metric in mind. Using a different one at search time will silently wreck your recall. Check the model card before picking.
  • Stay consistent. All vectors in a collection must use the same metric. You cannot mix them within a single index, and you cannot meaningfully compare scores across different metrics.

Try this: drag the query point near the origin and switch between Cosine and L2. Watch how Cosine cares only about which "direction" the query is pointing — points on the opposite side of the origin can be "close" under L2 but "far" under Cosine. That visual is the entire concept.