DevTools Logo

Embedding kNN Search

Embedding kNN Search

Rank a pasted vector corpus against a query by cosine, dot product or Euclidean distance — with tie and distribution diagnostics.

Runs in your browser
Try an example

Corpus and query

3 vector(s) · 2 dims · 1 line · 95 chars
3 vectors2 dims1 off-unit norm(s)

Nearest neighbors

3 scanned · top 3

1 of 3 vectors deviate from unit norm by more than 0.01 (max 0.414).

Top-k nearest neighbors with all three metrics
RankIDCosineDotEuclideanNorm
1a1.00001.00000.00001.0000
2c0.70711.00001.00001.4142
3b0.00000.00001.41421.0000

Score distribution (cosine)

min 0.0000 · mean 0.5690 · std 0.4198 · max 1.0000 across 3 scores.

Exact brute-force search over Float32 data. Nothing is uploaded or stored.

Examples

Find the closest chunk

Input
{"id":"a","vector":[1,0]}
{"id":"b","vector":[0,1]}
{"id":"c","vector":[1,1]}
Query: [1,0]

Cosine ranks a first (1.0), then c (0.7071), then b (0). All three scores appear side by side.

Check normalization

Input
Vectors with norms 1.0, 1.4 and 0.99

The diagnostics chip reports how many corpus vectors deviate from unit norm by more than 0.01.

Duplicate detection

Input
[1,0]
[1,0]
[0,1]

Near-identical scores are grouped into tie clusters so you can spot duplicates before indexing.

About this tool

When a RAG pipeline returns the wrong chunk, the fastest fix is usually to inspect the vectors. This tool parses a pasted corpus of embeddings — JSON objects with ids, arrays, CSV or one vector per line — and scores every row against your query using exact brute-force search. Cosine, dot product and Euclidean distance are all computed in one scan, so switching the primary metric re-ranks instantly. A top-k table shows the winner's id and all three scores; diagnostics flag duplicate or near-duplicate vectors, off-unit norms, dimension mismatches and zero queries, and a 20-bin histogram shows the score distribution across the corpus. A seeded cluster fixture is one click away for demos. Everything runs locally in Float32 typed arrays: no vector database, no upload, no persistence.

What this tool does not do

  • Processes only the inputs provided in this session without connecting to external accounts or background servers.
  • Runs entirely in the current browser tab; nothing is synced across devices or backed up to a server.

How to use this tool

  1. Paste corpus vectors and query

    Supply embeddings as JSON, JSONL, or CSV along with your query vector.

  2. Pick similarity metric and k

    Rank by cosine similarity, dot product, or Euclidean distance.

  3. Inspect top-k scores and norms

    Review ranked neighbors, score histogram, and normalization warnings.

Use cases

Find the closest chunk

Cosine ranks a first (1.0), then c (0.7071), then b (0). All three scores appear side by side.

Check normalization

The diagnostics chip reports how many corpus vectors deviate from unit norm by more than 0.01.

Duplicate detection

Near-identical scores are grouped into tie clusters so you can spot duplicates before indexing.

Common mistakes

Mistake:Does Euclidean distance rank the same neighbors as cosine similarity?

Fix:On unit-normalized vectors, squared Euclidean distance is strictly monotonic with cosine similarity (d² = 2 − 2·cos θ), yielding identical neighbor order; on unnormalized vectors they can diverge.

Mistake:What retrieval problems can the diagnostics panel catch?

Fix:It flags dimension mismatches between query and corpus rows, zero-norm vectors, unnormalized embeddings, duplicate tie clusters, and narrow score distributions.

Frequently asked questions

When do cosine similarity and dot-product rankings differ?

When every vector has unit L2 norm (length 1.0), cosine similarity and dot product produce identical rankings; when vector magnitudes vary, dot product favors longer vectors alongside directional alignment.

Does Euclidean distance rank the same neighbors as cosine similarity?

On unit-normalized vectors, squared Euclidean distance is strictly monotonic with cosine similarity (d² = 2 − 2·cos θ), yielding identical neighbor order; on unnormalized vectors they can diverge.

What retrieval problems can the diagnostics panel catch?

It flags dimension mismatches between query and corpus rows, zero-norm vectors, unnormalized embeddings, duplicate tie clusters, and narrow score distributions.

Are proprietary embeddings uploaded anywhere?

No. Exact Float32Array brute-force scoring runs locally in your browser tab with zero network calls.