zhaih commented on code in PR #12660: URL: https://github.com/apache/lucene/pull/12660#discussion_r1367957707
########## lucene/core/src/java/org/apache/lucene/util/hnsw/HnswGraphBuilder.java: ########## @@ -221,34 +292,39 @@ private long printGraphBuildStatus(int node, long start, long t) { return now; } - private void addDiverseNeighbors(int level, int node, GraphBuilderKnnCollector candidates) - throws IOException { + private void addDiverseNeighbors(int level, int node, NeighborArray scratch) 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); assert neighbors.size() == 0; // new node - popToScratch(candidates); int maxConnOnLevel = level == 0 ? M * 2 : M; - selectAndLinkDiverse(neighbors, scratch, maxConnOnLevel); + boolean[] mask = selectAndLinkDiverse(neighbors, scratch, maxConnOnLevel); // Link the selected nodes to the new node, and the new node to the selected nodes (again // applying diversity heuristic) - int size = neighbors.size(); - for (int i = 0; i < size; i++) { - int nbr = neighbors.node[i]; + for (int i = 0; i < scratch.size(); i++) { + if (mask[i] == false) { Review Comment: Sure, I added both javadoc and some more comments in `addDiverseNeighbors` method to explain why we need it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org