Skip to content
Sign in

What is Cosine Similarity?

Cosine similarity measures how similar two vectors are by computing the cosine of the angle between them, ignoring their magnitudes.

It is calculated as the dot product of the two vectors divided by the product of their lengths (magnitudes). The result ranges from -1 to 1, where 1 means identical direction, 0 means no similarity, and -1 means opposite directions.

The key idea is that it focuses purely on orientation rather than vector length, making it robust for high-dimensional or sparse data where absolute sizes vary.

It is commonly applied in data science to compare items like documents or user preferences represented as feature vectors.

Example

Two movie review vectors might share many positive words like 'great' and 'acting'; their cosine similarity of 0.85 shows they point in similar directions even if one review is much longer.

Why it matters

It powers modern search engines, recommendation systems, and clustering algorithms by efficiently finding similar items in large datasets without being skewed by document length.

Frequently asked questions

It means the two vectors point in exactly the same direction and are perfectly aligned.