8000 Support for inner product distance metric by tjgreen42 · Pull Request #167 · timescale/pgvectorscale · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support for inner product distance metric #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 26, 2024
Merged

Support for inner product distance metric #167

merged 9 commits into from
Nov 26, 2024

Conversation

tjgreen42
Copy link
Contributor
@tjgreen42 tjgreen42 commented Nov 19, 2024

Description

This PR adds support for negative inner product as a distance metric, which rounds out the de-facto standard set for ANN vector search: L2, cosine, and inner product. (We use negative inner product for the same postgres reasons as pgvector does.) We continue to follow pgvector syntax: so, <#> for the distance operator, and vector_ip_ops for the operator class name.

Some further details about the PR:

  • Cosine calculations refactored to expose (vectorized) inner product
  • For now, disallow use of inner product with plain storage. This is to keep distances positive in the core index pruning code.

Testing

  • I extended the unit tests that take DistanceType as a parameter to include DistanceType::InnerProduct
  • I added a unit test sanity-checking that inner product is really being used when requested

References

Design doc: https://timescale.slab.com/posts/distance-metrics-for-pgvectorscale-atrovg6n?shr=NaR3yhZgvzEx6SixcBHwKsqV

Feature request: #96

@tjgreen42 tjgreen42 requested a review from a team as a code owner November 19, 2024 19:25
@tjgreen42 tjgreen42 marked this pull request as draft November 19, 2024 21:23
@tjgreen42 tjgreen42 changed the title [WIP] Support for inner product distance metric Support for inner product distance metric Nov 21, 2024
Signed-off-by: tjgreen42 <tj@timescale.com>
@tjgreen42 tjgreen42 requested review from cevian and syvb November 21, 2024 01:38
@tjgreen42 tjgreen42 marked this pull request as ready for review November 25, 2024 17:09
Copy link
Collaborator
@cevian cevian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except 1 comment below

@tjgreen42 tjgreen42 merged commit b550fbb into main Nov 26, 2024
24 checks passed
@tjgreen42 tjgreen42 deleted the tj_inner_product branch November 26, 2024 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0