timescale / pgvectorscale

A complement to pgvector for high performance, cost efficient vector search on large workloads.
PostgreSQL License
1.37k stars 58 forks source link

Support L2 distance #95

Closed xcu closed 1 week ago

xcu commented 5 months ago

Right now only cosine is supported, but it would be great to have support for L2 as well.

cevian commented 5 months ago

Please vote on this issue of there is interest. We are also happy to get PRs. Otherwise, we'll prioritize this on our roadmap too.

cevian commented 5 months ago

@xcu It would also be useful to know which models need this? i.e. why this is important for your use-case.

xcu commented 5 months ago

@cevian I am running some tests to extract faces and see how much one resembles to the other, so L2 comes pretty handy for this. So far I'm using pgvector for it with IVF, but I'd love to try pgvectorscale and see how recall/speed improves.

jonny-d commented 4 months ago

It would be nice to have squared L2 like faiss has https://github.com/facebookresearch/faiss/wiki/MetricType-and-distances#metric_l2

jonny-d commented 4 months ago

I have a document search task where the squared L2 distance in particular is important.

matan-airis commented 2 months ago

I'm seeing all kinds of support in the code for L2 distance alongside the cosine distance, what's actually missing in order to support L2 distance?

https://github.com/timescale/pgvectorscale/blob/04e1d1309b2e1c70e1e979c49d71b3f499cf5853/pgvectorscale/src/access_method/meta_page.rs#L179

https://github.com/timescale/pgvectorscale/blob/04e1d1309b2e1c70e1e979c49d71b3f499cf5853/pgvectorscale/src/access_method/distance.rs#L17

tjgreen42 commented 1 week ago

Support added in 0.5.0 release.