Cosine similarity calculator
Cosine similarity is the workhorse metric for comparing embeddings. Whether you are debugging a semantic search index, evaluating a RAG retriever, or checking whether two pieces of text are near-duplicates, you reduce it to: how aligned are these two vectors? This tool computes that alignment along with the underlying dot product and norms, so you can sanity-check a result without writing code.
How it works
Cosine similarity is the dot product of the two vectors divided by the product of their L2 norms:
cos(θ) = (A · B) / (‖A‖ × ‖B‖)
The tool parses both inputs into number arrays, verifies they have the same dimension, then computes the dot product (sum of element-wise products) and each vector’s L2 norm (the square root of the sum of squares). Dividing gives a value in the range −1 to 1. A small interpretation note translates that number into plain language — near 1 means very similar, near 0 means unrelated, negative means opposed.
Tips and notes
- Both inputs must match in length. A 1536-dim OpenAI embedding only compares to another 1536-dim vector.
- Cosine vs distance. Cosine distance is simply
1 − similarity; some vector databases report distance, so a “0.1 distance” means 0.9 similarity. - Pre-normalised vectors. If your embeddings are already unit length, the cosine similarity equals the dot product — a handy cross-check.
- Local only. Vectors are processed entirely in your browser.