slow-J commented on code in PR #16271:
URL: https://github.com/apache/lucene/pull/16271#discussion_r3497919704
##########
lucene/core/src/java/org/apache/lucene/search/AbstractKnnVectorQuery.java:
##########
@@ -149,9 +149,64 @@ public Query rewrite(IndexSearcher indexSearcher) throws
IOException {
topK = runSearchTasks(tasks, taskExecutor, perLeafResults,
leafReaderContexts);
}
if (topK.scoreDocs.length == 0) {
- return MatchNoDocsQuery.INSTANCE;
+ return new MatchNoDocsQuery("No documents matched the nearest-neighbor
search");
}
- return DocAndScoreQuery.createDocAndScoreQuery(reader, topK, reentryCount);
+ return DocAndScoreQuery.createDocAndScoreQuery(
+ reader, topK, reentryCount, noMatchExplainer(topK, filterWeight));
+ }
+
+ /** Builds the explainer for documents this query did not collect, capturing
minTopKScore. */
+ private DocAndScoreQuery.NoMatchExplainer noMatchExplainer(TopDocs topK,
Weight filterWeight) {
+ // topK is score-descending, so the lowest collected score is the last
entry.
+ final float minTopKScore = topK.scoreDocs[topK.scoreDocs.length - 1].score;
+ return (context, doc, topN) ->
+ explainNotCollected(context, doc, topN, filterWeight, minTopKScore);
+ }
+
+ /** Explains why a doc was not collected, by recomputing its score. null
when no vectors. */
+ private Explanation explainNotCollected(
+ LeafReaderContext context, int doc, int topN, Weight filterWeight, float
minTopKScore)
+ throws IOException {
+ String prefix = "Not in top " + topN + " doc(s): ";
+ FieldInfo fi = context.reader().getFieldInfos().fieldInfo(field);
+ if (fi == null || fi.getVectorDimension() == 0) {
+ return null;
+ }
+ VectorScorer vectorScorer = createVectorScorer(context, fi);
+ if (vectorScorer == null) {
+ return null;
+ }
+ if (vectorScorer.iterator().advance(doc) != doc) {
+ return Explanation.noMatch(prefix + "no vector value in field \"" +
field + "\"");
+ }
+ if (filterWeight != null && docPassesFilter(filterWeight, context, doc) ==
false) {
+ return Explanation.noMatch(prefix + "excluded by filter");
+ }
+ float score = vectorScorer.score();
+ if (score < minTopKScore) {
+ return Explanation.noMatch(prefix + "score " + score + " < minTopKScore
" + minTopKScore);
Review Comment:
Sure :D
Edit: done in latest commit
--
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]