Distance Metrics
Mathematical formulas used to calculate similarity scores between vector coordinates.
Last reviewed: July 25, 2026
Distance metrics are the mathematical functions used to quantify how similar or dissimilar two vector embeddings are — the calculation that underlies every vector search, recommendation system, and semantic similarity comparison. Choosing the right distance metric for a given embedding model and use case has a direct, measurable effect on search quality, since different metrics can produce meaningfully different rankings for the same set of vectors.
Common Distance Metrics
Cosine similarity measures the angle between two vectors, ignoring their magnitude — it answers “do these vectors point in the same direction?” rather than “how far apart are they?” This makes it robust to differences in vector length that don’t carry semantic meaning, which is why it’s the default choice for most text embedding models.
Euclidean distance (L2 distance) measures the straight-line distance between two points in vector space, taking magnitude into account. It’s common in image embeddings and clustering algorithms where absolute distance is meaningful.
Dot product multiplies corresponding vector components and sums the results; it’s mathematically related to cosine similarity but also incorporates vector magnitude, and is favored in some retrieval systems for being cheaper to compute at scale.
Why the Choice Matters
Embedding models are trained with a specific distance metric in mind — using a mismatched metric at query time (say, Euclidean distance on a model trained with cosine similarity in its contrastive loss) can silently degrade retrieval quality without producing an obvious error. Vector databases like Pinecone, Qdrant, and Milvus let users configure which metric an index uses, and that choice should generally match the documentation of whichever embedding model produced the vectors being indexed.
Manhattan Distance and Other Less Common Metrics
Beyond cosine similarity, Euclidean distance, and dot product, some specialized applications use Manhattan distance (also called L1 distance), which sums the absolute differences between corresponding vector components rather than the squared differences Euclidean distance uses — it’s less sensitive to large individual outlier differences between two vectors, which can be useful in specific high-dimensional settings, though it’s considerably less common than the three primary metrics in mainstream vector search and embedding applications. Hamming distance, which counts the number of positions at which two vectors differ, is used specifically for binary embeddings (a compression technique that represents each dimension as a single bit rather than a full floating-point value), trading substantial accuracy for extremely fast comparison and minimal storage, a niche but growing technique for extreme-scale vector search where storage cost is the dominant constraint.
Historical figures and technical concepts for informational purposes only. Not technical, professional, legal, or financial advice. Sources: Official Documentation.