Glossary

Dot product similarity

A similarity score for two vectors found by multiplying their matching coordinates and adding the results, which grows with both their alignment and their length.

Dot product similarity scores how alike two vectors are by multiplying their matching coordinates and adding up the results. A higher score means more similar. Unlike cosine similarity, the dot product depends on the length of the vectors as well as the angle between them, so two vectors pointing the same way score higher when they are longer. For vectors normalised to unit length, the dot product and cosine similarity are the same number, which is why many vector search systems use the dot product as a faster way to compute cosine similarity. It is one of the three standard measures for comparing embeddings, alongside cosine similarity and Euclidean distance.

How the dot product is calculated

For two vectors a and b with n dimensions, the dot product is a1 times b1, plus a2 times b2, and so on up to an times bn. Take a = (1, 2, 3) and b = (4, 5, 6). The products are 4, 10 and 18, and their sum is 32. That is the dot product. It is also called the inner product, and vector databases often label it IP.

There is a geometric reading that explains its behaviour. The dot product equals the length of a, times the length of b, times the cosine of the angle between them. When two vectors point the same way, the cosine is 1 and the dot product is as large as their lengths allow. When they are at right angles, it is zero. When they point in opposite directions, it is negative. Length and direction are both in the score, multiplied together.

For an embedding with hundreds or thousands of dimensions, the calculation is the same, with more terms. It needs one multiplication and one addition per dimension and nothing else, which makes it the cheapest of the common similarity measures.

Dot product vs cosine similarity

Cosine similarity is the dot product divided by the product of the two vectors’ lengths. Dividing out the lengths leaves only the angle, so cosine similarity always falls between minus one and one and ignores how long the vectors are. The dot product keeps the lengths in.

When every vector has length one, the division changes nothing, and the two measures are identical. Many embedding models return normalised vectors for exactly this reason: the system can store them once, use the fast dot product at query time, and get cosine rankings. If you normalise vectors yourself, do it for both stored items and queries, or the scores will be skewed.

When vectors are not normalised, the two measures can rank results differently. A short vector pointing exactly at the query has a cosine similarity of 1, but its dot product may be smaller than that of a longer vector pointing slightly away. Which behaviour you want depends on what vector length means in your data.

When vector length carries meaning

In some systems, length is information rather than noise. Recommendation models often learn item vectors whose length reflects popularity or general appeal, so a dot product naturally favours items that are both relevant and widely liked. Some retrieval models are trained with a dot product objective and learn to encode something like confidence or informativeness in the length of each passage vector. In those cases, normalising the vectors throws away part of what the model learned.

In other systems, length is an artefact. If longer documents produce longer vectors simply because they contain more text, the dot product will push long documents up the rankings regardless of relevance. The safest rule is to use the similarity measure the model was trained with, which its documentation will state. For most general-purpose text embedding models that means cosine similarity or a dot product over normalised vectors, which comes to the same thing.

Sparse vectors are a case where the dot product is the natural choice. In learned sparse models such as SPLADE, each dimension is a vocabulary term with a weight, and the dot product of query and document vectors adds up the weights of the terms they share. That is close in spirit to how keyword scoring works, and it is computed efficiently over an inverted index.

A worked example

Suppose the query vector is q = (1, 1) and there are four stored vectors. The table shows how the two measures rank them.

Vector

Dot product with q

Cosine similarity with q

d1 = (2, 2)

4

1.00

d2 = (3, 0)

3

0.71

d3 = (0.5, 0.5)

1

1.00

d4 = (4, 1)

5

0.86

By dot product, the order is d4, d1, d2, d3. By cosine similarity, d1 and d3 tie for first, followed by d4 and then d2. The vector pointing exactly at the query, d3, comes last by dot product because it is short, and d4 wins because it is long, even though it points slightly away. If these vectors were normalised first, both measures would give the cosine ranking. This is the whole difference between the two, in four rows.

Maximum inner product search

Finding the stored vectors with the highest dot product against a query is called maximum inner product search (MIPS). It is the dot product version of k-nearest neighbours search, and at scale it is done approximately with the same index families used for other measures: HNSW graphs, IVF clustering and quantised codes, all covered under approximate nearest neighbour search.

There is one technical wrinkle. The dot product is not a true distance: a vector’s dot product with itself is not necessarily its highest score, and the triangle inequality does not hold. Some index algorithms rely on those properties. Libraries handle this either by supporting inner product directly or by transforming the vectors, for example by adding one extra dimension so that maximum inner product search becomes an ordinary Euclidean distance search. FAISS and most vector databases support inner product as a first-class option, and with normalised vectors the issue disappears.

