From: jkatz (@jkatz) <noreply+jkatz@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #259: Understanding HNSW + filtering
Date: Mon, 11 Sep 2023 14:22:35 +0000
Message-ID: <gh-pgvector-pgvector-259-c1713993076@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-259@github.com>
References: <gh-pgvector-pgvector-259@github.com>
@Palmik PostgreSQL supports [conditional indexing][1] through [partial indexes][1] which lets you define an index like:
```sql
CREATE INDEX ON document USING hnsw(embedding) WHERE category = ?
```
However, you would have to do this for every single category in the database. To look up from both indexes at the same time, pgvector would have to add support for bitmap scans in `hnsw`.
That said, picking an indexing strategy may depend on the actual contents of your data. For example, if your `category` filter eliminates most rows (e.g. you have a handful of vectors to compare remaining), using the index `embedding` may not make sense. Or based upon your use case, you may want to perform the ANN search first and then filter out the results by category.
[1]: https://www.postgresql.org/docs/current/indexes-partial.html