Zenaique

Match each similarity metric to its formal definition

Match pairs·Medium·4.0 · 0·~2 min·Asked atEyNotionWandb
Attempt it

Drag each answer to line up with its matching prompt

Cosine similarity

u · v = sum of u_i × v_i; on unit norm vectors equals cosine

Dot product (inner product)

Number of bit positions where two binary vectors differ; used for binary quantized embeddings

Euclidean (L2) distance

(u · v) / (||u|| × ||v||); measures angle between vectors, ignores magnitude

Hamming distance

||u - v|| = sqrt of sum of squared differences; on unit norm vectors monotone equivalent to cosine

TL;DR

Cosine measures angle, dot product is the unnormalized inner product, Euclidean measures straight-line distance, Hamming counts bit differences for binary vectors.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine four ways to ask 'how alike are these two things'. One asks 'do they point in the same direction' (cosine). One adds up how much they agree position by position (dot product). One asks 'how far apart are they' (Euclidean). And one asks, for two strings of light switches, 'how many switches differ' (Hamming). Each is useful in a different setting, and a couple of them turn into the same answer when you do a little preprocessing.

Key concepts

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

Similarity metrics are the boring middle of every embedding system: necessary, easy to confuse, and unforgiving when chosen wrong. Four metrics dominate 2026 production: cosine, dot product, Euclidean, and Hamming. Three are for real-valued vectors and one is for binary. The four are not orthogonal options. They collapse to two under common preconditions, and most retrieval stacks end up using one of two configurations.

This deep dive defines each metric formally, walks through the algebraic identities that link them, and ends with the practical question of which metric to choose given the precision tier of your vectors.

The four definitions

Cosine similarity

cos(u,v)=uvu2v2\cos(u, v) = \frac{u \cdot v}{\|u\|_2 \, \|v\|_2}

Range: [-1, 1]. Scale-invariant: cos(u, v) = cos(αu, βv) for any positive α, β. Measures the angle between the two vectors.

Dot product (inner product)

uv=i=1duiviu \cdot v = \sum_{i=1}^{d} u_i v_i

Range: unbounded for general real vectors; [-1, 1] when both vectors are unit norm. Not scale-invariant. On unit-norm vectors it equals cosine.

Euclidean (L2) distance

uv2=i=1d(uivi)2\|u - v\|_2 = \sqrt{\sum_{i=1}^{d} (u_i - v_i)^2}

Range: [0, ∞) in general; [0, 2] on unit-norm vectors. Measures the straight-line distance between vector tips.

Hamming distance

For binary vectors u, v ∈ {0, 1}^d:

dH(u,v)=i=1d1[uivi]d_H(u, v) = \sum_{i=1}^{d} \mathbb{1}[u_i \neq v_i]

Range: [0, d]. The integer count of bit positions where the two vectors differ.

The algebraic relationships
Production trade-offs
Picking the metric in practice
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • Pinecone supports cosine, dot, and Euclidean metric types per index, defaulting to cosine.
  • FAISS provides IndexBinaryFlat that uses Hamming distance for binary embeddings.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QHow would you compute Hamming distance efficiently on packed binary vectors?
A

Pack 64 bits per uint64, compute XOR, then call the CPU popcount instruction. On AVX-512, an entire 512-bit register can be popcounted in a few cycles.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Treating dot product and cosine as different metrics on production embeddings. On normalized vectors they are identical and dot product is faster.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Formula for each of the four metrics

  • Which metrics are scale-invariant and which are not

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Why is cosine similarity preferred over Euclidean distance for text embeddings?
Flashcard·Easy