Cosine Similarity Calculator
Calculate the cosine similarity between two vectors instantly
Cosine Similarity Calculator
Cosine similarity measures the angle between two vectors in multi-dimensional space, returning a value between -1 and 1. A value of 1 means the vectors point in exactly the same direction, 0 means they are orthogonal (no similarity), and -1 means they point in opposite directions. It is one of the most commonly used similarity metrics in machine learning, NLP, and information retrieval because it is invariant to vector magnitude — only direction matters.
How to Use This Calculator
- Enter Vector A — comma-separated or space-separated numbers representing the first vector.
- Enter Vector B — the second vector. It must have the same number of dimensions as Vector A.
- The calculator instantly shows the cosine similarity, dot product, magnitudes, and the angle in degrees and radians.
Cosine Similarity Formula
For two vectors A and B:
cos(θ) = (A · B) / (|A| × |B|)
Where A · B is the dot product (sum of element-wise products) and |A|, |B| are the Euclidean magnitudes (L2 norms).
Common Interpretation Ranges
- 0.9 to 1.0: Very high similarity — vectors are nearly co-directional.
- 0.7 to 0.9: High similarity — commonly interpreted as semantically related in NLP tasks.
- 0.5 to 0.7: Moderate similarity.
- 0 to 0.5: Low similarity.
- 0: Orthogonal — completely unrelated directions.
- Negative: Vectors are more opposite than similar.
Real-World Applications
Word embeddings: Word2Vec and GloVe represent words as dense vectors. The cosine similarity between "king" and "queen" is high because they appear in similar contexts.
Document similarity: Two TF-IDF vectors can be compared with cosine similarity to find the most relevant documents for a search query.
Recommendation systems: User preference vectors are compared using cosine similarity to find users with similar taste.
Image retrieval: CNN feature embeddings are compared using cosine similarity to find visually similar images.
Cosine Similarity vs. Euclidean Distance
Euclidean distance is sensitive to vector magnitude — a short vector and a long vector pointing in the same direction have a large Euclidean distance. Cosine similarity ignores magnitude and only measures angular distance. This makes it ideal for text analysis where document length should not affect similarity scores.