Cosine similarity
Cosine similarity measures how alike two vectors are by the angle between them. It ranges from -1 to 1, ignores vector length, and is the most common way to compare embeddings in search.
Also called: cosine distance
By Divya Sharma · Checked Nov 15, 2026 · How we review
When two embeddings point in the same direction, their cosine similarity is 1. When they are at right angles it is 0, and when they point in opposite directions it is -1. Because only direction counts, a long document and a short one about the same topic can still score as close.
(Not to be confused with Cosine, an AI coding tool that shares the name.)
How it is calculated
Take the dot product of the two vectors and divide by the product of their lengths. If both vectors are already normalized to length 1, cosine similarity equals the plain dot product, which is cheaper to compute. Many embedding models return normalized vectors for this reason.
Cosine distance
Some vector databases ask for a distance instead of a similarity. Cosine distance is usually 1 minus cosine similarity, so smaller means closer.
Choosing a metric
Use the metric the embedding model was trained for, which its documentation states. With normalized vectors, cosine, dot product and Euclidean distance give the same ranking, so the choice matters less than people expect. With unnormalized vectors they can differ.
Limits
A high score does not mean a fixed percentage of relevance. Score ranges differ between models, so a threshold that works for one model can fail for another. Set thresholds from tests on your own data, or let a reranker decide.
Related terms
- Embedding
- An embedding is a list of numbers (a vector) that represents a piece of text, an image or other data, produced so that items with similar meaning end up with vectors close together.
- Vector search
- Vector search finds items by comparing their embeddings to the embedding of a query and returning the closest ones, so results match on meaning rather than on shared keywords.
- Vector database
- A vector database stores embeddings alongside their source records and finds the stored vectors closest to a query vector, usually with an approximate index so search stays fast across millions of items.
- Embedding dimension
- Embedding dimension is the number of values in each vector an embedding model outputs. More dimensions can hold more detail, but every extra value adds storage, memory and search cost per item.
- Reranking
- Reranking is a second search step that takes a short list of candidate documents and reorders them by relevance to the query, using a more accurate but slower model than the first search.