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.
What the score means in practice
Raw cosine similarity scores have different thresholds depending on the embedding model and the task. As a rough guide for text embeddings from modern models:
| Score range | Typical meaning |
|---|---|
| 0.95–1.00 | Near-identical texts or duplicates |
| 0.85–0.95 | Highly related — same topic, similar wording |
| 0.70–0.85 | Related — overlapping concepts but distinct content |
| 0.50–0.70 | Loosely related — same domain, different angle |
| Below 0.50 | Unrelated or marginally connected |
These thresholds are illustrative. Different embedding models normalise differently, and models trained on specific domains (code, biomedical text, multilingual) may cluster differently. For production retrieval, establish your own threshold by evaluating a labelled sample from your actual data.
Worked example
Suppose vector A represents the sentence “machine learning is transforming healthcare” and vector B represents “AI is being used in medical diagnosis”, encoded by the same embedding model. A typical similarity for semantically equivalent medical-AI sentences might be around 0.88 — high enough that a retrieval system would correctly identify them as related.
Now suppose vector C encodes “the company’s Q3 revenue exceeded projections”. Comparing A and C would typically score below 0.30, correctly reflecting that these sentences discuss unrelated topics.
Common uses in AI development
- Semantic search debugging: Paste the embedding of a query and a retrieved document to verify the retriever’s similarity score matches your expectations.
- Deduplication: Find text pairs that score above a threshold to identify near-duplicate content in a corpus before indexing.
- RAG evaluation: Compare the query embedding against each retrieved chunk to confirm the most similar chunk was actually retrieved.
- Clustering sanity check: Paste two vectors you expect to cluster together and verify they actually point in a similar direction.
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 — paste any embeddings without concern about data leaving your machine.