GEOMETRYCoordinate GeometryMathematics Calculator

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.

Concept Fundamentals
cos θ = A·B/(|A||B|)
Formula
[-1, 1]
Range
cos θ = 1
Same dir
cos θ = 0
Orthogonal

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.

Key quantities
cos θ = A·B/(|A||B|)
Formula
Key relation
[-1, 1]
Range
Key relation
cos θ = 1
Same dir
Key relation
cos θ = 0
Orthogonal
Key relation

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.

1 = identical direction; -1 = opposite; 0 = perpendicular.Used in word embeddings (Word2Vec, GloVe) and document similarity.

Run the calculator when you are ready.

Cosine SimilarityEnter two vectors to get similarity and angle

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

1

cos θ = 1 when vectors point same direction.

— Property

Key Takeaways

  • • Cosine similarity cosθ=ABAB\cos\theta = \frac{\vec{A}\cdot\vec{B}}{|\vec{A}||\vec{B}|} 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?

Text Analysis

Document similarity in vector space models uses cosine similarity between word vectors.

Recommendations

Finding similar users or items often uses cosine similarity.

Image Recognition

Feature vectors are compared using cosine similarity.

Information Retrieval

Search engines rank results by cosine similarity to the query.

Clustering

K-means and other algorithms use distance metrics derived from cosine.

Embeddings

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.

cosθ=ABAB\cos\theta = \frac{\vec{A} \cdot \vec{B}}{|\vec{A}||\vec{B}|}

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

  1. Set the number of dimensions (2–10).
  2. Enter components for vectors A and B.
  3. Click "Calculate" to get cosine similarity and angle.

Disclaimer: Cosine similarity is undefined for zero vectors. For applications where magnitude matters, consider Euclidean distance.

👈 START HERE
⬅️Jump in and explore the concept!
AI

Related Calculators