What is inner product?

Inner product (dot product) multiplies two vectors dimension by dimension and sums the results, reflecting both directional alignment and vector magnitude, unlike cosine similarity.
Created: Updated: 3 min read

Inner product, also called dot product, multiplies two vectors dimension by dimension and adds up the results, producing a single number that reflects both how aligned the two vectors’ directions are and how large their magnitudes are, unlike cosine similarity, which discards magnitude entirely.

How is inner product actually calculated between two vectors?

For each dimension, multiply the two vectors’ values in that dimension together, then add up all of these products across every dimension. The result is larger when the two vectors point in a similar direction and both have larger magnitudes, and smaller — or negative — when the vectors point in different directions or have smaller magnitudes, combining directional alignment and scale into a single number rather than measuring either one separately.

Why does inner product care about magnitude when cosine similarity doesn’t?

Cosine similarity, covered elsewhere in this glossary, divides the inner product by the product of both vectors’ lengths specifically to remove magnitude from the comparison, leaving only the angle between them. Inner product skips this division step, which means a longer vector pointing in a similar direction can produce a larger inner product than a shorter vector pointing in exactly the same direction — the extra length genuinely adds to the result rather than being normalized away. This makes inner product the right tool whenever a vector’s magnitude was deliberately trained to carry meaning, rather than being an incidental detail that should be ignored during comparison.

When does inner product become the right choice over cosine similarity?

Recommendation systems, covered in this site’s page on how HNSW is used inside recommendation systems, are the clearest example: an item’s embedding length might meaningfully reflect its overall popularity or the model’s confidence in that representation, information a system genuinely wants to influence the final ranking rather than discard. Maximum inner-product search, or MIPS, is the name given to nearest-neighbor search specifically built around this measure, and it’s worth noting that when every vector being compared has already been normalized to the same length, ranking by inner product produces exactly the same ordering as ranking by cosine similarity — the two only diverge once vectors are allowed to have genuinely different magnitudes.

Inner product sits alongside cosine similarity and Euclidean distance as one of the three comparisons covered throughout this site’s discussion of measuring distance and similarity between vectors. From here, the page on maximum inner-product search covers the specific search problem built around this measure in more depth.