Cosine Similarity Calculator
Calculate the cosine similarity between two vectors used in embedding comparisons.
About Cosine Similarity Calculator
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
Worked example
With the default values below, Cosine Similarity Calculator returns Cosine Similarity of 0.9938. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Vector A
- 1, 2, 3, 4
- Vector B
- 2, 3, 4, 5
Results
- Cosine Similarity
- 0.9938
- Cosine Distance
- 0.0062
- Angle Between Vectors
- 6.38 °
- Dot Product
- 40.0000
Step by step
- 1Dot product: A · B = Σ(A_i × B_i)= 40.0000
- 2Magnitudes: ||A|| and ||B||= 5.4772, 7.3485
- 3Cosine similarity: (A · B) / (||A|| × ||B||)= 0.9938
Assumptions and limits
- The result is derived only from the 2 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to 4 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
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.
