Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Cosine Similarity Calculator

An interactive cosine-similarity and vector-distance calculator. Paste two vectors and instantly see their dot product, magnitudes, cosine similarity, cosine distance, the angle between them, and Euclidean and Manhattan distance — the exact numbers behind how embedding search decides which items are “close.” See why cosine ignores magnitude and when to prefer it over Euclidean distance.

0.9653cosine similarity
15.1°angle between vectors

Strongly similar

Cosine distance 1 − similarity0.0347
Dot product A · B0.97
Magnitude |A|1.01
Magnitude |B|0.995
Euclidean distance L20.2646
Manhattan distance L10.5

Cosine similarity asks whether two vectors point the same way, ignoring how long they are, which is why it is the default score for comparing embeddings. Enter two vectors of the same length and the calculator returns their cosine similarity and the angle it implies, the cosine distance, the dot product and magnitudes it was built from, and the Euclidean and Manhattan distances for comparison.

What it computes

A · B      = Σ aᵢ × bᵢ                  dot product
|A|        = √(Σ aᵢ²)                   magnitude (L2 norm)
cos(A, B)  = A · B ÷ (|A| × |B|)        from −1 to 1
angle      = arccos(cos) × 180 ÷ π      degrees
distance   = 1 − cos                    from 0 to 2
Euclidean  = √(Σ (aᵢ − bᵢ)²)            L2
Manhattan  = Σ |aᵢ − bᵢ|                L1

Similarity is 1 for the same direction (0°), 0 for perpendicular vectors (90°) and −1 for opposite ones (180°). Dividing by both magnitudes rescales each vector to length 1 before comparing, so only direction survives. Euclidean and Manhattan distance keep magnitude, which is why they are shown alongside.

Input is split on spaces, commas, semicolons and square brackets, so a JSON array such as [0.9, 0.1, 0.4, 0.2] pastes as is. Any other token that is not a plain number, such as a quoted "0.9" or a label, is dropped. Both vectors need the same number of dimensions, and neither may be all zeros, since a zero vector has no direction.

A worked example

The defaults are A = (0.9, 0.1, 0.4, 0.2) and B = (0.8, 0.3, 0.5, 0.1).

Dimensionaba × b(a − b)²
10.90.80.720.01
20.10.30.030.04
30.40.50.200.01
40.20.10.020.01
Sum0.970.07
  1. Dot product: 0.97.
  2. Magnitudes: |A| = √1.02 = 1.00995, shown as 1.01, and |B| = √0.99 = 0.99499, shown as 0.995.
  3. Cosine: 0.97 ÷ (1.00995 × 0.99499) = 0.97 ÷ 1.00489 = 0.9653, labeled "Strongly similar".
  4. Angle: arccos(0.9653) = 15.1°, and cosine distance is 0.0347.
  5. Euclidean: √0.07 = 0.2646. Manhattan: 0.1 + 0.2 + 0.1 + 0.1 = 0.5.

Now double every value of B. The dot product becomes 1.94 and |B| becomes 1.99, but the cosine stays 0.9653 and the angle 15.1°, while Euclidean distance jumps to 1.0488 and Manhattan to 1.8. That is the whole difference between the metrics: cosine sees direction only.

Assumptions and limits

  • Direction only. Cosine treats a vector and any positive multiple of it as identical. If magnitude carries meaning in your data, such as counts or intensities, a distance that keeps it may fit better.
  • Normalized vectors make the metrics agree. For unit-length vectors, squared Euclidean distance equals 2 − 2 × cos, so both rank neighbors identically, and the dot product alone equals the cosine.
  • Verdict labels are geometric. The bands at 0.99, 0.7, 0.3, −0.3 and −0.7 describe angles, not meaning. What counts as relevant depends on the model.
  • Toy dimensions. Real embeddings have hundreds or thousands of dimensions, and each model's scores sit in their own range, so intuition from four dimensions transfers only partly.
  • Display rounding. Values are shown to four decimals with trailing zeros removed, and the angle to one decimal.

