From: txfs19260817 (@txfs19260817) <noreply+txfs19260817@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #1003: Support RabitQ in pgvector
Date: Mon, 09 Nov 2026 20:12:30 +0000
Message-ID: <gh-pgvector-pgvector-1003-c6750293448@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-1003@github.com>
References: <gh-pgvector-pgvector-1003@github.com>
Hi @ankane, I am Zishuo Ding from AWS. I work on PostgreSQL performance. These are my results for asymmetric BQ.
One-commit branches:
- [`asymmetric-bq`](https://github.com/txfs19260817/pgvector/tree/asymmetric-bq): As you suggested above, it adds the `bit_vector_ip_ops` operator class and a support function 4 in about 190 lines of src code.
- [`hnsw-quantization`](https://github.com/txfs19260817/pgvector/tree/hnsw-quantization): Another asymmetric BQ prototype that adds `WITH (quantization = ...)` to the existing operator classes. In this way, queries need no cast. It is about 260 lines of C src.
- Benchmarks across 6 datasets: [`benchmarks/doc`](https://github.com/txfs19260817/pgvector/tree/benchmarks/doc)
**8.8M MS MARCO**
Setup: 8.8M [MS MARCO](https://microsoft.github.io/msmarco/) with 960 dimensions, recall@10 of about 0.99, 8 clients, and r7i.2xlarge (x86) and r7g.2xlarge (ARM) with 64 GB.
| Option | QPS, x86 / ARM | Index size |
|---|---|---|
| HNSW, halfvec | 280 / 368 | 22.5 GiB |
| BQ + rerank, halfvec | 261 / 345 | **3.5 GiB** |
| *Asymmetric BQ + rerank, halfvec* | **625** / **693** | **3.5 GiB** |
| *Asymmetric BQ + rerank, vector* | 441 / 500 | **3.5 GiB** |
In another run, `WITH (quantization = 'binary')` on halfvec with the CTE rerank got 583 / 676 QPS.
**More datasets**
These are recall-QPS curves with 1 client. This is [dbpedia-openai-1000k-angular](https://huggingface.co/datasets/KShivendu/dbpedia-entities-openai-1M) on x86. Each BQ value is the median of 3. The [doc](https://github.com/txfs19260817/pgvector/tree/benchmarks/doc) has 4 more datasets, ARM results, and a dimension sweep.

| Option | QPS at recall 0.90 | 0.95 | 0.98 | Index size | Build time |
|---|---|---|---|---|---|
| HNSW, halfvec | 829 | 438 | 112 | 3,867 MB | 219 s |
| BQ + rerank, halfvec | 466 | 256 | 100 | **474 MB** | 60 s |
| *Asymmetric BQ + rerank, halfvec* | 853 | 435 | **165** | **474 MB** | **59 s** |
| *`WITH (quantization = 'binary')`, halfvec* | **1,021** | **548** | 161 | **474 MB** | 60 s |
A [dimension sweep](https://github.com/txfs19260817/pgvector/tree/benchmarks/doc#dimension-sweep) experiment truncates text-embedding-3-large to 256-3,072 dims. At recall 0.95 on x86, `WITH` is 3.7x as fast as BQ + rerank at 256 dimensions, and 1.2x at 3,072. Below about 1,024 dimensions, HNSW on halfvec is still faster.
**Prototype `WITH (quantization = 'binary')`**
```sql
CREATE INDEX ON items USING hnsw (embedding vector_cosine_ops) WITH (quantization = 'binary');
WITH candidates AS MATERIALIZED (
SELECT id, embedding <=> '[1,-2,3]' AS distance FROM items ORDER BY distance LIMIT 100
) SELECT * FROM candidates ORDER BY distance + 0 LIMIT 10;
```
It works the same as `asymmetric-bq` with no rerank inside the index so a materialized CTE reranks the rows.
**RaBitQ**
I also wrote an experimental RaBitQ patch for HNSW for comparison. It is the [`rabitq-hnsw`](https://github.com/txfs19260817/pgvector/tree/rabitq-hnsw) branch. In my tests it did not do better than asymmetric BQ (see the doc), so I do not plan to continue it, putting my time on asymmetric BQ instead.
@zthhhhh and @gouyt13 know RaBitQ much better than I do. If my RaBitQ results can help your work, feel free to use them. I am also happy to work together on it.