Vector Similarity, Embedding Search and K-Means Elbow Lab

Enter a query vector and labelled document vectors with the relevant ones, or k and WCSS pairs, and see rankings, recall@k and the suggested number of clusters.

Runs in your browser. Your files never leave your device. See how to check

…

How to do it

  1. 1
    Choose the task

    Search or elbow.

  2. 2
    Enter vectors

    Query and documents.

  3. 3
    Mark relevant documents

    For recall.

  4. 4
    Read the ranking

    And metrics.

  5. 5
    Or enter WCSS

    To find k.

About this tool

Embeddings turn text, images and products into vectors of numbers, so that similar items have similar vectors. Search and retrieval-augmented generation (RAG) systems find the documents whose vectors are closest to a query, most often by cosine similarity. Checking how well the right documents come back, through recall and precision at k, is the first test of any retrieval system. Clustering the same vectors with k-means needs a choice of k, often made with the elbow method. This lab does both with your own small examples.

Who this is for

Developers building search and RAG systems, data science students, and teams testing embedding models.

Similarity measures

Cosine similarity = a·b / (|a| |b|), from −1 to 1, measuring direction regardless of length. Euclidean distance is the straight-line distance; Manhattan the sum of absolute differences; the dot product combines direction and length. Many embedding models normalise vectors, making cosine and dot product rank identically.

Ranking and evaluation

The table ranks documents by cosine similarity. Recall@k = relevant documents found in the top k / all relevant documents; precision@k = relevant documents in the top k / k. In RAG, recall matters most: the model cannot use a document it never sees.

The elbow method

For k-means, the within-cluster sum of squares (WCSS) falls as k increases. Plotting WCSS against k usually shows an elbow where extra clusters stop helping much. The calculator finds the point farthest from the straight line between the first and last points.

A worked example

A query vector closest to "Returns form" and "Refund policy" retrieves both in the top 2, recall@2 = 1.0. WCSS values from k = 1 to 7 of 1,520 down to 232 give an elbow at k = 3.

Tips

Use the same embedding model for queries and documents, test with real questions, and keep a small labelled set to measure changes. Real embeddings have hundreds or thousands of dimensions; small vectors here are for learning and checking.

## Building a test set Write 20 to 50 real questions, and for each one note which documents should answer it. Run them through your retrieval system and record recall@5 and recall@10. Repeat the test whenever you change the embedding model, chunk size or ranking method; small changes can move recall by several points.

Chunking

Documents are usually split into chunks of a few hundred tokens before embedding. Chunks that are too large blur several topics together; chunks that are too small lose context. Overlapping chunks by 10% to 20% helps keep sentences intact.

## Entering vectors Type each document on its own line as a name, a colon and its numbers, such as Refund policy: 0.9, 0.1, 0.3. Mark relevant documents by name, separated by commas. For the elbow, enter lines such as 3: 410 from your clustering runs.

Limits

The elbow is a heuristic; silhouette scores and domain knowledge also guide k. General information only.

Worked example

The two relevant documents rank first and second: recall@2 = 1.0.

Quick facts

Frequently asked questions

What is cosine similarity?

The cosine of the angle between two vectors, from −1 to 1.

Cosine or Euclidean?

Cosine for direction; with normalised vectors they rank similarly.

What is recall@k?

The share of relevant documents found in the top k results.

What is the elbow method?

Choosing k where extra clusters stop reducing WCSS much.

Can I paste real embeddings?

Yes, if the query and documents have the same number of dimensions.

Is my data stored?

No. It stays in your browser.

Guides for this tool

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages