Match each similarity metric to its formal definition
Cosine measures angle, dot product is the unnormalized inner product, Euclidean measures straight-line distance, Hamming counts bit differences for binary vectors.
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.
Detailed answer & concept explanation~4 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
6-8 min: define each metric + state when cosine equals dot + state when Euclidean and cosine rank identically + Hamming for binary vectors + production usage.
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.
- Qdrant and Weaviate auto-translate cosine to dot product when vectors are normalized.
- Cohere embed v3 binary quantization output is meant to be searched with Hamming, not cosine.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you compute Hamming distance efficiently on packed binary vectors?
QWhen would Manhattan (L1) distance be preferable to Euclidean?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Treating dot product and cosine as different metrics on production embeddings. On normalized vectors they are identical and dot product is faster.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.