Skip to content

Embedding Similarity Calculator

About Embedding Similarity

Compare two embedding vectors using multiple distance and similarity metrics. Cosine similarity measures angular similarity (direction), while Euclidean and Manhattan measure absolute distance. Dot product captures both magnitude and direction.

All computation uses Float64Array for numerical precision. No data leaves your browser.

What This Tool Does

Paste two embedding vectors as JSON arrays and get cosine similarity, dot product, Euclidean distance, and Manhattan distance in one pass — computed locally in your browser with Float64Array precision, nothing uploaded. Cosine compares direction and ignores magnitude, which is why it is the default for text embeddings; for unit-normalized vectors it equals the dot product, so the two metrics agree there.

Last updated:

This tool is provided as-is for convenience. Output should be verified before use in any production or critical context.

Agent Invocation

Best Path For Builders

Browser workflow

Runs instantly in the browser with private local processing and copy/export-ready output.

Browser Workflow

This tool is optimized for instant in-browser execution with local data handling. Run it here and copy/export the output directly.

/embedding-similarity-calculator/

For automation planning, fetch the canonical contract at /api/tool/embedding-similarity-calculator.json.

How to Use Embedding Similarity Calculator

  1. 1

    Calculate cosine similarity between two embeddings

    Paste two embedding vectors (comma or space-separated floats). The tool computes cosine similarity (0 = unrelated, 1 = identical). Use to verify if two pieces of text/code are semantically similar.

  2. 2

    Verify embedding quality in RAG pipelines

    Embed a query and a retrieved document. Calculate cosine similarity. If < 0.7, the retrieval ranking may be wrong. High similarity (>0.85) suggests good match for the LLM.

  3. 3

    Debug semantic search ranking issues

    Calculate similarity between user query embedding and multiple candidate document embeddings. Compare scores to understand why a 'wrong' result ranked high. Helps tune embedding model choice.

  4. 4

    Find near-duplicate content in a corpus

    Embed multiple documents, calculate pairwise similarity. Documents with similarity >0.95 are likely duplicates. Useful for deduplication before indexing or for clustering similar content.

  5. 5

    Validate embedding model performance

    Embed semantically similar sentence pairs (synonyms, paraphrases) and dissimilar pairs. Similar pairs should score >0.8, dissimilar <0.3. If not, your embedding model needs retraining or swapping.

Frequently Asked Questions

What is cosine similarity?
Cosine similarity measures the angle between two vectors, returning a value from -1 (opposite) to 1 (identical). It's the most common metric for comparing text embeddings in RAG and search applications.
What embedding dimensions are supported?
Any dimension from 1 to 10,000+. Common dimensions include 384 (MiniLM), 768 (BERT), 1024 (Cohere), 1536 (OpenAI text-embedding-3-small), and 3072 (text-embedding-3-large).
When should I use cosine similarity vs euclidean distance?
Cosine similarity measures direction and is best for normalized embeddings (most common in text search). Euclidean distance measures both magnitude and direction, better for detecting outliers or when vectors are not normalized.
Is this tool free and private?
Yes. Free to use. All calculations run in your browser using JavaScript typed arrays. Your embedding vectors are not sent to external services.
Can I compare multiple embeddings at once?
The tool supports pairwise comparison of two vectors with four metrics: cosine similarity, dot product, euclidean distance, and Manhattan distance.

How do I calculate cosine similarity between two embedding vectors?

Cosine similarity is the dot product of the two vectors divided by the product of their magnitudes: cos(A, B) = (A · B) / (|A| × |B|). The result ranges from −1 (opposite direction) through 0 (orthogonal, unrelated) to 1 (same direction). To compute it here, paste each vector as a JSON array of numbers — the format embedding APIs return — and press Compute. Both vectors must have the same dimension count; the calculator recognizes common sizes such as 1536 (OpenAI text-embedding-3-small and ada-002), 3072 (text-embedding-3-large), 768 (BERT-family), and 1024 (Cohere embed-v3).

Worked example in 3 dimensions

Take A = [3, 2, 1] and B = [1, 2, 3]. Every metric this calculator reports, by hand:

dot(A, B)  = 3×1 + 2×2 + 1×3            = 10
|A|        = √(3² + 2² + 1²) = √14      ≈ 3.741657
|B|        = √(1² + 2² + 3²) = √14      ≈ 3.741657
cosine     = 10 / (√14 × √14) = 10/14   ≈ 0.714286
Euclidean  = √((3−1)² + (2−2)² + (1−3)²) = √8 ≈ 2.828427
Manhattan  = |3−1| + |2−2| + |1−3|      = 4

Paste those two arrays into the calculator and you get the same numbers. Note what cosine did: A and B contain identical values in reversed order, and it scores them 0.714 — clearly related in direction but far from identical. A magnitude change would not move cosine at all: scaling B to [2, 4, 6] leaves cosine at 0.714286 while doubling the dot product to 20 and changing both distances.

Cosine vs dot product vs Euclidean vs Manhattan

Metric Formula Range When to use
Cosine similarity (A·B) / (|A||B|) [−1, 1] Direction only, magnitude-invariant — the default for comparing text embeddings.
Dot product Σ aᵢbᵢ unbounded Direction and magnitude together; identical to cosine when both vectors are unit-normalized, and cheaper to compute.
Euclidean distance (L2) √Σ(aᵢ−bᵢ)² [0, ∞) Straight-line distance; for unit-normalized vectors it ranks pairs in the same order as cosine (d² = 2 − 2cos).
Manhattan distance (L1) Σ|aᵢ−bᵢ| [0, ∞) Sum of per-dimension differences; less dominated by a single large coordinate difference than L2.

All four metrics as implemented in this calculator (Float64Array arithmetic). Edge case: if either vector has zero magnitude, cosine is mathematically undefined; this tool reports 0 for that case.

Why do OpenAI embeddings give cosine similarity near 1 for unrelated texts?

Because modern text embeddings are anisotropic: the vectors do not spread evenly around the origin but cluster in a narrow cone of the embedding space, sharing a handful of dominant directions. Two texts with nothing in common therefore still point in broadly the same direction, and their cosine lands well above zero — often high enough to look "similar" if you expected unrelated pairs to score near 0. The practical consequence: absolute cosine values are not comparable across models, and fixed thresholds like "0.8 means related" are meaningless without calibration. What is reliable is ranking — for one query embedding, the candidate with the higher cosine is the more related one. Calibrate by measuring a baseline over deliberately unrelated pairs from your own corpus and reading scores relative to that baseline.

Which similarity metric should my vector database use?

Match the metric your embedding model was trained and evaluated with — for most text-embedding APIs that is cosine. If your provider returns unit-length vectors, dot product gives identical rankings at lower cost, which is why vector stores often default to it. Whatever you choose, use the same metric at index time and query time; mixing metrics silently reorders results.

Do my embedding vectors leave the browser?

No. Parsing and all four computations run client-side; vectors are never uploaded or stored. Embeddings can be partially inverted back toward their source text, so treat production embeddings as sensitive data — a local-only calculator is the safe way to spot-check them.