Cosine Similarity Calculator
Calculate the cosine similarity between two vectors, commonly used to compare embeddings.
Inputs
Comma-separated numbers, e.g. 1, 2, 3, 4
Comma-separated numbers, must be the same length as Vector A.
Cosine Similarity
0.9938
Cosine Distance
0.0062
Angle Between Vectors
6.38°
Dot Product
40.0000
Step by step
Dot product: A · B = Σ(A_i × B_i)
[1, 2, 3, 4] · [2, 3, 4, 5]
= 40.0000
Magnitudes: ||A|| and ||B||
||A|| = 5.4772, ||B|| = 7.3485
= 5.4772, 7.3485
Cosine similarity: (A · B) / (||A|| × ||B||)
40.0000 ÷ (5.4772 × 7.3485)
= 0.9938
How it works
Cosine similarity measures the cosine of the angle between two vectors: cos(θ) = (A·B) / (‖A‖ × ‖B‖). It ranges from -1 (opposite direction) to 1 (identical direction), with 0 meaning orthogonal (unrelated). Unlike Euclidean distance, cosine similarity ignores vector magnitude and focuses purely on direction, which is why it's the standard metric for comparing text and image embeddings in semantic search, RAG retrieval, and recommendation systems — where the direction of an embedding vector encodes meaning more reliably than its length.
Formula
cosine_similarity = dot(A, B) / (norm(A) * norm(B))
- A, B
- Input vectors
- A \cdot B
- Dot product of A and B
- \|A\|
- Euclidean norm (magnitude) of A
- \|B\|
- Euclidean norm (magnitude) of B
Frequently Asked Questions
What does a cosine similarity of 1 mean?
A similarity of 1 means the two vectors point in exactly the same direction, indicating maximum similarity (e.g. semantically identical embeddings).
Why use cosine similarity instead of Euclidean distance for embeddings?
Embedding magnitude often reflects factors like text length rather than meaning, so cosine similarity — which normalizes by magnitude — better captures semantic similarity independent of vector length.
Can cosine similarity be negative?
Yes, it ranges from -1 to 1. Negative values indicate the vectors point in substantially opposite directions, which is uncommon for typical embedding models but possible mathematically.
What's the difference between cosine similarity and cosine distance?
Cosine distance is simply 1 minus cosine similarity, converting a similarity score (higher is more similar) into a distance metric (lower is more similar), which is convenient for nearest-neighbor search algorithms.