From: hlinnaka (@hlinnaka) <noreply+hlinnaka@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] PR #282: Hnsw iterator
Date: Fri, 29 Sep 2023 20:50:16 +0000
Message-ID: <gh-pgvector-pgvector-282-rc1341781220@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-282-rc1341132985@github.com>
References: <gh-pgvector-pgvector-282@github.com>
<gh-pgvector-pgvector-282-rc1341132985@github.com>
(on src/hnswutils.c:624)
Makes sense. I was working on a similar thing before I saw your update. See https://github.com/hlinnaka/pgvector/tree/hnsw_iterator. I took that other approach: I split W into three separate heaps: a min-heap and max-heap to maintain the top-ef elements, and a third heap to hold the rest of the elements. Yeah, `pairingheap_nth` is certainly simpler. Perhaps we should put those three heaps behind an abstraction, to make it look like one heap that provides a fast `peek nth element` operation.
Other changes:
- GetCandidate(): It kept the search going on all levels simultaneously, but I didn't understand how it works. The original algorithm walks down to the bottom level and forgets about the upper levels after that. I changed the iterator to do the same. It now uses HnswSearchLayer() for the upper levels like usual, and only uses the "continuous mode" on the bottom level.
- Added some comments to try to explain the continuous algorithm. Hope it helps.
What do you think?