Cosine Similarity

Cosine similarity measures how similar two vectors are by comparing their direction rather than their magnitude.

Intuition

Two embeddings can point in the same semantic direction even if one has a larger length.

Technical definition

Cosine similarity is the dot product of two vectors divided by the product of their Euclidean norms.

Example

Semantic search often ranks documents by cosine similarity between query and document embeddings.

Common misunderstandings

  • Cosine similarity ignores vector length after normalization.
  • High cosine similarity does not guarantee factual relevance.

Need this inside a product?

The studio builds the systems these terms describe. Tell us what you are working on.