Math
Cosine Similarity Calculator
Paste two vectors as comma-separated lists (2D, 3D, or hundreds of components) and mathcheck computes cos θ = (A · B) / (|A| |B|) with the dot product and magnitudes shown, gives an exact form like 4√10/15 when the components are integers, converts the result to the angle between the vectors, and reports the cosine distance 1 - cos θ used in text and embedding comparisons.
Components separated by commas or spaces. Any length.
Same number of components as A.
Try an example
Result
Cosine similarity
—
- Angle between the vectors
- —
- Dot product A · B
- —
- |A|
- —
- |B|
- —
- Cosine distance (1 - cos θ)
- —
- Reading
- —
Student quick launch
Grade planning, algebra checks, and formulas students reach for most.
Study path
Use this calculator with
Follow these when you want the formula behind the answer, a short lesson, or nearby tools in the same topic.
What cosine similarity measures
Cosine similarity compares the directions of two A quantity with both a size and a direction, often drawn as an arrow. while ignoring their lengths. It is the cosine of the angle between them: 1 when they point the same way, 0 when they are perpendicular, and -1 when they point in opposite directions. Because it discards The length or size of a vector, ignoring which way it points., it is the standard way to compare word counts, ratings, and embedding vectors where scale is irrelevant.
| cos θ | Angle | Meaning |
|---|---|---|
| 1 | 0° | same direction |
| 0.7 to 1 | 0° to 45° | strongly similar |
| 0 | 90° | orthogonal, no shared direction |
| -1 | 180° | opposite direction |
⟨1, 2, 3⟩ and ⟨4, 5, 6⟩
A · B = 4 + 10 + 18 = 32. |A| = √14, |B| = √77. cos θ = 32 / (√14 · √77) = 32 / √1078 = 32/(7√22) = 32√22/154 = 16√22/77 ≈ 0.9746, so θ ≈ 12.93°.
How to use this calculator
- Type vector A as a comma-separated list of numbers.
- Type vector B with the same number of components.
- Read the cosine similarity, then the angle, Multiply two vectors piece by piece and add the results to get one number., magnitudes, and cosine distance.
- Use the reading line for a quick verbal interpretation, and Show the work for the full computation.
How to read the answer
Values near 1 mean the vectors point almost the same way, regardless of how long they are. A value of 0 means they are perpendicular and share no direction. Negative values mean they lean opposite ways. The angle is the same information in degrees; the cosine distance flips the scale so that 0 means identical, which some libraries prefer. The result is undefined for a zero vector.
Common mistakes and edge cases
- Dividing by |A| + |B| or by |A|^2 |B|^2 instead of the product of the magnitudes.
- Forgetting the square root when computing a magnitude.
- Comparing vectors of different lengths; pad or align them first.
- Reading cosine similarity as a correlation. It is not centered: subtract each vector's mean first if you want the Pearson correlation.
- Passing a zero vector, which has no direction and makes the formula divide by 0.
Worked examples
Textbook vectors
⟨1, 2, 3⟩ and ⟨4, 5, 6⟩
Cosine similarity
16√22/77 (0.9746)
Perpendicular vectors
⟨1, 0⟩ and ⟨0, 1⟩
Cosine similarity
0
Opposite directions
⟨2, 2⟩ and ⟨-1, -1⟩
Cosine similarity
-1
Same direction, different length
⟨3, 4⟩ and ⟨6, 8⟩
Cosine similarity
1
Word-count vectors (5D)
⟨2, 0, 1, 1, 0⟩ and ⟨1, 1, 0, 1, 1⟩
Cosine similarity
√6/4 (0.6124)
Decimal embeddings
⟨0.2, -0.4, 0.9⟩ and ⟨0.1, -0.5, 0.8⟩
Cosine similarity
0.98593
Zero vector
Cosine similarity
—
Different lengths
Cosine similarity
—
Frequently asked questions
What is the cosine similarity formula?+
cos θ = (A · B) / (|A| |B|): the dot product of the two vectors divided by the product of their lengths. It equals the cosine of the angle between them.
What range can cosine similarity take?+
From -1 (opposite) through 0 (perpendicular) to 1 (same direction). If every component is non-negative, as with counts, the value is between 0 and 1.
How is cosine distance different?+
Cosine distance is 1 - cosine similarity, so 0 means identical direction and 2 means opposite. It is a convenience for algorithms that expect smaller numbers to mean 'closer'.
Why does cosine similarity ignore vector length?+
Dividing by both magnitudes normalizes each vector to length 1 before taking the dot product. Doubling every component of a vector leaves its direction, and therefore its similarity, unchanged.
Is cosine similarity the same as correlation?+
Not quite. The Pearson correlation is the cosine similarity of the mean-centered vectors. For vectors that already have mean 0 the two coincide.
How do I get the angle between the vectors?+
Take the inverse cosine of the similarity. The calculator reports it in degrees and radians, with exact π fractions for angles like 60° or 90°.
About this calculator
- Written by
- mathcheck editorial team
- Last reviewed
- September 4, 2026
Method
- Uses the values entered by the user and stable formulas documented on the page.
Related calculators
Dot Product Calculator
Compute the dot product of two 2D or 3D vectors with the angle between them, both magnitudes, the scalar projection, and an orthogonality check, with every multiplication shown.
Angle Between Two Vectors Calculator
Find the angle between two 2D or 3D vectors in degrees and radians using the dot product, with the exact cosine, magnitudes, and an acute/obtuse/perpendicular classification.
Vector Magnitude and Direction Calculator
Find the magnitude (length) and direction angle of a 2D or 3D vector from its components or from two points. Exact radical magnitude, unit vector, direction cosines, and an arrow diagram.
Unit Vector Calculator
Normalize a 2D or 3D vector to a unit vector with exact rationalized radical components and decimals, plus the magnitude, direction angle, and the opposite unit vector.
Manhattan Distance Calculator
Compute the Manhattan (taxicab, L1) distance between two points in 2D, 3D, or any number of dimensions, alongside the Euclidean and Chebyshev distances for comparison, with every coordinate difference shown.
Correlation Coefficient Calculator
Calculate Pearson correlation coefficient r from paired x and y data.
Last updated: September 4, 2026