From: Palmik (@Palmik) <noreply+Palmik@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #259: Understanding HNSW + filtering
Date: Mon, 11 Sep 2023 08:45:04 +0000
Message-ID: <gh-pgvector-pgvector-259@github.com> (raw)
Hi, I would like to understand how the current implementation handles HNSW + filtering.
Imagine you have a table:
```sql
CREATE TABLE document (
id UUID PRIMARY KEY,
text TEXT NOT NULL,
embedding REAL[] NOT NULL,
category TEXT NOT NULL
)
```
And that you even have an index on `category`:
```sql
CREATE INDEX document_category ON document (category);
```
And then you want to do a query like:
```sql
SELECT id, text
FROM document
WHERE category = $1
ORDER BY embedding <-> $2
LIMIT 10;
```
To do this efficiently is not straightforward -- ideally we want to do the expensive HNSW ANN on the already pruned subset (https://qdrant.tech/articles/filtrable-hnsw/). Can pgvector do this, or is there plan to enable such optimization in the future?
(In this case the condition is simple enough that you might be able to use table partitioning, but that's not always the case)