Similarity is an angle, not a distance traveled.

Embedding models map text into high-dimensional vectors. Rotate a query through a teaching projection, change its magnitude, and watch cosine ranking separate semantic direction from raw vector length.

Enter the vector field
cos θ
0.98best cosine
11°nearest angle
1.00query norm
emailnearest concept

Embeddings turn retrieval into geometry.

Direction

Cosine similarity compares the angle between vectors. Parallel vectors score 1, orthogonal vectors 0, and opposite vectors -1.

cos(a,b) = a·b / (||a|| ||b||)

Normalization

Unit normalization removes magnitude. After normalization, maximizing dot product is equivalent to maximizing cosine similarity.

â = a / ||a||

Nearest neighbors

Retrieval ranks stored vectors by a selected metric. Approximate indexes trade exact ranking for lower latency at large scale.

top-k = argmax sim(q, xᵢ)

Read retrieval failures geometrically.

Magnitude bias

Raw dot product rewards both alignment and vector length. If model norms vary for reasons unrelated to relevance, long vectors can outrank better-aligned short vectors. Normalize when cosine semantics are intended.

Projection is only a teaching view

Production embeddings often have hundreds or thousands of dimensions. This 3D field preserves designed relationships, but PCA, UMAP, or t-SNE projections can distort distances and neighborhoods.

Similarity is not truth

A close vector means the encoder considers two inputs similar under its training objective. Retrieval still needs metadata filters, reranking, provenance, and evaluation against the task.

Practical questions

Why does changing magnitude leave cosine ranking unchanged?

Positive scaling multiplies both the dot product and vector norm by the same factor, so they cancel in cosine similarity.

When should I use Euclidean distance?

Use it when absolute geometry and magnitude are meaningful or when the embedding model was trained for L2 distance. Match the production metric to the model’s training and index configuration.

Can unrelated text have high cosine similarity?

Yes. Dense encoders compress information, and domain shift or short ambiguous inputs can collide. Evaluate hard negatives and add reranking where mistakes matter.

Primary sources

Mikolov et al. (2013) established efficient distributed word representations. Reimers and Gurevych (2019) introduced Sentence-BERT for cosine-searchable sentence embeddings. Karpukhin et al. (2020) demonstrated dense passage retrieval. FAISS documentation explains similarity-search indexing and metrics.