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: Wed, 20 Sep 2023 00:37:30 +0000
Message-ID: <gh-pgvector-pgvector-259-c1726718951@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-259@github.com>
References: <gh-pgvector-pgvector-259@github.com>
> I think storing the values in the lists themselves in a B-tree structure would have a bad performance as the size of the vector struct is big and we need to read the pages randomly to compute the distances for a specific list as the category_id that in the same list may be distributed in different pages.
In this case, the size of an `int4` is nothing compared to the size of a vector, so I don't see this being a practical concern. Additionally, I don't see the random pages being a concern either -- the pages themselves are already clustered together in the index (at least at creation), whereas the random reads occur once we read values from the heap.
The bulk of the work is handled when pruning the lists: we know that `N` lists contain `category_id`, so we only have to review those lists. Given we'd have to scan all the pages in a given list, we can at least skip vector comparisons on index entries that do not match `category_id`. While it does not filter everything, it allows us to visit fewer lists and perform vector calculations on fewer candidates.