jpountz commented on code in PR #15070: URL: https://github.com/apache/lucene/pull/15070#discussion_r2296292691
########## lucene/core/src/java/org/apache/lucene/search/AbstractKnnVectorQuery.java: ########## @@ -200,17 +202,17 @@ private TopDocs getLeafResults( if (scorer == null) { return NO_RESULTS; } - - BitSet acceptDocs = createBitSet(scorer.iterator(), liveDocs, reader.maxDoc()); + int documentSize = reader.maxDoc(); + BitSet acceptDocs = createBitSet(scorer.iterator(), liveDocs, documentSize); final int cost = acceptDocs.cardinality(); QueryTimeout queryTimeout = timeLimitingKnnCollectorManager.getQueryTimeout(); - - float leafProportion = ctx.reader().maxDoc() / (float) ctx.parent.reader().maxDoc(); + float leafProportion = documentSize / (float) ctx.parent.reader().maxDoc(); int perLeafTopK = perLeafTopKCalculation(k, leafProportion); - - if (cost <= perLeafTopK) { - // If there are <= perLeafTopK possible matches, short-circuit and perform exact search, since - // HNSW must always visit at least perLeafTopK documents + int expectedVisitedNodesEstimate = expectedVisitedNodes(perLeafTopK, documentSize); + if (cost <= expectedVisitedNodesEstimate) { + // If there are <= expectedVisitedNodes possible matches, short-circuit and perform exact + // search, since + // HNSW must always visit at least expectedVisitedNodes documents Review Comment: Let's fix this comment to say that HNSW likely needs to visit this many documents, rather than guaranteeing that it needs to visit this many vectors? ########## lucene/core/src/java/org/apache/lucene/search/AbstractKnnVectorQuery.java: ########## @@ -200,17 +202,17 @@ private TopDocs getLeafResults( if (scorer == null) { return NO_RESULTS; } - - BitSet acceptDocs = createBitSet(scorer.iterator(), liveDocs, reader.maxDoc()); + int documentSize = reader.maxDoc(); Review Comment: Can you call it `maxDoc` instead? -- 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