RAG

Cosine similarity

Cosine similarity measures the angle between two vectors.

originABIt compares the angle between vectors, not their length.
Cosine similarity measures the angle between two vectors. Values shown in the worked visual are illustrative unless the labels state otherwise.

How it works

It compares direction while ignoring overall magnitude. For normalized embeddings, cosine similarity equals their dot product.

A concrete example

Illustrative: vectors [1, 0] and [0.8, 0.6] have cosine similarity 0.8.

Do not confuse it with Euclidean distance

cosine compares direction; Euclidean distance measures straight-line separation.

Study the full lesson