dungba88 commented on code in PR #13285: URL: https://github.com/apache/lucene/pull/13285#discussion_r1689296027
########## lucene/core/src/java/org/apache/lucene/search/AbstractVectorSimilarityQuery.java: ########## @@ -103,16 +114,18 @@ public Explanation explain(LeafReaderContext context, int doc) throws IOExceptio public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { LeafReader leafReader = context.reader(); Bits liveDocs = leafReader.getLiveDocs(); - final Scorer vectorSimilarityScorer; + + QueryTimeout queryTimeout = searcher.getTimeout(); + TimeLimitingKnnCollectorManager timeLimitingKnnCollectorManager = Review Comment: Can we share this variable for all segments? Such as creating it at top-level variable in `createWeight`? ########## lucene/core/src/java/org/apache/lucene/search/AbstractVectorSimilarityQuery.java: ########## @@ -143,27 +156,23 @@ protected boolean match(int doc) { } // Perform an approximate search - TopDocs results = approximateSearch(context, acceptDocs, cardinality); + TopDocs results = + approximateSearch(context, acceptDocs, cardinality, timeLimitingKnnCollectorManager); - // If the limit was exhausted - if (results.totalHits.relation == TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO) { - // Return a lazy-loading iterator - vectorSimilarityScorer = - VectorSimilarityScorer.fromAcceptDocs( - this, - boost, - createVectorScorer(context), - new BitSetIterator(acceptDocs, cardinality), - resultSimilarity); - } else if (results.scoreDocs.length == 0) { - return null; - } else { + if (results.totalHits.relation == TotalHits.Relation.EQUAL_TO + // Return partial results only when timeout is met + || (queryTimeout != null && queryTimeout.shouldExit())) { // Return an iterator over the collected results - vectorSimilarityScorer = - VectorSimilarityScorer.fromScoreDocs(this, boost, results.scoreDocs); + return VectorSimilarityScorerSupplier.fromScoreDocs(boost, results.scoreDocs); + } else { + // Return a lazy-loading iterator + return VectorSimilarityScorerSupplier.fromAcceptDocs( Review Comment: It seems to be a waste that we can't reuse the results from the approximate search (I also saw similar behavior in top-k KnnVectorQuery). Maybe we can pass the partial results to this method, and we don't need to compute score for those? -- 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