From: knizhnik (@knizhnik) <noreply+knizhnik@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #259: Understanding HNSW + filtering
Date: Wed, 25 Oct 2023 14:00:18 +0000
Message-ID: <gh-pgvector-pgvector-259-c1779342280@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-259@github.com>
References: <gh-pgvector-pgvector-259@github.com>
> @jkatz
>
> I did not understand from your original reply what the current behavior is for the query in the question. Would it do filtering during the KNN search, i.e. similarly to [how it is implemented in Elastic Search](https://discuss.elastic.co/t/pre-filter-knn-vector-search/341585)? And if so, then, when there are thousands of categories, is this approximate KNN search any faster than brute-force exact KNN search within the category of interest?
It was not question to me, but I can answer: no filtering is not done inside KNN search.
So first you perform ANN search and return efSearch closest result and then apply filter to it.
Obviously it may return less results than expected. Ornate return any results at all.
Postgres index access method API doesn't allow to push filter in this case.
This is why I proposed PR where index search returns as much results as requested (iterator).