How to use the result

  • Rank, don't threshold blindly. In retrieval the order of scores matters more than their absolute value. If you need a cutoff, calibrate it on labeled pairs from your own data and model.
  • Match the index metric to the model. Use the similarity the embedding model was trained for, usually cosine or dot product for text, and configure the vector database to use the same one.
  • Normalize once, then use the dot product. If you store unit vectors, the dot product is the cosine and is cheaper to compute at scale.
  • Debug with known pairs. Paste two embeddings that should match and two that should not. If the gap between their cosines is small, look at the model or the chunking before the search.

When to use it, and when not

Use it to check a small case by hand: confirm that a library, a vector database or your own code returns the same cosine for a pair of vectors, see what normalization does, or show a colleague why a doubled vector still scores 0.9653. It takes any number of dimensions, so a full embedding pasted as plain numbers works.

Do not use it to rank a corpus, which is a job for a vector index, or to decide whether two passages are relevant, which needs labeled pairs scored with your own model. For sets of tags or shingles, where only overlap matters, Jaccard similarity is the usual measure. For counts or intensities whose size means something, use a distance that keeps magnitude.

Trade-offs and limits

Cosine buys its indifference to length by also being blind to three other things, and each can make a score look better than the data deserves.

Cosine ignoresEffectOn this calculator
LengthA scaled copy scores the sameDouble B: cosine stays 0.9653, Euclidean goes 0.2646 → 1.0488
A shared offsetEvery pair drifts toward 1Add 10 to every value of both defaults: cosine 0.9999, angle 0.7°, Euclidean still 0.2646
Per-dimension scaleOne large dimension dominates(100, 0.9, 0.1) against (100, 0.1, 0.9) scores 0.9999; drop the first dimension and it is 0.2195
SignNon-negative data never scores below 0(1, 0, 0) against (0, 1, 0) is 0, the floor for counts

The offset row explains why raw scores from some embedding models crowd into a narrow positive band: a direction every vector shares inflates every pair. Subtracting a common direction, such as the corpus mean, before comparing spreads them out again. Subtracting each vector's own mean turns cosine into the Pearson correlation, which for the defaults is 0.9096.

Common mistakes

  • Pasting a truncated printout. NumPy shortens long arrays with ..., and that token is not a number, so it is dropped. Paste [0.9 0.1 ... 0.2] and [0.8 0.3 ... 0.1] and both vectors still match in length: the tool compares (0.9, 0.1, 0.2) with (0.8, 0.3, 0.1) and shows 0.9652 with no error. On a real embedding the hidden middle is hundreds of dimensions. Check the dims count under each box.
  • Ranking by dot product on vectors that are not normalized. For the query (1, 0), the document (2, 2) has a dot product of 2 against 0.9 for (0.9, 0.1), so it ranks first, yet its cosine is 0.7071 against 0.9939. Length beat direction.
  • Mixing vectors from two models. Each model's dimensions mean different things, so the cosine between an old-model vector and a new-model vector is noise even when the dimension counts match. Re-embed the whole corpus when you change models.
  • Averaging unit vectors and assuming the result is still unit. The mean of the two normalized defaults has length 0.9913, so a dot-product index no longer returns cosine for it. Normalize again after any arithmetic on vectors.
  • Reading 0 as "unrelated" for count data. With non-negative features, 0 is the lowest possible score and means no shared nonzero dimension at all. The opposed bands never fire.

Check yourself

A = (3, 4) and B = (4, 3). What are the cosine, the angle and the Euclidean distance?

Dot product 12 + 12 = 24, both magnitudes 5, so the cosine is 24 ÷ 25 = 0.96, labeled "Strongly similar". The angle is arccos(0.96) = 16.3°. Euclidean distance is √(1 + 1) = 1.4142.

Two unit vectors have a cosine of 0.8. How far apart are they in Euclidean distance?

For unit vectors the squared distance is 2 − 2 × 0.8 = 0.4, so the distance is √0.4 = 0.6325. Any pair of unit vectors at that cosine sits exactly that far apart, which is why the two metrics rank them the same way.

