Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions sql/vector_mhnsw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,12 @@ class VisitedSet
count++;
return v;
}
void remember(FVectorNode *node)
{
// Mark a distance-tested node without materialising a queue entry.
insert(node);
count++;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move count++ inside insert()

  • you'll have it only in one place
  • you won't need remember() at all, just invoke insert() directly

void insert(const FVectorNode *n)
{
nodes[idx++]= n;
Expand Down Expand Up @@ -1367,22 +1373,27 @@ static int search_layer(MHNSW_param *p, const FVector *target, float threshold,
}
else
{
Visited *v= visited.create(links[i],
links[i]->distance_greater_than(target, furthest_best,
p->mode, &p->acc));
if (v->distance_to_target <= threshold)
float distance= links[i]->distance_greater_than(target, furthest_best,
p->mode, &p->acc);
if (distance <= threshold)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better write

  if (distance <= threshold || distance >= furthest_best)

{
visited.remember(links[i]);
continue;
if (v->distance_to_target < furthest_best)
}
if (distance < furthest_best)
{
Visited *v= visited.create(links[i], distance);
candidates.safe_push(v);
if (skip_deleted && v->node->deleted)
continue;
if (v->distance_to_target < best.top()->distance_to_target)
if (distance < best.top()->distance_to_target)
{
best.replace_top(v);
furthest_best= lenient_furthest(best, p->acc.diameter, leniency);
}
}
else
visited.remember(links[i]);
}
}
}
Expand Down