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
38 changes: 21 additions & 17 deletions sql/vector_mhnsw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1125,11 +1125,11 @@ class VisitedSet
{
auto *v= new (root) Visited(node, dist);
insert(node);
count++;
return v;
}
void insert(const FVectorNode *n)
{
count++;
nodes[idx++]= n;
if (idx == 8) flush();
}
Expand Down Expand Up @@ -1355,10 +1355,14 @@ static int search_layer(MHNSW_param *p, const FVector *target, float threshold,
return err;
if (!best.is_full())
{
Visited *v= visited.create(links[i], links[i]->distance_to(target));
if (v->distance_to_target <= threshold)
float distance= links[i]->distance_to(target);
if (distance <= threshold)
{
visited.insert(links[i]);
continue;
p->acc.diameter= std::max(p->acc.diameter, v->distance_to_target);
}
p->acc.diameter= std::max(p->acc.diameter, distance);
Visited *v= visited.create(links[i], distance);
candidates.safe_push(v);
if (skip_deleted && v->node->deleted)
continue;
Expand All @@ -1367,21 +1371,21 @@ 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 || distance >= furthest_best)
{
visited.insert(links[i]);
continue;
}
Visited *v= visited.create(links[i], distance);
candidates.safe_push(v);
if (skip_deleted && v->node->deleted)
continue;
if (v->distance_to_target < furthest_best)
if (distance < best.top()->distance_to_target)
{
candidates.safe_push(v);
if (skip_deleted && v->node->deleted)
continue;
if (v->distance_to_target < best.top()->distance_to_target)
{
best.replace_top(v);
furthest_best= lenient_furthest(best, p->acc.diameter, leniency);
}
best.replace_top(v);
furthest_best= lenient_furthest(best, p->acc.diameter, leniency);
}
}
}
Expand Down