Skip to content

Support binary quantization #69

@Kerollmops

Description

@Kerollmops

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 🤔

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions