pgvector.git / summary / log / commit / refs
commit 6fc7d0631370d8a8e3858aaefbf65ad94704e38c
Author: Andrew Kane <andrew@ankane.org>
Date: Sun Aug 13 22:53:07 2023 +0000
Improved HNSW vacuuming
src/hnswutils.c | 27 ++++++++++++++++++++-------
test/t/016_hnsw_vacuum_recall.pl | 2 +-
2 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/src/hnswutils.c b/src/hnswutils.c
index 6721ae1a..56db0eed 100644
--- a/src/hnswutils.c
+++ b/src/hnswutils.c
@@ -566,7 +566,13 @@ HnswSearchLayer(Datum q, List *ep, int ef, int lc, Relation index, FmgrInfo *pro
pairingheap_add(C, &(CreatePairingHeapNode(hc)->ph_node));
pairingheap_add(W, &(CreatePairingHeapNode(hc)->ph_node));
- wlen++;
+ /*
+ * Do not count elements being deleted towards ef when vacuuming. It
+ * would be ideal to do this for inserts as well, but this could
+ * affect insert performance.
+ */
+ if (skipElement == NULL || list_length(hc->element->heaptids) != 0)
+ wlen++;
}
while (!pairingheap_is_empty(C))
@@ -625,12 +631,19 @@ HnswSearchLayer(Datum q, List *ep, int ef, int lc, Relation index, FmgrInfo *pro
pairingheap_add(C, &(CreatePairingHeapNode(ec)->ph_node));
pairingheap_add(W, &(CreatePairingHeapNode(ec)->ph_node));
- /* TODO Possibly don't count elements being deleted in wlen */
- wlen++;
-
- /* No need to decrement wlen */
- if (wlen > ef)
- pairingheap_remove_first(W);
+ /*
+ * Do not count elements being deleted towards ef when
+ * vacuuming. It would be ideal to do this for inserts as
+ * well, but this could affect insert performance.
+ */
+ if (skipElement == NULL || list_length(e->element->heaptids) != 0)
+ {
+ wlen++;
+
+ /* No need to decrement wlen */
+ if (wlen > ef)
+ pairingheap_remove_first(W);
+ }
}
}
}
diff --git a/test/t/016_hnsw_vacuum_recall.pl b/test/t/016_hnsw_vacuum_recall.pl
index 35548aa5..815fce94 100644
--- a/test/t/016_hnsw_vacuum_recall.pl
+++ b/test/t/016_hnsw_vacuum_recall.pl
@@ -61,7 +61,7 @@ $node->safe_psql("postgres",
);
# Add index
-$node->safe_psql("postgres", "CREATE INDEX ON tst USING hnsw (v vector_l2_ops) WITH (m = 4);");
+$node->safe_psql("postgres", "CREATE INDEX ON tst USING hnsw (v vector_l2_ops) WITH (m = 4, ef_construction = 8);");
# Delete data
$node->safe_psql("postgres", "DELETE FROM tst WHERE i > 2500;");
[parent: 304e262a4195]