Kolkata ·  
AI engineering
retrieval
short · 3 min

Cosine similarity

How alike two embeddings are, measured by the angle between them and ignoring their length.

updated 27 Sept 2026

You run a search over your documents and the top hit comes back with a score of 0.6. Is that good? Is it "60% similar"?

Not really. To see why, we need to know what the number is. Cosine similarity is the usual way to say how alike two embeddings are, and it's simpler than it sounds.

Arrows

An embedding is a list of numbers. A list of numbers is a point in space, and if we draw an arrow from the origin to that point, we get something with a direction and a length. Real embeddings have hundreds or thousands of numbers, but let's use two so we can picture them:

VectorNumbersLength
a(3, 4)5
b(6, 8)10
c(4, −3)5
d(−3, −4)5

b points exactly the same way as a, just twice as long. c is turned a quarter circle away. d points the opposite way.

Cosine similarity only asks how far apart the directions are. Same direction scores 1, a right angle scores 0, opposite scores −1. Length is ignored completely, so a and b score a perfect 1 even though one is twice the other.

Getting the angle from the numbers

We don't need a protractor. Start with the dot product: multiply the two lists position by position and add it up. For a and c that's 3×4 + 4×(−3) = 0.

The dot product grows as the arrows line up, but it also grows as they get longer. a with b gives 50, while a with itself gives only 25. So to cancel out length, we divide by both lengths:

cos⁡(a,b)=a⋅b∥a∥ ∥b∥\cos(a, b) = \frac{a \cdot b}{\lVert a \rVert \, \lVert b \rVert}

a and b: 50 ÷ (5 × 10) = 1. Try something slightly off from a, like (4, 3): the dot product is 24, divided by 5 × 5, gives 0.96. Nearly lined up, nearly 1. With a thousand numbers instead of two it's the same work, just longer.

Now a shortcut. If we divide a vector by its own length, we get a vector of length 1 pointing the same way (that's normalizing). When both vectors already have length 1, the division is by 1 × 1, so cosine similarity is just the dot product. OpenAI's embeddings come back normalized like that. So you can skip the division, and plain straight-line distance between the points ranks results in exactly the same order. The choice of distance stops mattering. One catch: if you shorten vectors yourself by keeping the first N numbers, they aren't length 1 anymore, so normalize them again.

Back to that 0.6

So what was the 0.6? It's the cosine of an angle, somewhere between −1 and

  1. What counts as high depends entirely on the model. One model's 0.6 can be a great match and another's a weak one (you'll see real scores from a small model in semantic search). So don't copy a cutoff from someone else; look at scores from your own model on your own data. And a cosine between vectors from two different models means nothing, since each model puts text in its own space.

There's a deeper doubt, too. Cosine throws away length, and length can carry information. Researchers at Netflix showed mathematically that for some learned embeddings the cosine score can come out arbitrary, shaped by how the model was trained, and for some models not even unique. Their work was on recommendation models, not text embedding APIs, and in practice a plain dot product sometimes does better and sometimes worse. So the 0.6 is a good way to rank results against each other. It isn't a measurement of meaning.

Further reading