From: michaelbautin (@michaelbautin) <noreply+michaelbautin@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #729: User-defined distance functions
Date: Tue, 10 Dec 2024 02:29:54 +0000
Message-ID: <gh-pgvector-pgvector-729-c2530082234@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-729@github.com>
References: <gh-pgvector-pgvector-729@github.com>
I thought it would be great to override the distance function at least during prototyping/testing of user apps, and even evaluating various approaches for improving pgvector itself, for example, implementing product quantization outside of pgvector. A distance function could treat each coordinate of a uint8 vector as a centroid in a product quantization subspace, and the result would be computed based on such centroids of two quantized vectors. But I guess that specific use case would require support for int8/uint8 vectors first.
In general, however, algorithms such as HNSW do not even require elements to be vectors. All that is required is a way to compute distance between two elements. For example, the [usearch](https://github.com/unum-cloud/usearch) C++ library fully abstracts the distance function. Postgres is not C++, of course, but it is also very extensible. Users are certainly very comfortable defining their own functions.