pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
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:15:29 +0000
Message-ID: <gh-pgvector-pgvector-259-c1779381503@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-259@github.com>
References: <gh-pgvector-pgvector-259@github.com>

Subquery can not somehow help. There are two different indexes: HNSW index by embedding and B-Tree by category.
You can not use both indexes in your query if you want to satisfy both conditions (except using bitmap scan).
So you have either perform search by category and then sort all selected records by embedding distance.
Either get records in distance increasing order and filter out once belonging to the particular category.

If number of categories is small and fixed, then creating partial index for each category may help. By in general case it doesn't work.

So there are three working solutions:
1. Brute-force search
2. Dynamically increase`efSearch` to get required number of results
3. Return iterator which can provide arbitrary number of results.

3) seems to be the best choice. And I have implemented in my PR.


view thread (90+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-259-c1779381503@github.com>
Permalink:  ../gh-pgvector-pgvector-259-c1779381503@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