%3C/text%3E%3C/svg%3E">
💻
💻 Tech & IT

Cosine Similarity & Euclidean Distance Calculator

Results update as you type.

Your numbers

Understanding the cosine similarity and distance calculator — concept and principle

Cosine similarity measures how closely two vectors point in the same direction, regardless of their length. It is the standard way to compare text embeddings, document word-count vectors and user preference profiles in search engines and recommendation systems. Alongside it, this calculator reports the dot product, the Euclidean (straight-line) distance and the Manhattan (city-block) distance, which do depend on magnitude.

Cosine similarity of A = (1,2,3,4) and B = (2,3,4,5)Multiplying matching entries gives 2 + 6 + 12 + 20 = 40. Dividing by the lengths 5.48 and 7.35 gives cosine 0.9938, an angle of about 6.4°, while the Euclidean distance between the tips is 2.Cosine looks at direction, not lengthABA×B122236+3412+4520+= 40‖A‖ = 5.48‖B‖ = 7.35distance 2cos θ =40 ÷ (5.48 × 7.35)= 0.9938θ ≈ 6.4°4-D vectorsdrawn flat
Dot product 40 ÷ (5.48 × 7.35) = 0.9938: the vectors point almost the same way.

How it is calculated

For vectors A = (a₁, …, aₙ) and B = (b₁, …, bₙ) of the same length:

The principle

The dot product equals ‖A‖ × ‖B‖ × cos θ, where θ is the angle between the vectors. Dividing out both lengths leaves only cos θ: 1 when the vectors point the same way, 0 when they are perpendicular, −1 when they point in opposite directions. This is why cosine similarity suits text, where a long document and a short one about the same topic should look alike. Euclidean distance instead measures how far apart the two points are, so scaling one vector changes it. For vectors normalised to length 1, the two are directly linked: squared Euclidean distance = 2 − 2 × cosine.

Worked example

  1. A = (1, 2, 3, 4), B = (2, 3, 4, 5).
  2. Dot product = 2 + 6 + 12 + 20 = 40.
  3. ‖A‖ = √30 = 5.4772 and ‖B‖ = √54 = 7.3485, so ‖A‖ × ‖B‖ = √1,620 = 40.249.
  4. Cosine = 40 ÷ 40.249 = 0.99381, an angle of about 6.4°.
  5. Each difference is 1, so Euclidean = √4 = 2 and Manhattan = 1 + 1 + 1 + 1 = 4.

How to read the result

A cosine of 0.994 says the vectors point almost the same way even though they are 2 units apart. For non-negative data such as word counts, cosine ranges from 0 to 1. With embeddings, what counts as "similar" depends on the model, so compare scores within one model rather than using a fixed cut-off. Use Euclidean or Manhattan distance when absolute size matters, for example physical measurements.

Common mistakes

Keep in mind: In very high dimensions, distances between random points become similar, and raw scores can mislead. Results also depend on feature scaling, so standardise inputs when features use different units.

Frequently asked questions

What is cosine distance?

It is usually defined as 1 − cosine similarity. It is useful for ranking but does not satisfy the triangle inequality.

Is cosine similarity the same as Pearson correlation?

Pearson correlation is the cosine similarity of the two vectors after subtracting each one's mean.

Which is faster for search, cosine or dot product?

If all vectors are pre-normalised to length 1, the dot product equals cosine similarity and is the cheaper operation.

Sources: C. D. Manning, P. Raghavan and H. Schütze, Introduction to Information Retrieval, Cambridge University Press, 2008 · G. Strang, Introduction to Linear Algebra, Wellesley-Cambridge Press

Checked 8 Nov 2026. Standard formulas and RFC/IEEE definitions, computed locally in your browser — nothing you type is sent anywhere.

💻 All tech & IT tools →🌍 Calculators by country →