~/tools / Embeddings and search (RAG) / Embedding Similarity Calculator
Embedding Similarity Calculator — Compare embedding vectors from Ollama /api/embed: cosine similarity, dot product, distance
Paste the response from Ollama's /api/embed or an OpenAI-compatible /v1/embeddings endpoint and compare the vectors: cosine similarity, dot product and Euclidean distance, ranked against the vector you choose, plus a similarity matrix. It also shows each vector's dimensions and length, so you can see whether the vectors are normalized and whether they came from the same model. Nothing leaves your browser.
The example uses made-up, unit-length vectors with 4 dimensions so that you can read them. Real embeddings have hundreds or thousands of dimensions.
Read as an Ollama /api/embed response: 4 vectors with 4 dimensions. All vectors have a length of 1, so cosine similarity and dot product are equal.
Ranking by cosine similarity
Compared with #0 How do I keep a model loaded in Ollama?. Higher is more similar.
| Rank | Text | Cosine | Dot product | Distance |
|---|---|---|---|---|
| 1 | #1 keep_alive controls how long the model stays in memory | 0.9962 | 0.9962 | 0.0876 |
| 2 | #2 Protect Ollama with nginx and a password | 0.4037 | 0.4037 | 1.0921 |
| 3 | #3 Tomorrow's weather forecast | 0.0100 | 0.0100 | 1.4071 |
Cosine similarity matrix
Each cell compares the vector in the row with the vector in the column.
| #0 | #1 | #2 | #3 | |
|---|---|---|---|---|
| #0 | 1.000 | 0.996 | 0.404 | 0.010 |
| #1 | 0.996 | 1.000 | 0.475 | -0.005 |
| #2 | 0.404 | 0.475 | 1.000 | -0.377 |
| #3 | 0.010 | -0.005 | -0.377 | 1.000 |
Vectors
| Text | Dimensions | Length (L2 norm) | Unit length |
|---|---|---|---|
| #0 How do I keep a model loaded in Ollama? | 4 | 1.000000 | Yes |
| #1 keep_alive controls how long the model stays in memory | 4 | 1.000000 | Yes |
| #2 Protect Ollama with nginx and a password | 4 | 1.000001 | Yes |
| #3 Tomorrow's weather forecast | 4 | 1.000000 | Yes |
Based on Ollama's embeddings documentation and API reference, checked on 2026-11-04. Ollama: Embeddings / Ollama API: Generate embeddings
Everything is calculated in your browser. Nothing is sent anywhere.
An embedding model turns a piece of text into a list of numbers, a vector. Ollama's documentation describes using these vectors for semantic search with cosine similarity, and for RAG. Before you write the search code, it helps to look at the numbers: does the question really come out closest to the passage that answers it? This tool reads the JSON that Ollama returns from /api/embed ({"embeddings": [[…], …]}), the OpenAI-compatible shape from /v1/embeddings ({"data": [{"embedding": […]}]}) or a plain array of vectors. It ranks every vector against the one you pick by cosine similarity, and also shows the dot product and the Euclidean distance. Ollama's documentation says /api/embed returns L2-normalized (unit-length) vectors; for such vectors, cosine similarity and the dot product are the same number, and the tool shows the length of each vector so you can confirm it. The documentation also says to use the same embedding model for indexing and for querying. Vectors with different numbers of dimensions cannot be compared at all, and the tool stops with an error when it finds them. The calculations were checked against values computed separately in Python.
The core logic of this tool is open source under the MIT License. github.com/seigo5555/toolkitbox-lib/src/embedding-similarity.ts
Use Cases
- Embed a question and a few candidate passages in one /api/embed request and see which passage ranks first before you build a search
- Compare two embedding models on the same sentences, one model at a time, to see which one separates related and unrelated text more clearly
- Check whether stored vectors are unit length and have the dimensions you expect before you choose a distance metric for your vector database
Usage
- Send the texts to your model in one request, for example curl http://localhost:11434/api/embed -d '{"model": "embeddinggemma", "input": ["question", "passage 1", "passage 2"]}', and paste the whole JSON response.
- Optionally write one label per line, in the same order as the input, so the results show the texts instead of numbers.
- Choose which vector to compare against (by default #0, the first input). The table ranks the others by cosine similarity; the matrix shows every pair when there are 10 vectors or fewer.
FAQ
Which similarity should I use?
Ollama's embeddings page says to use cosine similarity for most semantic search use cases. Cosine similarity compares the direction of two vectors and ignores their length; 1 means the same direction. The tool also shows the dot product and the Euclidean distance, because vector databases often let you choose between these.
Why are the cosine similarity and the dot product the same?
Because the vectors have a length of 1. Ollama's documentation says /api/embed returns L2-normalized, unit-length vectors, and for unit-length vectors the cosine similarity equals the dot product. The tool shows each vector's length and says whether all of them are unit length (within 0.001).
The tool says the dimensions do not match. What does that mean?
Two vectors can only be compared when they have the same number of numbers. The length depends on the model, which the documentation puts at typically 384 to 1024 dimensions, and the /api/embed request also accepts a dimensions field. Different lengths usually mean the vectors came from different models or settings. The documentation says to use the same embedding model for indexing and for querying.
Can I paste a response with base64 embeddings?
No. The tool reads numbers only. If you call the OpenAI-compatible /v1/embeddings endpoint, request the embeddings as floats, not base64.
Is a similarity of 0.8 good?
There is no fixed threshold. The values depend on the model and on your texts, so compare the scores of related and unrelated passages from the same model rather than judging one number alone.
Is my data sent anywhere?
No. The calculations run in your browser. The tool never calls Ollama or any other server; you send the request to your model yourself.
Related articles
- Embeddings with Ollama: the basics for search and RAGMake embeddings with Ollama's /api/embed: the models and their sizes, truncate and dimensions, unit-length vectors and cosine similarity, from the official docs.
- Store and search Ollama embeddings in PostgreSQL with pgvectorKeep Ollama embeddings in PostgreSQL with pgvector, search them with HNSW or IVFFlat, and pass the results to /api/chat so that the answer cites its sources.