Skip to content
All calculators

Cosine Similarity Calculator for Vectors

Compare the direction of two pasted vectors and see the angle and dot product.

Calculator inputs

Paste vectors to compare them. Use an embedding model to turn text into vectors.

Vectors

Separate numbers with commas, spaces or line breaks.

Separate numbers with commas, spaces or line breaks.

Display
Decimal precision

Cosine similarity

0.44

Angle
63.61°
Cosine distance
0.56
Dot product
4
Matching dimensions
3 each
Length of A
3
Length of B
3

The Cosine Similarity Formula

Cosine similarity is the dot product of vectors A and B divided by the product of their lengths. The result is the cosine of the angle between the vectors.

To find the dot product, multiply each number in A by the number at the same position in B and add the products. To find a vector’s length, square its numbers, add the squares and take the square root. The vectors must have the same number of entries, and each must have at least one nonzero entry.

  • A score near 1 means the vectors point in nearly the same direction. A score of 1 means they point in exactly the same direction.
  • A score near 0 means the vectors are nearly perpendicular. A score of 0 corresponds to a 90° angle.
  • A score near −1 means the vectors point in nearly opposite directions. A score of −1 corresponds to a 180° angle.

To normalise a vector, divide each entry by the vector’s length. When both vectors have length 1, their lengths multiply to 1 and cosine similarity equals their dot product.

Worked Example With Three-Dimensional Vectors

The calculator opens with A = [1, 2, 2] and B = [2, 2, −1]. These are example vectors you can check by hand.

  1. Multiply the matching entries and add the products. The dot product is 1 × 2 + 2 × 2 + 2 × (−1) = 4.
  2. Find each length. For A, √(1 + 4 + 4) = 3. For B, √(4 + 4 + 1) = 3.
  3. Divide the dot product by the product of the lengths. The cosine similarity is 4 ÷ (3 × 3), which displays as 0.44.
  4. Take the inverse cosine of 4 ÷ 9 and convert the angle to degrees. The angle is 63.61°. Subtract the same fraction from 1 to get a cosine distance of 0.56.

The display rounds the results after calculating them. Very small figures can keep extra decimal digits so you can distinguish them from zero.

Semantic search can use cosine similarity to rank passages by how closely their embeddings point in the same direction as the question’s embedding. An embedding model converts each passage and the question into a vector of numbers. When the index uses cosine similarity, higher scores rank closer matches first.

Cosine distance is 1 minus cosine similarity. A vector database can report distance because it searches for nearest neighbours, where smaller values rank closer matches first. A result with cosine similarity 0.8 has cosine distance 0.2. Check which metric the query returns before setting the direction of a filter.

Each embedding model can place the same texts differently in its vector space. A cutoff of 0.8 that works with one model can admit weak matches or drop relevant passages with another. After switching models, score representative questions against examples of relevant and irrelevant passages, then choose a cutoff based on the search results you want to keep.