DevTools Logo

Vector Similarity Calculator

Vector Similarity Calculator

Cosine, dot, Euclidean and Manhattan matrices for embedding vectors, with a 2D projection.

Runs in your browser
Try an example

Vectors

1 line · 49 chars

One vector per line (comma or space separated), or JSON such as [[1, 0], [0, 1]]. Every vector needs the same number of dimensions.

Cosine similarity

4 × 4, 3D
The plot shows only the first 2 of 3 components. Use PCA to see the directions that vary most.
Pairwise cosine values
Vectorv1v2v3v4
v110.9701430-1
v20.97014310.242536-0.970143
v300.24253610
v4-1-0.97014301

2D projection

first two components
v1v2v3v4

About

Paste JSON arrays or comma-separated vectors to calculate pairwise metrics and inspect a 2D projection. All calculations run locally with no API calls.

Examples

Orthogonal cosine pair

Input
calculateVectorSimilarity("1,0\n0,1", "cosine")
Output
matrix [[1, 0], [0, 1]]

Perpendicular unit vectors score 0 cosine with 1s on the diagonal.

Zero-vector warning

Input
calculateVectorSimilarity("0,0\n1,0", "cosine")
Output
matrix[0][1] = 0 + "zero vector" warning

Cosine is undefined for a zero vector, so the tool reports 0 and warns explicitly.

About this tool

Vector Similarity Calculator compares embedding-style vectors with calculateVectorSimilarity(input, metric, projectionMethod): inputs parse from JSON arrays or comma/whitespace/newline-separated rows via parseVectors, mismatched dimensions return an explicit error, and results include a full pairwise matrix plus a 2D projection.

Metrics are cosine (cosineSimilarity, 0 for zero vectors with a warning), euclidean distance, and raw dot product via vectorDistance. Projections use projectVectors with first-two coordinates or a deterministic PCA path (power iteration with fixed sign) that returns identical output across calls.

The matrix is square (n x n) with 1s (cosine) down the diagonal — C(n,2) unique off-diagonal pairs — and single-vector or empty input yields guidance warnings or an enter-at-least-two-vectors error. All math runs client-side.

How to use this tool

  1. Paste two or more vectors

    Enter one vector per line (1,0 / 0,1) or a JSON array like [[1, 2], [3, 4]] — all rows need equal dimensions.

  2. Pick cosine, euclidean, or dot

    Cosine scores direction (orthogonal = 0), euclidean scores distance, dot scores raw alignment.

  3. Read the matrix and projection

    Check pairwise scores in the square matrix and the first-two or PCA scatter for cluster shape.

Use cases

Sanity-checking embeddings

Confirm similar texts score near 1 cosine and unrelated ones near 0 before indexing.

Comparing distance metrics

See how cosine, euclidean, and dot rank the same vector pairs differently.

Previewing cluster layout

Project small vector sets with first-two or PCA coordinates for a quick scatter view.

Common mistakes

Mistake:Passing ragged rows and expecting partial scores.

Fix:Any dimension mismatch returns an error with an empty matrix — pad or truncate rows to equal length first.

Mistake:Reading cosine of a zero vector as meaningful.

Fix:Zero vectors always report 0 with a warning; re-embed or drop them instead of ranking on that score.

Mistake:Expecting the matrix to list only unique pairs.

Fix:The matrix is square n x n including the diagonal — count C(n,2) unique off-diagonal pairs (6 for 4 vectors) yourself.

Frequently asked questions

What does this tool do?

It compares vectors with calculateVectorSimilarity: JSON or line-based input via parseVectors, cosine/euclidean/dot metrics in a square n x n matrix, plus first-two or deterministic PCA projection via projectVectors.

What happens with mismatched dimensions or zero vectors?

Mismatched dimensions return an explicit same-dimensions error with an empty matrix; a zero vector reports cosine 0 with a warning that the score is undefined.

Is my vector data uploaded or stored?

No. Parsing, similarity math, and PCA all run locally in your browser.

Why is the matrix square instead of unique pairs?

The matrix includes the full n x n grid with the diagonal, so for 4 vectors you read C(4,2) = 6 unique off-diagonal pairs out of 16 cells.

References & standards