Cosine Similarity Calculator

← All tools

Paste two JSON arrays of numbers. The page reports cosine similarity, the dot product, both magnitudes, and the Euclidean and Manhattan distances.

The vectors never leave the browser. Nothing is uploaded, and the arrays are not stored in the URL.

Not compared

Result

About this tool

Cosine similarity is the cosine of the angle between two vectors. For vectors A and B it is the dot product A·B divided by the product of the two lengths. Each length is the square root of the sum of the squared coordinates. The result is 1 when the vectors point the same way, 0 when they are perpendicular, and -1 when they point in opposite directions. In retrieval, a higher cosine means the two embedding vectors are closer in direction. It does not tell you that a chunk answers the question.

The dot product is the sum of coordinate products. Euclidean distance is the straight-line distance between the two points, the square root of the sum of squared differences. Manhattan distance adds the absolute differences. The angle is the arccosine of the cosine, converted from radians to degrees. If floating point pushes the cosine a tiny bit outside -1 to 1, the angle uses the clamped value and the result says so.

A vector whose length is 0 has no direction, so the cosine and the angle are undefined. The other numbers are still reported. The two arrays must have the same length. Each value must be a finite JSON number. This page accepts up to 8,192 dimensions. A longer array is refused so a huge paste does not lock the tab. The sample is [1, 2, 3] and [1, 2, 4].

Read more

Free books, courses, and software

Get my programming books, course editions, and complete software.

Get the download library →