benwtrent commented on code in PR #12434: URL: https://github.com/apache/lucene/pull/12434#discussion_r1279430631
########## lucene/core/src/java/org/apache/lucene/search/KnnCollector.java: ########## @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.lucene.search; + +/** + * KnnCollector is a knn collector used for gathering kNN results and providing topDocs from the + * gathered neighbors + * + * @lucene.experimental + */ +public interface KnnCollector { + + /** + * If search visits too many documents, the results collector will terminate early. Usually, this + * is due to some restricted filter on the document set. + * + * <p>When collection is earlyTerminated, the results are not a correct representation of k + * nearest neighbors. + * + * @return is the current result set marked as incomplete? + */ + boolean earlyTerminated(); + + /** + * @param count increments the visited vector count, must be greater than 0. + */ + void incVisitedCount(int count); + + /** + * @return the current visited vector count + */ + long visitedCount(); + + /** + * @return the visited vector limit + */ + long visitLimit(); + + /** + * @return the expected number of collected results + */ + int k(); + + /** + * Collect the provided docId and include in the result set. Review Comment: @msokolov see: - https://github.com/apache/lucene/pull/12434#discussion_r1260329978 - https://github.com/apache/lucene/pull/12434/files#diff-ba3b6b03fc9c4dde56640064013726c8d5334076a6f8622c5f9eaee048b4ad47R272 So, all user provided collectors will end up getting wrapped with the "OrdinalTranslatedKnnCollector" and the collection will only ever see docId. Do you think this is a bad idea? If so, we need to provide the ordinal translation to the collector at some point. The requirements are: - Vector search over sparse indices requires the translation when building topDocs - Parent Join requires the translation eagerly because the parentBitSet assumes docIds, not sparse ordinals. I couldn't think of a clean way. Maybe having a "setter" method that can set the ordinal translation for the collector? Or we continue to do it eagerly? -- 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]
