Vector Similarity Calculator
NEWCompare a collection of labelled vectors: the cosine, dot product or Euclidean matrix of every pair, the collection on a plane and the effect of normalization on the nearest neighbours of the query, with every convention stated.
Similarity matrix
Labelled vectors
Example data: the vectors are illustrative, not real embeddings.
- Outlined pair
- Cosine
- Angle
- Dot product
- Euclidean
2-D projection
Normalization effectdistances from A
| Vector | Cosine | Euclidean, raw | Rank | Euclidean, unit | Rank |
|---|
Marked: the rank changes once the vectors are normalized.
Found a bug or missing something? Write to us
Scope and limits
Stated conventions, exact arithmetic
Every value can be checked by hand
The arithmetic is tested against reference cases: [1, 2, 3] and [2, 0, 1] give a dot product of 5, a cosine of 5 / √70 = 0.597614, an angle of 53.30° and a Euclidean distance of exactly 3. Cosine with a zero vector stays undefined instead of becoming 0, and equal distances share a rank.
Help
FAQ
How is cosine similarity calculated?
As the dot product of two vectors divided by the product of their lengths. For [1, 2, 3] and [2, 0, 1] the dot product is 5 and the lengths are √14 and √5, so the cosine is 5 / √70 = 0.597614, an angle of 53.30°. It ranges from -1 for opposite directions to 1 for the same direction, and does not depend on length.
Why is cosine similarity undefined for a zero vector?
A zero vector has no direction, and the formula divides by its length of 0. The calculator shows the value as undefined instead of replacing it with 0, because 0 would wrongly mean that the two vectors are perpendicular. Such a vector also cannot be scaled to unit length.
When do cosine similarity and Euclidean distance rank neighbours differently?
When the vectors differ in length. [2, 4, 6] points the same way as [1, 2, 3], so its cosine is 1, yet its raw Euclidean distance is 3.7417. After both are scaled to unit length the distance is 0. For unit vectors the two orders always agree, because the squared distance equals 2 minus twice the cosine.
What does the 2-D projection show?
The collection on its first two principal components: the directions along which the centred vectors vary most. The page states how much of the variance they keep. Distances on the plane are approximate, so the matrix and the table always use every dimension. Vectors with two dimensions or fewer are drawn as they are.
How are ranks with equal distances counted?
As competition ranks: equal distances share the better rank and the next rank is skipped, so the order reads 1, 2, 3, 4, 4, 6. Distances that differ only by rounding, such as 3 and 2.9999999999, count as equal.
Are the vectors sent to a server?
No. Every value is calculated in the browser. The page address holds the vectors and their notes when they differ from the example, so the analysis can be shared as a link; nothing else is stored or sent.
