What is a non-metric dissimilarity function?
A non-metric dissimilarity function is any measure of how different two things are that fails at least one of the four properties required of a true metric space — non-negativity, identity of indiscernibles, symmetry, or the triangle inequality — while still being genuinely useful for ranking or comparing vectors in practice.
Which property does a non-metric dissimilarity function usually fail, and why does that happen?
The triangle inequality, covered elsewhere in this glossary, is the property most commonly violated, since it’s the strictest and most specific of the four requirements a distance function has to satisfy to qualify as a true metric. A dissimilarity function can be perfectly well-behaved in every other respect — never negative, zero only for identical inputs, symmetric in both directions — and still occasionally produce a case where measuring directly between two points gives a larger value than measuring through some third point, which is all it takes to disqualify it as a formal metric. This tends to happen with measures built around specialized statistical or domain-specific reasoning rather than pure geometric distance, where the calculation was designed to capture a particular kind of difference rather than to satisfy an abstract mathematical property.
Does failing to be a true metric actually make a dissimilarity function worse for vector search?
Not necessarily — HNSW is fundamentally an approximate, empirically-tuned algorithm, and plenty of practical systems get excellent results using dissimilarity functions that don’t fully satisfy metric space properties. What’s lost is some of the theoretical reasoning about why the search behaves reliably, covered in this site’s page on the triangle inequality, since that reasoning depends specifically on the property holding true. In practice, this usually shows up as needing to rely more heavily on empirical testing and tuning to confirm a system performs well, rather than being able to lean on a formal guarantee that it must.
How should someone decide whether a non-metric dissimilarity function is still the right choice?
The decision usually comes down to whether the dissimilarity function captures the actual notion of “similar” that matters for the task at hand, even at the cost of the cleaner guarantees a true metric would provide. A specialized measure built for a specific kind of data, such as comparing probability distributions or capturing domain-specific structure, might reflect what “similar” really means for that data far better than forcing the comparison into a geometric distance that happens to satisfy the triangle inequality but doesn’t actually match the problem. Evaluating this in practice, covered in this site’s coverage of evaluation and benchmarking, by testing real recall and quality against a known ground truth, is generally a more reliable guide than the abstract question of whether the underlying function is technically a metric.
Non-metric dissimilarity functions occupy the practical middle ground between the clean guarantees of a true metric space and the reality that some of the most useful similarity measures don’t fully satisfy those guarantees. From here, the pages on metric space and on the triangle inequality lay out exactly what properties are being traded away, and the evaluation and benchmarking section covers how to judge whether that trade-off is working out in practice.