Why is cosine similarity preferred over Euclidean distance for text embeddings?
Text embedding norms vary with content length and density, so cosine measures direction (semantic meaning) while ignoring magnitude. Euclidean distance would conflate length with semantic difference.
Imagine arrows on a giant map, all starting from the centre and pointing outward. Each arrow stands for a sentence. We want to measure how alike two sentences are. One way: ask if the arrows point in the same direction, no matter how long they are. Another way: ask how close the tips of the arrows are. The first way only cares about direction. The second cares about direction and length together. For sentences, the direction is what carries meaning. The length usually just reflects boring things like how many words were in the sentence. If we measured by tip position, two paragraphs about the same topic but with different lengths would look unrelated. By only looking at direction, they line up the way a person would expect: same idea, same heading on the map.
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.
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.
The cosine versus Euclidean question is one of the first design decisions in any vector retrieval system, and it is one where the technically correct answer is more nuanced than the textbook answer suggests. The textbook says cosine, because text embeddings have varying magnitudes. The production reality is that most modern embedding APIs return unit-norm vectors anyway, which makes the two metrics rank-equivalent.
What matters is understanding the underlying reason cosine became the convention, so that you can recognise the cases where the convention does not apply and the cases where it does.
Direction versus magnitude
Every vector in embedding space has two pieces of information: which way it points and how long it is. Cosine similarity uses only the first piece, by dividing the dot product by both norms:
Euclidean distance uses both pieces, because subtracting two vectors and taking the norm of the difference depends on both their directions and their lengths. Two vectors pointing the same way will still have a nonzero Euclidean distance if one is twice as long as the other.
For text, only the direction carries the meaning the embedding model learned. Lengths reflect mechanical properties of the input and the pooling step, not semantic content. So using a metric that listens to direction and ignores magnitude is the natural choice.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- OpenAI's `text-embedding-3-large` returns unit-normalised vectors, so dot-product equals cosine and either is the natural index metric.
- Voyage AI's `voyage-3` and Cohere's `embed-english-v3` both follow the same unit-norm convention for the same reason.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does the contrastive training objective most modern embedding models use favour cosine at inference?
Look at the InfoNCE loss used in models like SimCSE and E5. The loss operates on normalised dot products, which is cosine similarity. The model literally learns to push positives close in angle and negatives apart in angle, so the inference metric should match the training metric.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Assuming cosine and Euclidean rank results identically. They agree only when all vectors are normalised to unit length. Modern embedding APIs often already L2-normalise, hiding the distinction in practice.
60 second bullets to scan on the way to the call.
State that cosine measures direction and Euclidean measures absolute position.
Explain why direction carries semantic content while magnitude does not.
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.