A similarity score is not a probability

Embeddings, cosine normalization and compatible model versions

Dot product and cosine can rank the same vectors differently. Similarity also depends on compatible encoders, normalization and versioning.

“The request was sent twice” and “prevent duplicate operations” may describe related problems without sharing the words a keyword search expects. A text encoder can represent each passage as a fixed-dimensional vector, allowing retrieval by a learned geometry.

The geometry reflects the model's training objective and data. Individual coordinates need not have human-readable labels.

Build an index, then encode the query

Compute document embeddings ahead of time and store them with passage identifiers. At query time use the compatible query encoder and score candidates. Retrieval can return the original passage; generating an answer is a separate step.

Some models distinguish query and document encoding or require particular prompts. Follow that contract.

Two metrics can rank differently

These are invented vectors, not measured model outputs. Let q=(1,0):

| Candidate | Vector | Length | Dot with q | Cosine with q | |---|---|---:|---:|---:| | A | (2,0) | 2 | 2 | 1 | | B | (3,4) | 5 | 3 | 0.6 |

The dot product sums componentwise products. It ranks B first because 3>2.

Cosine divides by the vectors' lengths: dot(q,B)/(length(q)×length(B)) = 3/5. It ranks A first because its direction matches q exactly. For nonzero vectors cosine lies between -1 and 1; a zero vector needs explicit handling.

What normalization buys, and removes

L2 normalization turns A into (1,0) and B into (0.6,0.8). Dot product on unit vectors equals cosine on the original vectors.

Normalization removes magnitude information. That is useful only if it matches the model's intended similarity metric. It is not an automatic improvement.

Equal dimensions do not imply compatible spaces

Two encoders can both return 384 numbers and use incompatible coordinate systems. Rotating both a query and its documents together preserves angles; rotating just one side does not.

Record encoder version, query/document encoding rules, normalization and metric beside the index. A model change generally requires re-encoding documents and evaluating the replacement before switching.

Similarity is not truth

A cosine score of 0.9 is not a 90% probability that a passage is correct or answers the question. Contradictory passages may share a topic and be close.

For a learning archive, similarity can nominate possible duplicates. Comparing objectives and mechanisms still matters: two TCP notes can use similar vocabulary and teach different things.

Try it

Multiplying B by ten increases its dot score from 3 to 30, while cosine stays 0.6. The text did not become more relevant; the metric responded to magnitude.

Tagged: ai, embeddings, retrieval, fundamentals

Area: AI

Related notes

עברית