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

Support binary quantization #69

Closed
Kerollmops opened this issue Mar 11, 2024 · 1 comment · Fixed by #82
Closed

Support binary quantization #69

Kerollmops opened this issue Mar 11, 2024 · 1 comment · Fixed by #82
Labels
enhancement New feature or request
Milestone

Comments

@Kerollmops
Copy link
Member

Kerollmops commented Mar 11, 2024

It would be great to support binary quantization in arroy. The main principle is to convert the dimensions values x <= 0 to 0 and x > 0 to 1. This way, we can represent the quantized vector with 32x less space and compute the distances in a much faster and CPU-friendly way. We are currently limited to something like 15M (float 32bit, 768dims) on a 63GiB machine, but with binary quantization, we can go up to 480M vectors on the same machine.

Here is an example of implementing the Euclidean distance with binary data. Here is the formula: $\sqrt{(p1-q1)^2+(p2-q2)^2}$.
This means that computing the difference at the power of two is equivalent to a xor:
$(0-1)^2 = (-1)^2 = 1$
$(1-0)^2 = 1^2 = 1$
$(0-0)^2 = 0$
$(1-1)^2 = 0$

Ultimately, the Euclidean operation is the sum of the XORed dimensions of both vectors squared: $\sqrt{(p1 \bigoplus q1)+(p2 \bigoplus q2)}$. All the necessary operations can be SIMD-optimized or maybe using the u8::BitXor and u8::count_ones methods will be SIMD-optimized by itself 🤔

@Kerollmops Kerollmops added the enhancement New feature or request label Mar 11, 2024
@sorenbs
Copy link

sorenbs commented Jun 12, 2024

I would love to see this!

Here is mixedbread.ai talking about the benefits: https://www.mixedbread.ai/blog/binary-mrl

@Kerollmops Kerollmops linked a pull request Aug 26, 2024 that will close this issue
@irevoire irevoire added this to the v0.4.0 milestone Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants