pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: ivanstepanovftw (@ivanstepanovftw) <noreply+ivanstepanovftw@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #742: Which index types are available for bit vectors?
Date: Sun, 29 Dec 2024 16:28:29 +0000
Message-ID: <gh-pgvector-pgvector-742-c2564774229@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-742@github.com>
References: <gh-pgvector-pgvector-742@github.com>

Both HNSW and IVFFlat indexes are supported for bit vectors in pgvector. That means you **can** index bit vectors (i.e. binary vectors) for fast approximate nearest neighbor searches by Hamming distance—not just brute force.

For example, HNSW indexing for Hamming distance:

```sql
CREATE INDEX ON items USING hnsw (embedding bit_hamming_ops);
```

and IVFFlat indexing:

```sql
CREATE INDEX ON items USING ivfflat (embedding bit_hamming_ops) WITH (lists = 100);
```

You can then query using the `<~>` operator for Hamming distance:

```sql
SELECT *
FROM items
ORDER BY embedding <~> '101'
LIMIT 5;
```

view thread (6+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-742-c2564774229@github.com>
Permalink:  ../gh-pgvector-pgvector-742-c2564774229@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox