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 and semicolons, and any token that is not a plain number is dropped. Paste values without the brackets of a JSON array, because a number glued to a bracket, such as [0.9, is discarded. 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.

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.