From: alanwli (@alanwli) <noreply+alanwli@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #244: HNSW + dead tuples: recall loss/usability issues
Date: Tue, 29 Aug 2023 17:51:52 +0000
Message-ID: <gh-pgvector-pgvector-244@github.com> (raw)
This issue is a follow-up on this [discussion](https://github.com/pgvector/pgvector/issues/239#issuecomment-1696563229) in #239.
**Scenario:** User sets `ef_search` to 10 expecting to get top-10 results back. But the top-10 results in the HNSW index happen to be dead tuples (due to updates & deletes), then the query will return 0 results. While this doesn't impact things like ann-benchmark, it will impact more realistic usecases where applications update/delete data.
**Desired Behavior:** HNSW index returns the top-10 results where the tuples aren't dead to avoid causing significant recall loss - e.g. in the scenario above, recall would be 0%. Note that ivfflat has the desired behavior.
I can see some potentially ugly workarounds:
1. users always performs a vacuum on every update/delete
* con: resource intensive
* con: complexity on application logic
2. users performs more frequent periodic vacuum
* con: should theoretically minimize the problem but offers no bounded guarantees, user can still hit the above problem between the periodic vacuums
3. users can specify higher `ef_search`
* con: how will a user know what `ef_search` to specify?
* con: `ef_search` can be specified up to 1k, which should theoretically minimize the problem but also offers no bounded guarantees - e.g. user can still hit the above problem when the top-1k results of a large dataset in HNSW are dead
And I think the ugly workarounds will fall apart especially for larger datasets, so having a principled fix in the HNSW index would help real-world users.
Thoughts?