benwtrent commented on code in PR #12413:
URL: https://github.com/apache/lucene/pull/12413#discussion_r1254849673


##########
lucene/core/src/java/org/apache/lucene/util/hnsw/HnswGraphSearcher.java:
##########
@@ -256,6 +256,56 @@ public NeighborQueue searchLevel(
     return results;
   }
 
+  /**
+   * Function to find the best entry point from which to search the zeroth 
graph layer.
+   *
+   * @param query vector query with which to search
+   * @param vectors random access vector values
+   * @param graph the HNSWGraph
+   * @param visitLimit How many vectors are allowed to be visited
+   * @return An integer array whose first element is the best entry point, and 
second is the number
+   *     of candidates visited. Entry point of `-1` indicates visitation limit 
exceed
+   * @throws IOException When accessing the vector fails
+   */
+  private int[] findBestEntryPoint(
+      T query, RandomAccessVectorValues<T> vectors, HnswGraph graph, int 
visitLimit)
+      throws IOException {
+    int size = graph.size();
+    int visitedCount = 1;
+    prepareScratchState(vectors.size());
+    int currentEp = graph.entryNode();
+    float currentScore = compare(query, vectors, currentEp);
+    boolean foundBetter;
+    for (int level = graph.numLevels() - 1; level >= 1; level--) {
+      foundBetter = true;
+      visited.set(currentEp);
+      // Keep searching the given level until we stop finding a better 
candidate entry point
+      while (foundBetter) {

Review Comment:
   do/while is indeed valid. But daggum, it confuses the crap out of me, wish 
Java didn't have it. If you don't mind, I will keep the `while` loop. I don't 
particularly mind if somebody changes it later.



-- 
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

Reply via email to