From: spyderdfx (@spyderdfx) <noreply+spyderdfx@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #972: Binary vectors - querying the nearest neighbors by Hamming distance with HNSW gives wrong results
Date: Wed, 01 Apr 2026 09:11:28 +0000
Message-ID: <gh-pgvector-pgvector-972-c4168671665@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-972@github.com>
References: <gh-pgvector-pgvector-972@github.com>
1.
```sql
SELECT (vector_binary <~> '<576 bits omitted>') AS distance FROM image_hashes ORDER BY (vector_binary <~> '<576 bits omitted>') LIMIT 10;
distance
----------
0
230
231
231
232
233
233
234
234
234
(10 rows)
```
2. There were many dups (like ~15kk out of 20kk). I deleted all of them but the query with index scan doesn't produce the row with distance of 0.
3. Wavelet hashing
4. Yeah, there is the needed row now (but after I deleted dups)
```sql
=> SET hnsw.ef_search = 1000;
SET
=> SELECT (vector_binary <~> '<576 bits omitted>') AS distance FROM image_hashes ORDER BY (vector_binary <~> '<576 bits omitted>') LIMIT 10;
distance
----------
0
232
234
235
236
236
237
238
238
238
(10 rows)
```