You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Essentially, BQ converts any vector embedding of floating point numbers into a vector of binary or boolean values.
In exchange for reducing our 32 bit embeddings to 1 bit embeddings we can see up to a 40x retrieval speed up gain!
One of the reasons vector search still works with such a high compression rate is that these large vectors are over-parameterized for retrieval. This is because they are designed for ranking, clustering, and similar use cases, which typically need more information encoded in the vector.
This is just another form of product quantization -- it could be interesting, but requires testing. The biggest tradeoff (as mentioned in the article) is the impact to recall, which requires searching over a larger space to get a better representative set of the approximated results. There's also testing to see how this would work given how PostgreSQL stores data on disk, as the benefit would be towards minimizing the number of pages loaded into memory during an index scan, which is not necessarily correlated to vector size.
Hey @nileshtrivedi, thanks for sharing! I'm not sure it's common enough to include at this point, but seems like it'd be simpler to implement and use than scalar or product quantization, so may try it out in a branch.
@ankane I think this will be become really relevant in the future. Cohere is providing binary embeddings out of the box. We are working on a novel form of binary quantization. I think this could work well with #429.
Support is now available in the bitvector branch for anyone who wants to try it (in a non-production environment).
CREATETABLEitems (id bigserialPRIMARY KEY, embedding vector(3));
INSERT INTO items (embedding) VALUES ('[1,-2,3]'), ('[-4,5,-6]');
CREATEINDEXON items USING hnsw ((quantize_binary(embedding)::bit(3)) bit_hamming_ops);
-- no re-rankingSELECT id FROM items ORDER BY quantize_binary(embedding)::bit(3) <~> quantize_binary('[1,-2,3]') LIMIT5;
-- re-rankingSELECT id FROM (
SELECT*FROM items ORDER BY quantize_binary(embedding)::bit(3) <~> quantize_binary('[1,-2,3]') LIMIT20
) ORDER BY embedding <=>'[1,-2,3]'LIMIT5;
Reacted by Nilesh, Pierre Dulac and Farzad Sunavala
Activity
jkatz commentedon Jan 4, 2024
This is just another form of product quantization -- it could be interesting, but requires testing. The biggest tradeoff (as mentioned in the article) is the impact to recall, which requires searching over a larger space to get a better representative set of the approximated results. There's also testing to see how this would work given how PostgreSQL stores data on disk, as the benefit would be towards minimizing the number of pages loaded into memory during an index scan, which is not necessarily correlated to vector size.
ankane commentedon Jan 8, 2024
Hey @nileshtrivedi, thanks for sharing! I'm not sure it's common enough to include at this point, but seems like it'd be simpler to implement and use than scalar or product quantization, so may try it out in a branch.
aamir-s18 commentedon Jan 27, 2024
@ankane I think this will be become really relevant in the future. Cohere is providing binary embeddings out of the box. We are working on a novel form of binary quantization. I think this could work well with #429.
ankane commentedon Mar 27, 2024
Support is now available in the
bitvectorbranch for anyone who wants to try it (in a non-production environment).ankane commentedon Mar 27, 2024
You can also store binary embeddings directly.
ankane commentedon Apr 2, 2024
Support for binary quantization been merged (94a444f) and will be included in 0.7.0 (#508). Thanks for the suggestion @nileshtrivedi!
nileshtrivedi commentedon Apr 4, 2024
@ankane Thanks! This looks great. 👏
With the

vectortype (instead of sayvector(3)), I am able to store vectors of different dimensions in the same column.To get the same flexibility, can/should I store binary embeddings in a column of type
bytea?ankane commentedon Apr 4, 2024
You can use
bit varying/varbit.