cpoerschke commented on code in PR #13635: URL: https://github.com/apache/lucene/pull/13635#discussion_r1755202681
########## lucene/core/src/java/org/apache/lucene/util/hnsw/HnswGraphSearcher.java: ########## @@ -70,6 +72,44 @@ public static void search( search(scorer, knnCollector, graph, graphSearcher, acceptOrds); } + /** + * Searches the HNSW graph for for the nerest neighbors of a query vector, starting from the + * provided entry points. + * + * @param scorer the scorer to compare the query with the nodes + * @param knnCollector a collector of top knn results to be returned + * @param graph the graph values. May represent the entire graph, or a level in a hierarchical + * graph. + * @param acceptOrds {@link Bits} that represents the allowed document ordinals to match, or + * {@code null} if they are all allowed to match. + * @param entryPointOrds the entry points for search. + */ + public static void search( + RandomVectorScorer scorer, + KnnCollector knnCollector, + HnswGraph graph, + Bits acceptOrds, + DocIdSetIterator entryPointOrds) + throws IOException { + ArrayList<Integer> entryPointOrdInts = null; + if (entryPointOrds != null) { + entryPointOrdInts = new ArrayList<Integer>(); + int entryPointOrdInt; + while ((entryPointOrdInt = entryPointOrds.nextDoc()) != NO_MORE_DOCS) { + entryPointOrdInts.add(entryPointOrdInt); + } + } + if (entryPointOrdInts == null || entryPointOrdInts.isEmpty()) { + search(scorer, knnCollector, graph, acceptOrds); + } else { + HnswGraphSearcher graphSearcher = + new HnswGraphSearcher( + new NeighborQueue(knnCollector.k(), true), new SparseFixedBitSet(graph.size())); + int[] entryPointOrdIntsArr = entryPointOrdInts.stream().mapToInt(Integer::intValue).toArray(); + graphSearcher.searchLevel(knnCollector, scorer, 0, entryPointOrdIntsArr, graph, acceptOrds); Review Comment: naive questions: looking at https://github.com/apache/lucene/blob/releases/lucene/9.11.1/lucene/core/src/java/org/apache/lucene/util/hnsw/HnswGraphSearcher.java#L103-L106 and https://github.com/apache/lucene/blob/releases/lucene/9.11.1/lucene/core/src/java/org/apache/lucene/util/hnsw/HnswGraphSearcher.java#L133 we 'know' it's the 0-th layer. (how) do we know that it's also the 0-th layer/level here and/or could the entry points from the seed query also be from different layers/levels? would love to see a short comment in the code re: that. ```suggestion graphSearcher.searchLevel(knnCollector, scorer, 0 /* level */, entryPointOrdIntsArr, graph, acceptOrds); ``` -- 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