Why the dot product is so fast

Because it is just multiplications and additions, the dot product maps directly onto the hardware built for machine learning. Comparing one query with a million stored vectors is a single matrix-vector product, and comparing a batch of queries is a matrix-matrix product. CPUs with vector instructions and GPUs both run these at very high throughput, which is why brute-force dot product search is practical for collections far larger than most people expect.

Compression makes it faster still. Storing vectors as 8-bit integers instead of 32-bit floats cuts memory by four and speeds up the arithmetic, usually with a small loss of accuracy. Binary quantisation goes further, reducing each dimension to a single bit so that comparisons become bit operations. These are forms of vector quantisation, and systems that use them often re-score a shortlist with full-precision dot products before returning results.

The dot product inside language models

The same operation sits at the centre of the transformer. In the attention mechanism, each token produces a query vector and a key vector, and the model computes the dot product of every query with every key to decide how much attention each token pays to each other token. The scores are divided by the square root of the vector size, which keeps them in a range where the softmax step behaves well, a variant known as scaled dot product attention. Retrieval and attention are, at this level, the same idea: score relevance with a dot product, then take the highest scores.

Common pitfalls

The most common mistake is a mismatch between the measure used to train the model and the measure used by the index. A model trained for cosine similarity queried with an unnormalised dot product, or the reverse, returns plausible-looking results that are quietly worse. The second is treating raw dot product scores as if they had a fixed scale. Unlike cosine similarity, they are unbounded, and a threshold that works for one model or one collection will not transfer to another.

The third is expecting high similarity to mean relevance. Like every embedding measure, the dot product finds what is close in the model’s space, and close is not the same as correct; see similarity isn’t relevance. This is why production retrieval adds keyword matching through hybrid search and a reranking step that reads the query and candidate together, often with a cross-encoder. The difference between scoring separately embedded vectors and reading pairs together is covered in bi-encoder vs cross-encoder.

Where Exabase fits

Exabase handles the similarity layer so you do not choose or tune it. Content stored as Resources is extracted and indexed automatically, and Deep Search runs retrieval with hybrid text search by default, combining semantic search with typo-tolerant keyword matching. Results come back as passages with page numbers or timestamps and a relevance score per hit and per chunk, and the precision parameter (0 to 1, default 0.3) sets how strict the results are. The searching resources guide shows the request shape.

Memory search works the same way for what an agent has learned about a user: hybrid semantic and keyword search with recency bias, optional query expansion into several retrieval passes, and reranking of up to 500 candidates, through the memory search endpoint. Exabase is the retrieval substrate in both cases; how results are used is up to your application. For how this improves answer quality in a RAG pipeline, see RAG accuracy. If you are comparing it with running your own index, Exabase vs Pinecone and Pinecone alternatives cover the trade-offs.

Frequently asked questions

What is dot product similarity?

Dot product similarity is a score found by multiplying the matching coordinates of two vectors and adding the results. Higher scores mean more similar vectors, and the score grows with both their alignment and their length.

Is dot product the same as cosine similarity?

Only for normalised vectors. Cosine similarity is the dot product divided by the two vectors’ lengths, so when both have length one the scores are identical.

When should I use dot product instead of cosine similarity?

Use the dot product when your embedding model was trained with it, or when vectors are normalised and you want the faster calculation. Use cosine similarity when vector length is an artefact you want to ignore.

Can a dot product be negative?

Yes. A negative dot product means the two vectors point in broadly opposite directions. Zero means they are at right angles.

What is maximum inner product search?

Maximum inner product search finds the stored vectors with the highest dot product against a query. It is the dot product form of nearest neighbour search and is supported by most vector databases and libraries such as FAISS.

Why are my dot product scores larger than one?

Dot product scores are unbounded when vectors are not normalised, so they can exceed one. Normalise the vectors if you need scores on a fixed scale.

Do I need to choose between dot product and cosine in Exabase?

No. Exabase indexes stored content automatically and Deep Search handles scoring, so you control results with the precision parameter rather than a similarity metric.

Related pages: Cosine similarity, Euclidean distance, K-nearest neighbours, Embedding, Sparse vectors, Attention mechanism, Vector search, Binary quantisation, Deep Search

Cut your token spend and give your agent precise context.

Get started in minutes.

Cut your token spend and give your agent precise context.

Get started in minutes.