cosine similarity calculator

Cosine Similarity Tool

Enter two vectors with values separated by commas, spaces, or new lines.

What Is Cosine Similarity?

Cosine similarity is a mathematical measure that tells you how similar two vectors are by looking at the angle between them. Instead of focusing on raw magnitude, it focuses on direction. That makes it extremely useful when comparing text documents, embeddings, recommendation profiles, and other high-dimensional data.

The score typically ranges from -1 to 1:

  • 1 means vectors point in exactly the same direction.
  • 0 means vectors are orthogonal (no directional similarity).
  • -1 means vectors point in opposite directions.

Formula

The cosine similarity between vectors A and B is:

cos(θ) = (A · B) / (||A|| × ||B||)

Where:

  • A · B is the dot product.
  • ||A|| and ||B|| are vector magnitudes (Euclidean norms).

How to Use This Calculator

  1. Enter numeric values for Vector A.
  2. Enter the same number of values for Vector B.
  3. Click Calculate Similarity.
  4. Read the score, interpretation, and breakdown details.

Tip: You can paste vectors in formats like [1, 2, 3], 1 2 3, or line-by-line values.

How to Interpret the Result

High Positive Similarity (close to 1)

The vectors share nearly the same direction. In machine learning and natural language processing, this often implies very similar items.

Around Zero

The vectors do not align meaningfully. They can still be large in magnitude, but their directions are different.

Negative Similarity

The vectors point in opposing directions. Depending on context, that can indicate contradiction, opposite preferences, or anti-correlation.

Worked Example

Suppose:

  • A = [1, 2, 3]
  • B = [2, 4, 6]

Here, B is just a scaled version of A. Their angle is 0°, so cosine similarity is 1. This is a classic example showing why cosine similarity is scale-insensitive: multiplying a vector by a positive constant does not change its direction.

Real-World Applications

Text Similarity and Search

Documents can be represented by TF-IDF vectors or embedding vectors. Cosine similarity helps rank results by semantic closeness.

Recommendation Systems

User profiles and product vectors can be compared to suggest relevant movies, songs, or products.

Machine Learning Feature Comparison

In clustering, nearest-neighbor search, and anomaly detection, cosine similarity is often preferred when direction matters more than absolute scale.

Semantic Embeddings

Modern AI systems compare sentence embeddings, image embeddings, or multimodal vectors using cosine similarity as a standard similarity measure.

Common Mistakes to Avoid

  • Different vector lengths: both vectors must have the same number of dimensions.
  • Zero vectors: if magnitude is zero, cosine similarity is undefined.
  • Assuming it measures distance: cosine similarity is a directional score, not a physical distance metric.
  • Ignoring preprocessing: in NLP tasks, tokenization and normalization heavily affect vector quality.

Cosine Similarity vs Euclidean Distance

Euclidean distance measures how far apart two points are in space. Cosine similarity measures how aligned they are. If your use case cares about direction (common in text analysis and embeddings), cosine similarity is usually the better choice.

Frequently Asked Questions

Can cosine similarity be greater than 1?

No. Numerical precision may show tiny floating-point artifacts, but mathematically the score is bounded by -1 and 1.

Why do I get an error with all zeros?

A zero vector has magnitude 0, and division by zero is undefined in the cosine formula.

Is cosine similarity good for sparse vectors?

Yes. It is widely used with sparse high-dimensional vectors, such as bag-of-words and TF-IDF representations.

Final Thoughts

Cosine similarity is one of the most practical and widely used vector similarity techniques in data science, search, and AI. Use the calculator above to quickly validate your vectors, inspect the dot product and norms, and better understand how similar two vectors really are.

🔗 Related Calculators