From: jkatz (@jkatz) <noreply+jkatz@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #461: Increase max vectors dimension limit for index
Date: Sat, 21 Sep 2024 14:51:05 +0000
Message-ID: <gh-pgvector-pgvector-461-c2365214688@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-461@github.com>
References: <gh-pgvector-pgvector-461@github.com>
@lmaddox @t-zuehlsdorff This isn't entirely accurate, though the indexing portion will come with a tradeoff of losing precision (and possibly recall).
With pgvector 0.7.0, you can use [binary quantization](https://jkatz05.com/post/postgres/pgvector-scalar-binary-quantization/) to store vectors over 2K/4K dimensions, e.g., though you will almost definitely need to re-rank, e.g.:
```sql
CREATE TABLE your_table (
-- ...
embedding vector(4096)
-- ...
);
CREATE INDEX ON your_table
USING hnsw ((binary_quantize(embedding)::bit(4096)) bit_hamming_ops);
-- query
SELECT i.id
FROM (
SELECT id, embedding <=> $1 AS distance
FROM items
ORDER BY binary_quantize(embedding)::bit(4096) <~> binary_quantize($1)
LIMIT 100 -- in v0.7.x, recommend setting to your value of `hnsw.ef_search`
) i
ORDER BY i.distance
LIMIT 10;
```
(With some of the work in [hnsw-streaming](https://github.com/pgvector/pgvector/tree/hnsw-streaming), the guidance may change on the `LIMIT`/`hnsw.ef_search` ratio in the subquery).
But this will at least help you benefit from using the index, though you likely have to use a higher `hnsw.ef_search` to get acceptable recall.