Skip to content
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

Avoid negative distances when using E4M3 cosine indices by renormalizing. #75

Closed
wants to merge 9 commits into from

Conversation

psobot
Copy link
Member

@psobot psobot commented Jul 26, 2024

No description provided.

@dylanrb123 dylanrb123 marked this pull request as ready for review July 30, 2024 16:24
@dylanrb123
Copy link
Contributor

@psobot I fixed the java tests and included a version bump/doc gen commit. LMK if you want me to do the latter in a separate PR.

Copy link
Member Author

@psobot psobot left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @dylanrb123!

Just to talk through the implications of this change:

  • Existing indices could have returned zero distances during queries due to precision errors when computing inner product
  • With this change, querying existing Cosine E4M3 indices with new vectors can now return negative distances, as the normalized vectors within them will not be re-normalized. Distances will be slightly increased as the query vector is properly normalized, however.
  • Newly-created indices after this change lands will never return negative distances.

One last thing I'm worried about: this change also potentially introduces quality loss when fetching a vector from the index and then passing it back in, as the vector will be re-normalized and normalize<E4M3>(x) is not idempotent. That might be something we want to think through carefully before landing this change.

@psobot
Copy link
Member Author

psobot commented Jul 31, 2024

Closing in favour of #80 due to reduced recall of this approach.

@psobot psobot closed this Jul 31, 2024
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