pgvector.git / summary / log / commit / refs
commit cfaa2ecd7f8336bf0c5d60e78ce5f369ea55c025
Author: Andrew Kane <andrew@ankane.org>
Date: Sat Aug 26 21:06:03 2023 +0000
Improved HNSW graph repair - #239
src/hnswutils.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/src/hnswutils.c b/src/hnswutils.c
index cec8812b..8e6f2a9c 100644
--- a/src/hnswutils.c
+++ b/src/hnswutils.c
@@ -623,10 +623,6 @@ HnswSearchLayer(Datum q, List *ep, int ef, int lc, Relation index, FmgrInfo *pro
Assert(!e->element->deleted);
- /* Skip self for vacuuming update */
- if (skipElement != NULL && e->element->blkno == skipElement->blkno && e->element->offno == skipElement->offno)
- continue;
-
/* Make robust to issues */
if (e->element->level < lc)
continue;
@@ -913,10 +909,10 @@ HnswUpdateConnection(HnswElement element, HnswCandidate * hc, int m, int lc, int
}
/*
- * Remove elements being deleted
+ * Remove elements being deleted or skipped
*/
static List *
-RemoveElementsBeingDeleted(List *w)
+RemoveElements(List *w, HnswElement skipElement)
{
ListCell *lc2;
List *w2 = NIL;
@@ -925,6 +921,10 @@ RemoveElementsBeingDeleted(List *w)
{
HnswCandidate *hc = (HnswCandidate *) lfirst(lc2);
+ /* Skip self for vacuuming update */
+ if (skipElement != NULL && hc->element->blkno == skipElement->blkno && hc->element->offno == skipElement->offno)
+ continue;
+
if (list_length(hc->element->heaptids) != 0)
w2 = lappend(w2, hc);
}
@@ -963,20 +963,27 @@ HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, F
if (level > entryLevel)
level = entryLevel;
+ /* Add one for existing element */
+ if (existing)
+ efConstruction++;
+
/* 2nd phase */
for (int lc = level; lc >= 0; lc--)
{
int lm = HnswGetLayerM(m, lc);
List *neighbors;
+ List *lw;
w = HnswSearchLayer(q, ep, efConstruction, lc, index, procinfo, collation, true, skipElement);
- /* Elements being deleted can help with search */
+ /* Elements being deleted or skipped can help with search */
/* but should be removed before selecting neighbors */
if (index != NULL)
- w = RemoveElementsBeingDeleted(w);
+ lw = RemoveElements(w, skipElement);
+ else
+ lw = w;
- neighbors = SelectNeighbors(w, lm, lc, procinfo, collation, NULL);
+ neighbors = SelectNeighbors(lw, lm, lc, procinfo, collation, NULL);
AddConnections(element, neighbors, lm, lc);
[parent: bb1e5ed98fdd]