From ad7cad5ecd30ef58aa942b50256106913dc66d29 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 11 Jun 2024 16:29:14 -0700 Subject: [PATCH] Improved HnswSearchLayer code --- src/hnswutils.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hnswutils.c b/src/hnswutils.c index 093e7ef..3eee045 100644 --- a/src/hnswutils.c +++ b/src/hnswutils.c @@ -799,15 +799,16 @@ HnswSearchLayer(char *base, Datum q, List *ep, int ef, int lc, Relation index, F { float eDistance; HnswElement eElement = HnswPtrAccess(base, e->element); + bool alwaysAdd = wlen < ef; f = ((HnswPairingHeapNode *) pairingheap_first(W))->inner; if (index == NULL) eDistance = GetCandidateDistance(base, e, q, procinfo, collation); else - HnswLoadElement(eElement, &eDistance, &q, index, procinfo, collation, inserting, wlen >= ef ? &f->distance : NULL); + HnswLoadElement(eElement, &eDistance, &q, index, procinfo, collation, inserting, alwaysAdd ? NULL : &f->distance); - if (eDistance < f->distance || wlen < ef) + if (eDistance < f->distance || alwaysAdd) { HnswCandidate *ec;