From: lambda-science (@lambda-science) <noreply+lambda-science@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #259: Understanding HNSW + filtering
Date: Wed, 06 Mar 2024 08:24:41 +0000
Message-ID: <gh-pgvector-pgvector-259-c1980320549@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-259@github.com>
References: <gh-pgvector-pgvector-259@github.com>
> @lambda-science Can you provide more info about your use-case? There are already several ways to pre-filter with PostgreSQL + pgvector today, including [partitioning and using partial indexes](https://github.com/pgvector/pgvector?tab=readme-ov-file#filtering), as well as post-filtering. It'd help to understand the size of your data set / storage pattern to see if it'd benefit from additional pre-filtering support.
My use case is that we have two type of search:
- 90% of the vector database (1M vectors) is avaliable to all user, like "technical documentation".
- 10% is private vector by users (100k, for example 10 user, each having 10 000 privates vectors), like "my own very private doc".
For the search on the first 90% public, I would do HSNW on ALL the database but there are two issues:
- What if among user private document one user uploaded something very similar to my query and now my 10 top_k are coming from with user results ? With full HNSW + post-filtering I have no results anymore.
- What if actually among these 90% documents I Want to add additionnal filter because it's hard for me to find the relevant document and we want to use more filter ? I would have to plan all filtering pattern and build partial HNSW for each categories.
- What if one day my DB grows a lot and now I have 45% (1M vector) technical documents, 45% (1M Vector) legal documents. I can't do full HNSW search anymore because there is too much risk my top_k is small with post-filtering. I have to *manually* build partial HNSW
For the search on the last 10% private doc, I could do pre-filtering + brute-force yes. Small caveat if someday one user has a loooot of vectors.
Basically our use-case is answering very precise technical documentation about products. So we want to apply as much filter as possible to limit the search space (product name, product version, country...) and irrelevant informations. Maybe we can do bruteforce in this case.