Start studying
Module 8 · Embeddings & Search Module contents
Module 8  ·  Card 3 / 17beginner

Cosine Similarity in Search

Cosine similarity scores two vectors by the angle between them.

It runs from -1 for opposite to 1 for identical direction.

Length is ignored, so a long document is not penalised against a short query.

If vectors are normalised, cosine similarity and dot product are equivalent.

It is the default scoring function in essentially every vector database.

Learn in depth ↓
Module 08 · Embeddings & Search · 17 concepts
In depth  /  15 lines

Cosine Similarity in Search, in more detail

Cosine similarity is the scoring function underneath essentially every vector search.

It measures the angle between the query vector and each document vector.

Identical direction scores one, unrelated scores near zero, opposite scores minus one.

With real text embeddings most scores land between about 0.3 and 0.9.

Length is ignored entirely, which is exactly what you want here.

A query is a few words and a document is a few hundred, so their vector lengths differ.

Euclidean distance would treat that difference as a difference in meaning.

Cosine looks only at direction and compares them fairly.

If vectors are normalised to length one, cosine and dot product give the same ranking.

Most embedding APIs normalise for you, so engines use the dot product for speed.

The absolute number means little, since 0.82 is not good or bad on its own.

What matters is the ranking and the gap between the top results.

Thresholds must be tuned per model and per corpus, never copied from a tutorial.

It is a similarity of wording and meaning, not of correctness.

A sentence and its negation sit very close, which is why retrieval can confidently return the opposite of the truth.

Want the full technical article? Wikipedia ↗
Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
What is the benefit of cosine similarity ignoring vector length?
Embeddings & Search

17 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close