Cosine Similarity
Cosine similarity = cos θ = (A·B)/(|A||B|), the cosine of the angle between vectors. Range [-1,1]: 1 = same direction, 0 = orthogonal, -1 = opposite. Used in NLP and ML.
Did our AI summary help? Let us know.
1 = identical direction; -1 = opposite; 0 = perpendicular. Used in word embeddings (Word2Vec, GloVe) and document similarity. Euclidean distance and cosine similarity are related for normalized vectors.
Ready to run the numbers?
Why: Cosine similarity measures orientation, not magnitude. Essential in text embeddings (NLP), recommendation systems, and clustering. Ignores vector length—focuses on direction.
How: cos θ = (A·B)/(|A||B|). Dot product divided by product of magnitudes. θ = arccos(similarity). Undefined for zero vectors.
Run the calculator when you are ready.
Vector Inputs
Vector A
Vector B
For educational and informational purposes only. Verify with a qualified professional.
🧮 Fascinating Math Facts
cos θ = A·B/(|A||B|) — angle between vectors.
— Linear Algebra
cos θ = 1 when vectors point same direction.
— Property
Key Takeaways
- • Cosine similarity measures direction, not magnitude.
- • Range: -1 (opposite) to 1 (same direction). Zero means orthogonal.
- • Used in NLP, recommendation systems, and clustering.
- • For normalized vectors, cosine similarity equals the dot product.
- • Undefined for zero vectors.
Did You Know?
Document similarity in vector space models uses cosine similarity between word vectors.
Finding similar users or items often uses cosine similarity.
Feature vectors are compared using cosine similarity.
Search engines rank results by cosine similarity to the query.
K-means and other algorithms use distance metrics derived from cosine.
Word2Vec and other embeddings are often compared via cosine similarity.
Understanding Cosine Similarity
Cosine similarity is the cosine of the angle between two vectors. It measures how similar their directions are, regardless of length.
Expert Tips
Interpretation
1 = same direction, 0 = perpendicular, -1 = opposite. Values in between indicate partial alignment.
Zero Vectors
Cosine similarity is undefined when either vector has zero magnitude.
Normalization
For unit vectors, cosine similarity equals the dot product.
Cosine Distance
Cosine distance = 1 - cosine similarity. Range [0, 2].
Frequently Asked Questions
What is cosine similarity?
The cosine of the angle between two vectors. It measures direction similarity, not magnitude.
What does 1 mean?
Vectors point in the same direction (0° angle).
What does 0 mean?
Vectors are perpendicular (orthogonal), 90° angle.
What does -1 mean?
Vectors point in opposite directions, 180° angle.
Why use cosine over Euclidean?
When magnitude does not matter (e.g., document length in text), cosine focuses on direction.
When is it undefined?
When either vector has zero magnitude (all components zero).
What is cosine distance?
1 - cosine similarity. Transforms to a distance metric in [0, 2].
How to Use This Calculator
- Set the number of dimensions (2–10).
- Enter components for vectors A and B.
- Click "Calculate" to get cosine similarity and angle.
Disclaimer: Cosine similarity is undefined for zero vectors. For applications where magnitude matters, consider Euclidean distance.
Related Calculators
Centroid Calculator
Centroid Calculator - Calculate and learn about coordinate-geometry concepts
MathematicsEndpoint Calculator
Endpoint Calculator - Calculate and learn about coordinate-geometry concepts
MathematicsGradient Calculator
Gradient Calculator - Calculate and learn about coordinate-geometry concepts
MathematicsRotation Calculator
Rotation Calculator - Calculate and learn about coordinate-geometry concepts
MathematicsVector Calculator
Vector Calculator - Calculate and learn about coordinate-geometry concepts
MathematicsY Intercept Calculator
Y Intercept Calculator - Calculate and learn about coordinate-geometry concepts
Mathematics