What does symmetry mean for a distance function?
Symmetry means a distance function gives back the exact same value no matter which of the two points it’s asked to measure from first, so the distance from point A to point B is always identical to the distance from B to A — a property that seems obvious for physical distance but is worth checking explicitly for the distance functions used in vector search.
Why would a distance function ever fail to be symmetric?
Physical distance between two locations is symmetric almost by definition — walking from one point to another covers the same ground as walking back. Some measures of dissimilarity between vectors don’t share this property, though, particularly ones built around asymmetric statistical ideas like measuring how well one distribution predicts another, where swapping which distribution is treated as the reference and which is treated as the comparison changes the result. A distance function like this can still be useful for certain tasks, but it means the order in which two vectors are passed into the function actually matters, which is a meaningfully different situation from the distance functions covered elsewhere in this glossary, like Euclidean distance or cosine distance, where order never matters at all.
Why does symmetry matter for how HNSW actually builds and searches its graph?
HNSW’s graph-building process, covered in this site’s coverage of how the algorithm constructs its layered structure, relies on comparing candidate vectors to decide which connections belong in the graph, and search relies on the same kind of comparison to decide which direction to move next. If distance from A to B could differ from distance from B to A, the graph’s edges would need to specify a direction for every connection, along with which distance value applies which way, adding real complexity to both construction and search. A symmetric distance function keeps every edge in the graph meaning the same thing regardless of which vector is treated as the starting point, which is exactly why HNSW is built around symmetric distance functions in virtually every practical implementation.
Where would an asymmetric measure actually still make sense to use?
Asymmetric measures show up in contexts where the two things being compared genuinely play different roles rather than being interchangeable, such as comparing a specific document against a broader reference distribution, where the direction of comparison reflects a real conceptual difference and not just a technical inconvenience. These situations are the exception rather than the rule for vector search, where a query and a stored vector are usually being compared as if they were two points that could just as easily be swapped, which is exactly the scenario symmetry was built to describe. Recognizing whether a task genuinely calls for an asymmetric measure, or is just being handed one out of habit, is part of choosing the right distance function for a given kind of data, covered elsewhere on this site.
Symmetry is one of the properties that separates a well-behaved metric, covered in this glossary’s page on metric space, from a more general dissimilarity measure that might still be useful but comes with fewer guarantees. From here, the pages on metric space and on non-metric dissimilarity functions round out this glossary’s coverage of what makes a distance function well-behaved.