Machine Learning & AI
Basic

Cosine Similarity

Measures the angle between two vectors; 1 means identical direction.

Formula

cosθ=abab\cos\theta = \dfrac{\mathbf{a}\cdot\mathbf{b}}{\lVert\mathbf{a}\rVert\,\lVert\mathbf{b}\rVert}

Variables

\mathbf{a},\mathbf{b}Vectors
\cdotDot product

Example

Identical vectors: cos = 1

Did You Know?

Cosine similarity powers semantic search — comparing text embeddings by direction, not length.

Share this formula