Cosine similarity

Also: cosine distance

The cosine of the angle between two vectors: their dot product divided by the product of their lengths. It is the standard similarity measure for embeddings; cosine distance is 1 minus it.

cos θ = (a · b) / (‖a‖ ‖b‖)

Cosine similarity is the cosine of the angle between two vectors

Example

a = (1, 1) and b = (1, 0) are 45° apart: cos θ = 1 / (√2 · 1) ≈ 0.707. (2, 2) and (1, 1) score exactly 1, because length does not matter.

See it in the lesson: RAG Architecture →

Related terms

More in Linear Algebra & Calculus