Divide the dot product by both norms
Vectors have the same dimension and feature order. The denominator must be positive.[1]
Multiply corresponding coordinates and add those products. Then take the square root of the sum of squares for each vector. Dividing by both norms removes overall length. If both vectors are already L2-normalized, their norms are 1 and the dot product alone suffices. A zero vector has no direction, however, so its quotient is undefined.[1]
The calculator supports two or three real coordinates per vector. The formula applies in any finite dimension. Negative coordinates are explicitly allowed. Document vectors built from TF-IDF have nonnegative weights under the common variants described here, so their dot product cannot be negative. That is a property of those inputs rather than a general lower bound on cosine similarity.[1]
Why direction and scaling are different
Normalization places both endpoints on the unit sphere. Their squared difference connects angular similarity and chord distance.[1]
Because the squared lengths of both u−v and u+v are nonnegative, u·v lies between −1 and +1. Equality at +1 means the same normalized direction, not necessarily identical original coordinates. A positive factor multiplying an entire vector cancels. A negative factor reverses its direction and changes the similarity’s sign.[1]
Equal length is not required
Free with a Quanta account. Your download stays ready after registration.
Rescaling an individual axis is different. Vectors x=(1,1) and y=(1,0) give 1/√2. Scaling the first axis tenfold for both produces (10,1) and (10,0), whose similarity is 10/√101≈0.9950. Changing units on only one feature axis can therefore shift the result. Choose a justified common feature scale first.[1]
Two complete calculations
Two positive two-dimensional vectors
- Given
- x=(3,4) and y=(4,3). Both coordinates use the same previously specified feature scale.
- Find
- Calculate the dot product and norms separately, then combine them.
Multiply corresponding coordinates and add.
Both norms equal 5 in this case.
Divide by the product of both norms.
Result: Cosine similarity is 0.96. This is a directional score, not a 96% probability of identical content.
Check: For 2x and y, both the numerator and x’s norm double. The quotient remains 0.96.
A negative result in three dimensions
- Given
- x=(1,2,2) and y=(−2,−1,−2). Coordinates are real and may be negative.
- Find
- Interpret a negative dot product geometrically.
The three coordinate products sum to −8.
Signs disappear when squaring, but not in the dot product.
The denominator stays positive.
Result: The directions form an obtuse angle. They are strongly opposed but not exactly opposite, which would require a score of −1.
Check: Replacing y with −y changes the score to +8/9. Both norms remain unchanged.
Recall the method later with the formula’s flashcards.
10 flashcards · English materials
Already have an account? Sign in for flashcardsAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Zero cases, distances and meaning
Some programs conventionally return 0 for a zero vector. This produces a practical array result, but does not define a mathematical right angle to that vector. This calculator reports the zero case explicitly. Also check whether an application uses cosine similarity or one minus cosine similarity: larger values indicate greater similarity in the first case, while smaller values do in the second.[1]
The expression 1−cosSim is often called cosine distance, but it does not satisfy the triangle inequality for general directions. Exercise 5 gives a counterexample. In semantic applications, the formula evaluates the supplied vectors rather than the quality of the underlying language model. A threshold such as 0.8 therefore does not automatically carry the same interpretation across embedding models.[1]
Five exercises with solutions
Calculate · Foundation
Calculate cosine similarity for x=(3,4) and y=(1,0).
Show hint
The norm of y is 1.
Learning goal: Calculate a simple similarity completely.
Show solution and calculation
The dot product is 3 and the norms are 5 and 1.
Thus cosSim=3/5=0.6.
Only x’s first coordinate enters the numerator here, but both enter its norm.
Rearrange · Application
Two real nonzero vectors have cosine similarity 0.5. What is their included angle between 0° and 180°?
Show hint
Use inverse cosine over the specified angular range.
Learning goal: Infer the included angle from similarity.
Show solution and calculation
θ=arccos(0.5)=60°.
This is the included angle; cosine similarity alone cannot identify an oriented rotation direction.
The page calculator returns similarity, and the angle is a separate calculation here.
Interpret · Application
For x and y, cosSim(x,y)=0.6. Find cosSim(5x,y) and cosSim(−5x,y).
Show hint
The norm of αx is |α| times the norm of x.
Learning goal: Distinguish positive and negative overall scaling.
Show solution and calculation
Positive factor 5 cancels, so the first value remains 0.6.
With factor −5 the numerator reverses sign while the norm stays positive; the second value is −0.6.
Error analysis · Application
A program returns 0 for x=(0,0) and y=(1,2). An evaluation concludes that the vectors are orthogonal. Is that justified?
Show hint
Check the denominator and whether x has a direction.
Learning goal: Separate a software convention from the mathematical domain.
Show solution and calculation
No.
The numerator is zero, but so is x’s norm, producing 0/0.
The reported number may be a library convention.
It defines no angle here and should be handled separately as a zero case.
Transfer · Challenge
Three unit vectors in a plane have angles 0°, 60° and 120°. Check whether d=1−cosSim satisfies the triangle inequality for this triple.
Show hint
Neighboring directions differ by 60°, while the outer pair differs by 120°.
Learning goal: Test the triangle inequality with a concrete counterexample.
Show solution and calculation
Neighboring values are each 1−cos 60°=0.5.
The outer value is 1−cos 120°=1.5.
The required inequality 1.5≤0.5+0.5 is false.
Thus 1−cosSim is not a metric distance on these directions.
This does not prevent its practical use as a dissimilarity score.
Check your understanding with the formula’s reference test.
8 test questions · English materials
Already have an account? Sign in for the testAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Sources for this explanation
Quanta · Updated November 1, 2026
Editorial responsibility: Quanta Study editorial team
Review scope
This explanation, 2 worked examples and 5 exercises are available in German and English. Structure, source references and mathematical notation undergo automated checks. Calculations, model assumptions and both language versions receive a separate AI review.
An independent, named human subject review has not yet been documented. Our exercise numbers are worked examples, rather than measurements published by the cited sources.
Editorial responsibility, sources and methodsChange history
- Added direction-based interpretation, two original examples and exercises on scaling, zero vectors and distance concepts.
Cite this reference page
Quanta. Cosine similarity between vectors. Updated November 1, 2026. https://quanta-study.de/en/formula-sheet/kosinus-aehnlichkeit-vektoren
When citing a specific scientific statement, also cite the specialist source linked to that statement.