ML-dev-crypto commented on code in PR #15667:
URL: https://github.com/apache/lucene/pull/15667#discussion_r2774076674
##########
lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborArray.java:
##########
@@ -310,21 +310,47 @@ private boolean isWorstNonDiverse(
float minAcceptedSimilarity = scores.get(candidateIndex);
if (candidateIndex == uncheckedIndexes[uncheckedCursor]) {
// the candidate itself is unchecked
- for (int i = candidateIndex - 1; i >= 0; i--) {
- float neighborSimilarity = scorer.score(nodes.get(i));
+ int numNodesToCheck = candidateIndex;
+ if (numNodesToCheck == 0) {
+ return false;
+ }
+
+ // Allocate a temporary buffer for scores.
+ // NeighborArray size is typically small (M=16 or 32), so this
allocation is acceptable
+ // and keeps the change localized to this class.
+ float[] neighborScores = new float[numNodesToCheck];
+
+ // Bulk score all neighbors.
+ // The default implementation in RandomVectorScorer handles the fallback
if needed.
+ scorer.bulkScore(nodes.buffer, neighborScores, numNodesToCheck);
Review Comment:
Understood. I've removed the verbose comments and kept the documentation
focused on the 'why' rather than the 'what'.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]