Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,7 @@ void addDiverseNeighbors(
UpdateableRandomVectorScorer scorer,
boolean outOfOrderInsertion)
throws IOException {
/* For each of the beamWidth nearest candidates (going from best to worst), select it only if it
* is closer to target than it is to any of the already-selected neighbors (ie selected in this method,
* since the node is new and has no prior neighbors).
*/
NeighborArray neighbors = hnsw.getNeighbors(level, node);
int maxConnOnLevel = level == 0 ? M * 2 : M;
boolean[] mask =
selectAndLinkDiverse(
node, neighbors, candidates, maxConnOnLevel, scorer, outOfOrderInsertion);
boolean[] mask = addDiverseForward(level, node, candidates, scorer, outOfOrderInsertion);

// Link the selected nodes to the new node, and the new node to the selected nodes (again
// applying diversity heuristic)
Expand All @@ -386,6 +378,25 @@ void addDiverseNeighbors(
}
}

boolean[] addDiverseForward(
int level,
int node,
NeighborArray candidates,
UpdateableRandomVectorScorer scorer,
boolean outOfOrderInsertion)
throws IOException {
/* For each of the beamWidth nearest candidates (going from best to worst), select it only if it
* is closer to target than it is to any of the already-selected neighbors (ie selected in this method,
* since the node is new and has no prior neighbors).
*/
NeighborArray neighbors = hnsw.getNeighbors(level, node);
int maxConnOnLevel = level == 0 ? M * 2 : M;
boolean[] mask =
selectAndLinkDiverse(
node, neighbors, candidates, maxConnOnLevel, scorer, outOfOrderInsertion);
return mask;
}

/**
* This method will select neighbors to add and return a mask telling the caller which candidates
* are selected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ private void fixDisconnectedNodes(
popToScratch(candidates, scratchArray);

// Add diverse neighbors using HNSW heuristic (prunes similar neighbors)
addDiverseNeighbors(level, node, scratchArray, scorer, true);
addDiverseForward(level, node, scratchArray, scorer, true);
} else {
// Node has no nighbors, add connections from scratch
// Node has no neighbors, add connections from scratch
addConnections(node, level, scorer);
}

Expand Down
Loading