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 15:25:24 +0000
Message-ID: <gh-pgvector-pgvector-259-c1714113332@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-259@github.com>
References: <gh-pgvector-pgvector-259@github.com>
> Is there any plan to support these kind of use cases, where combining traditional and hnsw indices would lead to much better performance?
I have a POC that does this, but it requires some more investigation on how to best support it. One challenge is that the values in the `ORDER BY` clause are not available to the index access method ([`amgetbitmap`][1]) that you need to perform this type of scan. There are other ways we could attempt it today, but we'd have to decide if it makes sense to add a new operator to the `WHERE` clause to specifically allow for this type of scan, or if we need to propose changes upstream.
It's likely possible to do "post-filtering" as part of the index scan if we add support for [covering indexes][2], though the tradeoff is that it requires storing more data in the index itself.
I took a quick look at the implementation you shared above -- it looks like it uses an alternative storage system, not PostgreSQL, so it would not be an apples-to-apples comparison on how to do dynaminc prefiltering as part of the index scan.
> While in our case category filter will eliminate most documents, the remaining document set is still too large for nearest-neighbor scan without index (millions of documents).
How many categories do you have? Do they all require partitions, or just a few? I'm curious, mainly because based on that, it may be reasonable to partition some set of the data and keep the rest in the default partition.
[1]: https://www.postgresql.org/docs/current/index-scanning.html
[2]: https://www.postgresql.org/docs/current/indexes-index-only-scans.html