From: williamhakim10 (@williamhakim10) <noreply+williamhakim10@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #259: Understanding HNSW + filtering
Date: Wed, 08 May 2024 15:10:20 +0000
Message-ID: <gh-pgvector-pgvector-259-c2100810428@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-259@github.com>
References: <gh-pgvector-pgvector-259@github.com>
@mauriciocirelli you're seeing this result in the second query because the query *isn't using the index*. Because pgvector's indices don't do filtering for you, you're left with two options: filter all results by your condition and then do a brute-force reordering, or use the index to find nearest neighbors and then filter afterwards. You have to choose which approach you want. Admittedly the planner is a little opaque, and certainly postgres version differences could cause the planner to choose differently (although there are ways you can nudge it). If you always want to do brute-force search (like Redis) drop the HNSW index and you'll always get brute force.