AI Glossary / Natural language and speech / Intermediate
Dot product
Definition
The dot product of two real-valued vectors is the sum of the products of their corresponding components. For vectors a and b with the same number of dimensions, a · b = a₁b₁ + a₂b₂ + ... + aₙbₙ. The result is one number, used widely in AI for weighted sums and vector comparisons.
What it means
Each pair of matching coordinates contributes to the final score. Positive and negative contributions can reinforce or cancel one another. The coordinates must be aligned: comparing the first feature of one vector with an unrelated feature in another makes the arithmetic possible but the interpretation unreliable.
In NLP, dot products can compare compatible embeddings or score how a feature vector aligns with learned weights. A larger value may represent a stronger match within a particular model, but it is not inherently a probability or a universal measure of semantic agreement.
Vector magnitude matters. Scaling one vector can change its dot product even when its direction stays the same.
How it works
Check that the vectors have matching dimensions and compatible representations. Multiply each component of one vector by the component in the same position in the other, then add those products.
Geometrically, the real Euclidean dot product equals the product of the two vector lengths and the cosine of their angle. This explains why both alignment and magnitude affect the value.
If both nonzero vectors are normalized to unit length first, their dot product equals cosine similarity. Without that normalization, raw dot product and cosine are different scores. A zero vector needs special handling for cosine because dividing by its length would be undefined.
Three practical examples
- A linear classifier combines a text feature vector with learned weights through a dot product before applying any bias or output transformation.
- An embedding-based retrieval system ranks compatible query and document vectors using a specified dot-product scoring rule.
- A neural-network computation uses many dot products as part of a matrix multiplication, producing weighted combinations of input features.
Think of it this way
Think of a shopping bill: multiply each quantity by its corresponding unit price and add the results. The quantities and prices form two aligned vectors, and the bill is their dot product. The analogy explains the arithmetic; AI coordinates often lack such direct meanings and may contain negative values.
Worked example
Take a = [2, −1, 3] and b = [4, 2, 0]. Their dot product is 2 × 4 + (−1) × 2 + 3 × 0 = 8 − 2 + 0 = 6. The componentwise product is [8, −2, 0], but the dot product is the scalar sum, 6.
Now multiply b by two to get c = [8, 4, 0]. The direction has not changed, yet a · c = 16 − 4 + 0 = 12. A raw score has doubled because the magnitude changed.
For comparison, the lengths are ||a|| = √14 and ||b|| = √20. Their cosine similarity is 6 / √280, approximately 0.359. For c, both the numerator and its length double, so the cosine remains approximately 0.359.
This calculation demonstrates why a retrieval system's choice between dot product and cosine must match its representation and training assumptions. It does not establish that these toy vectors encode any particular words or that one score is always preferable.
Illustrative case study
Fictional case: VectorShelf compares two configurations of a document search prototype. A developer changes from normalized vectors to unnormalized vectors while leaving the ranking explanation unchanged. Some documents receive much larger scores even though their vector directions have not changed.
The team checks vector norms and confirms that the scoring behavior now includes magnitude. It documents whether that magnitude is intended to carry useful information and evaluates retrieval quality under the chosen configuration.
The revised report names both the embedding representation and scoring rule. This fictional case illustrates an implementation mismatch; it does not claim that normalization always improves search or that raw dot product is inherently defective.
Common misconceptions and mistakes
Do not confuse the dot product with componentwise multiplication. The former sums the component products into one number.
Do not read an arbitrary dot-product score as a percentage or probability. Its scale depends on the vectors and any later transformation.
Avoid interpreting a zero dot product as universal semantic unrelatedness. It means orthogonality in the represented Euclidean space, and that representation may not capture every relevant meaning. Equal vector dimensions alone also do not guarantee compatible embedding spaces.
Business use
Understanding dot products helps teams interpret model scores and avoid misleading dashboards. It is relevant to search ranking, linear models, and neural-network computations even when the arithmetic is hidden inside a library.
A practical review asks whether vectors use the same feature ordering or compatible embedding space, whether normalization is applied, and whether score thresholds were evaluated under that exact configuration. Changing the representation or scale can invalidate a previously useful threshold without any change in the basic formula.
People also ask
Can a dot product be negative?
Yes. Negative component contributions can outweigh positive ones for real-valued vectors.
Is it the same as cosine similarity?
Only after appropriate unit-length normalization of nonzero vectors; raw dot product also depends on magnitude.
Does a high dot product prove two texts mean the same thing?
No. It reflects a score in a particular representation. Semantic equivalence requires evidence beyond an uncalibrated numerical value.
Check your understanding
A document vector is multiplied by three while its direction stays unchanged. What happens to its raw dot product with a fixed query vector?
Answer: The dot product is multiplied by three. Its cosine similarity with a nonzero query stays unchanged under this positive scaling, showing that the two scoring rules capture different aspects.
Related terms
- Vector
- Inner product
- Cosine similarity
- Embedding
- Weighted sum
- Linear model
- vector norm
- matrix multiplication
Learn next
Compute raw and normalized scores for a few small vectors, including negative components and a zero vector. Then inspect a retrieval system's documentation to identify which representation, normalization, and scoring rule it actually uses.
More in Natural language and speech
- Document-rotation denoising - Document-rotation denoising is a language-model pretraining task in which a document is cyclically shifted to start at a randomly chosen token, and the...
- Document structuring - Document structuring is the natural-language-generation task of organizing selected information into a coherent document.
- Document-term matrix - A document-term matrix is a numerical table representing documents through selected text features.
- Dynamic programming - Dynamic programming is a method for solving a problem by combining solutions to smaller subproblems and reusing their results.
- Dynamic time warping - Dynamic time warping, or DTW, aligns two sequences while allowing differences in their local timing.
- Edge-factored - Edge-factored describes a structured model whose score for a graph or tree decomposes into contributions from its individual edges.
Sources
Sources: Jurafsky and Martin, Speech and Language Processing, Embeddings, dot-product and cosine-similarity discussion: https://web.stanford.edu/~jurafsky/slp3/5.pdf Section5.4 equations5.7–5.10 and the non-probability warning were independently consulted. Original products, lengths and cosine approximation were recalculated.
Previous: Dot plot Next: Dot-product attention