A Triangle Inequality for Cosine Similarity

Erich Schubert
7/8/2021
cs.LGcs.DB

Official code: elki-project/elki (833 stars, Java, AGPL-3.0, last commit 2026-04-09).

Abstract

Similarity search is a fundamental problem for many data analysis techniques. Many efficient search techniques rely on the triangle inequality of metrics, which allows pruning parts of the search space based on transitive bounds on distances.

Show full abstract

Recently, Cosine similarity has become a popular alternative choice to the standard Euclidean metric, in particular in the context of textual data and neural network embeddings. Unfortunately, Cosine similarity is not metric and does not satisfy the standard triangle inequality. Instead, many search techniques for Cosine rely on approximation techniques such as locality sensitive hashing. In this paper, we derive a triangle inequality for Cosine similarity that is suitable for efficient similarity search with many standard search structures (such as the VP-tree, Cover-tree, and M-tree); show that this bound is tight and discuss fast approximations for it. We hope that this spurs new research on accelerating exact similarity search for cosine similarity, and possible other similarity measures beyond the existing work for distance metrics.

View on arXivView PDF

Code Implementations(1)

elki-project/elkiOfficial100%
AGPL-3.0

ELKI Data Mining Toolkit

833325Java, PythonMar 4, 20157 months agoAGPL-3.0
anomalydetectioncluster-analysisclusteringdata-analysisdata-mining+11 more

Similar Papers

Cite this paper

@article{schubert2021triangle,
  title  = {A Triangle Inequality for Cosine Similarity},
  author = {Erich Schubert},
  year   = {2021},
  eprint = {2107.04071},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2107.04071}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2107.04071.svg)](https://codeofpaper.com/paper/2107.04071)

Discussion