A vector comparison answers a practical question: how alike are these two numerical representations? The answer depends on the rule used to compare them.
Vector representations turn text, images, and other inputs into lists of numbers. Search and ranking systems then use a distance or similarity measure to decide which stored vectors are closest to a query.
Four common choices are cosine distance, Euclidean distance, Manhattan distance, and dot product. They use the same numbers but pay attention to different geometric properties.
The direction of the score matters. For Euclidean, Manhattan, and cosine distance, lower means closer. For cosine similarity and dot product, higher means more similar.
One pair of vectors, four views
Use the same two-dimensional vectors throughout this article:
A = [1, 1]
B = [4, 3]
The diagrams below show what each comparison measures. Production embeddings usually have hundreds or thousands of dimensions, but the calculations extend in the same way.
Euclidean distance
3.61Measures the shortest straight-line gap between the points.
Manhattan distance
5Adds the movement along each axis: 3 across plus 2 up.
Cosine distance
0.010Compares direction. Different lengths matter very little here.
Dot product
7Combines alignment with magnitude. Longer aligned vectors score higher.
Euclidean distance: the straight-line gap
Euclidean distance is the ordinary distance between two points. Subtract each coordinate, square the differences, add them, and take the square root.
distance(A, B)
= sqrt((4 - 1)^2 + (3 - 1)^2)
= sqrt(9 + 4)
= sqrt(13)
= 3.61
Euclidean distance pays attention to both direction and magnitude. If two vectors point in the same direction but one is much longer, they can still be far apart.
This measure is useful when absolute position and scale carry meaning. It is also common in clustering and nearest-neighbor methods. However, it can behave poorly if some dimensions use much larger numeric scales than others. Standardize feature columns when each dimension should contribute on a comparable scale. That is different from vector normalization, which rescales each whole vector to length 1.
Manhattan distance: movement along the axes
Manhattan distance adds the absolute difference in every dimension. Its name comes from moving through a street grid instead of cutting diagonally through buildings.
distance(A, B)
= abs(4 - 1) + abs(3 - 1)
= 3 + 2
= 5
In a larger vector, the same rule simply continues across every coordinate. Manhattan distance can be useful when changes happen independently along dimensions, or when axis-by-axis movement is a better model than a straight line.
Euclidean and Manhattan distance can rank candidates differently. Euclidean distance rewards a direct diagonal route. Manhattan distance charges for every coordinate change separately.
Manhattan distance is common in some tabular and operations problems, but it is rarely the first choice for dense text embeddings. Text embedding systems usually document cosine, dot product, or Euclidean-style indexing instead.
Cosine distance: the angle between directions
Cosine similarity compares the angle between two nonzero vectors. It divides the dot product by both vector lengths:
cosine_similarity(A, B)
= (1 * 4 + 1 * 3) / (sqrt(2) * 5)
= 7 / 7.071
= 0.990
cosine_distance(A, B)
= 1 - cosine_similarity(A, B)
= 0.010
A cosine similarity near 1 means the vectors point in nearly the same direction. A cosine distance near 0 therefore means they are close by angle.
This is often useful for text embeddings because direction can represent meaning while vector length may be less important. Multiplying a vector by a positive number does not change its cosine similarity:
[1, 1] and [10, 10] have cosine distance 0
Cosine comparison is undefined for a zero vector because a zero vector has no direction. A production system should handle that case explicitly instead of returning a confident score.
Dot product: alignment multiplied by length
The dot product multiplies matching coordinates and adds the results:
dot(A, B)
= (1 * 4) + (1 * 3)
= 7
Despite phrases such as “dot product distance,” the dot product itself is a similarity score, not a mathematical distance. Larger values usually rank as more similar. Some search systems convert it into a value to minimize, such as the negative dot product, but that converted score still does not have all the properties of a true distance metric.
The dot product rewards both:
- Alignment: vectors pointing in similar directions.
- Magnitude: longer vectors can produce larger scores.
That makes it useful when the embedding model intentionally stores information in vector length. It can also create surprising rankings when magnitude is not meaningful. The score can be negative when vectors point against each other, and it is unbounded: longer aligned vectors can keep producing larger values.
In the diagram above, “projection” means the shadow one vector casts along another vector’s direction. The dot product grows when that shadow points the same way and gets longer.
Why normalization changes the answer
Normalization rescales every nonzero vector to length 1 without changing its direction. After normalization:
- Dot product and cosine similarity are equal.
- Cosine ranking and dot product ranking are equal.
- Euclidean distance produces the same nearest-neighbor ordering as cosine distance only when every vector, including the query, is unit-normalized.
For unit vectors, the relationship is:
euclidean_distance^2 = 2 * cosine_distance
This does not mean the metrics are always interchangeable. It means they become closely related under the specific condition that every vector has length 1.
Choosing a metric
Do not pick a metric only because it is familiar or fast. Start with the embedding model’s documentation and the behavior your application needs.
- Choose cosine distance when direction matters and magnitude should mostly be ignored.
- Choose Euclidean distance when absolute geometric separation matters.
- Choose Manhattan distance when independent coordinate changes or grid-like movement fit the problem.
- Choose dot product when the model was trained for it or vector magnitude carries useful signal.
In practice, use this checklist:
- Use the metric the embedding model documents or evaluates with.
- Make the vector database index metric match that choice.
- Normalize vectors consistently at index time and query time, or do not normalize at all.
- Evaluate with recall@k on labeled queries before trusting demo results.
- Check the database’s names: “L2” usually means Euclidean distance, “inner product” usually means dot product, and “cosine” may mean either similarity or distance depending on the API.
Then evaluate the choice with real queries and expected results. A mathematically valid metric can still be wrong for a particular model, dataset, or product.
The key idea
Distance metrics do not discover meaning by themselves. They define what “close” means after a model has created the vectors. Euclidean distance measures a straight line, Manhattan distance adds axis-by-axis movement, cosine distance compares direction, and the dot product combines direction with length.
The best metric is the one that matches how the vectors were produced and what the application needs to rank.