A = (1, 2, 3) and B = (−1, −2, −3). What does the calculator report?

Dot product −14, both magnitudes √14, so the cosine is −1, the angle 180° and the cosine distance 2, the maximum, labeled "Strongly opposite". Euclidean distance is twice |A|, 2 × 3.7417 = 7.4833.

Add 10 to every value of both default vectors. What changes, and what does not?

The differences between A and B are unchanged, so Euclidean stays 0.2646 and Manhattan 0.5. The cosine rises from 0.9653 to 0.9999 and the angle falls from 15.1° to 0.7°, because both vectors now point mostly along the shared (1, 1, 1, 1) direction. The verdict flips to "Nearly identical direction" with no change in how far apart the vectors are.

A B 2B θ 15.1° cos(A,B) = cos(A,2B)0.9653 both: same angle Euclidean A to B0.2646 Euclidean A to 2B1.0488: length counts
Cosine reads only the angle between the arrows, so stretching B along its own line changes nothing. Euclidean distance measures the gap between the tips, which grows with length. The plot is schematic: the defaults have four dimensions.

How it works

  • Cosine similarity = dot(A, B) / (|A| × |B|), ranging from -1 to 1.
  • Cosine distance = 1 − similarity; the angle is arccos(similarity) in degrees.
  • Also reports dot product, magnitudes, Euclidean and Manhattan distance.
  • Runs entirely in your browser; the vectors never leave the page.

Frequently asked questions

What is cosine similarity?

Cosine similarity measures the angle between two vectors while ignoring their length. It is the dot product of the vectors divided by the product of their magnitudes, and it ranges from 1 for vectors pointing the same way, through 0 for perpendicular vectors, to -1 for opposite ones. Because it looks only at direction, two embeddings can score as highly similar even when one vector is much longer than the other.

Cosine similarity or Euclidean distance for embeddings?

Cosine compares direction, while Euclidean distance measures the straight-line gap, which includes magnitude. Many embedding models output normalized vectors of length 1, and for unit vectors the squared Euclidean distance equals 2 minus 2 times the cosine, so both produce the same ranking of nearest neighbors. Use cosine when magnitude is noise, the usual case for text embeddings, and a magnitude-aware distance when the length of the vector itself carries meaning.

What is cosine distance?

Cosine distance is 1 minus cosine similarity. It turns similarity into a distance where 0 means the same direction, 1 means perpendicular and 2 means opposite, which matches how nearest neighbor search ranks results: smaller is closer. It is not a true metric, because it can break the triangle inequality, but it works well for ranking. For the default vectors here, a similarity of 0.9653 is a cosine distance of 0.0347.

Why does cosine similarity ignore magnitude?

Dividing by both magnitudes rescales each vector to unit length before comparing them, so only the angle between them remains. Doubling every value of a vector leaves its cosine with any other vector unchanged: in the default example, doubling B moves the Euclidean distance from 0.2646 to 1.0488 while the cosine stays 0.9653. For text embeddings that is usually what you want, because you care whether two passages point the same way, not how large their vectors are.

How do I calculate cosine similarity by hand?

Multiply the vectors element by element and add the products to get the dot product. Square each element of each vector, add them and take the square root to get the two magnitudes. Then divide the dot product by the product of the magnitudes. For (0.9, 0.1, 0.4, 0.2) and (0.8, 0.3, 0.5, 0.1), the dot product is 0.97, the magnitudes are 1.00995 and 0.99499, and the cosine is 0.97 divided by 1.00489, or 0.9653, an angle of about 15.1 degrees.

What is a good cosine similarity score for embeddings?

There is no universal threshold. Each embedding model has its own distribution of scores, so a cutoff that works for one model can fail for another. Score a set of pairs you have labeled as relevant and irrelevant with your own model, then pick the cutoff that separates them best. In retrieval the ranking usually matters more than the raw score. The verdict labels in this calculator describe the geometry of the angle, not semantic relevance.