Cosine Similarity Calculator

Enter two vectors (up to 6 dimensions) and get the cosine similarity between them. Input values for Vector A and Vector B component by component, then see the similarity score, the angle θ between the vectors, and the cosine distance — all computed from the standard dot-product formula.

Number of components in each vector

Set to 0 if not used

Set to 0 if not used

Set to 0 if not used

Set to 0 if not used

Set to 0 if not used

Set to 0 if not used

Set to 0 if not used

Set to 0 if not used

Results

Cosine Similarity

--

Angle θ Between Vectors

--

Cosine Distance

--

Dot Product (A · B)

--

Magnitude ‖A‖

--

Magnitude ‖B‖

--

Vector Component Comparison

Frequently Asked Questions

What is cosine similarity?

Cosine similarity is a metric that measures the cosine of the angle between two non-zero vectors in an inner product space. It produces a value between -1 and 1, where 1 means the vectors point in exactly the same direction, 0 means they are orthogonal (perpendicular), and -1 means they point in opposite directions. It is widely used in NLP, recommendation systems, and clustering.

How do I calculate cosine similarity?

Cosine similarity is calculated as the dot product of the two vectors divided by the product of their magnitudes: SC(A, B) = (A · B) / (‖A‖ × ‖B‖). First compute the dot product by summing the products of corresponding components, then divide by the product of the Euclidean norms of each vector.

Can cosine similarity be negative?

Yes, cosine similarity can be negative. Since it equals the cosine of the angle between two vectors, and cosine is negative for angles between 90° and 270°, vectors that point in roughly opposite directions will have a negative cosine similarity. A value of -1 means the vectors are perfectly opposite.

What does a cosine similarity of -1 mean?

A cosine similarity of -1 means the two vectors are diametrically opposed — they point in exactly opposite directions. The angle between them is 180°. In text analysis, this would indicate the two documents are as different as possible in terms of their term distributions.

What is cosine distance?

Cosine distance is derived from cosine similarity as: DC = 1 − SC. It converts the similarity measure into a proper dissimilarity or distance metric. A cosine distance of 0 means the vectors are identical in direction, while a value of 1 means they are perpendicular, and 2 means they are completely opposite.

Why use cosine similarity instead of Euclidean distance?

Cosine similarity focuses on the orientation (direction) of vectors rather than their magnitude. This makes it especially valuable when comparing documents or embeddings of different lengths — a short document and a long document covering the same topic can still have a high cosine similarity even though their Euclidean distance would be large.

What is the range of cosine similarity values?

Cosine similarity ranges from -1 to 1. A value of 1 indicates perfect similarity (identical direction), 0 indicates orthogonality (no similarity in direction), and -1 indicates perfect dissimilarity (opposite directions). In applications where all vector components are non-negative (like TF-IDF), the range is typically 0 to 1.

What should I do if my vectors have different lengths (dimensions)?

Cosine similarity requires both vectors to have the same number of dimensions. If your vectors differ in length, pad the shorter one with zeros for the missing components. This is a common practice and doesn't distort the similarity measure — it simply means those dimensions contribute nothing to the dot product or magnitude difference.

More Math Tools