cpoerschke commented on code in PR #14170: URL: https://github.com/apache/lucene/pull/14170#discussion_r1933798309
########## lucene/core/src/java/org/apache/lucene/search/SeededKnnVectorQuery.java: ########## @@ -0,0 +1,321 @@ +/* + * 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; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Objects; +import org.apache.lucene.codecs.lucene90.IndexedDISI; +import org.apache.lucene.index.FieldInfo; +import org.apache.lucene.index.KnnVectorValues; +import org.apache.lucene.index.LeafReader; +import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.index.QueryTimeout; +import org.apache.lucene.search.knn.KnnCollectorManager; +import org.apache.lucene.search.knn.KnnSearchStrategy; +import org.apache.lucene.util.Bits; + +/** + * This is a version of knn vector query that provides a query seed to initiate the vector search. + * NOTE: The underlying format is free to ignore the provided seed + * + * <p>See <a href="https://dl.acm.org/doi/10.1145/3539618.3591715">"Lexically-Accelerated Dense + * Retrieval"</a> (Kulkarni, Hrishikesh and MacAvaney, Sean and Goharian, Nazli and Frieder, Ophir). + * In SIGIR '23: Proceedings of the 46th International ACM SIGIR Conference on Research and + * Development in Information Retrieval Pages 152 - 162 + * + * @lucene.experimental + */ +public class SeededKnnVectorQuery extends AbstractKnnVectorQuery { + final Query seed; + final Weight seedWeight; + final AbstractKnnVectorQuery delegate; + + /** + * Construct a new SeededKnnVectorQuery instance for a float vector field + * + * @param knnQuery the knn query to be seeded + * @param seed a query seed to initiate the vector format search + * @return a new SeededKnnVectorQuery instance + * @lucene.experimental + */ + public static SeededKnnVectorQuery fromFloatQuery(KnnFloatVectorQuery knnQuery, Query seed) { + return new SeededKnnVectorQuery(knnQuery, seed, null); + } + + /** + * Construct a new SeededKnnVectorQuery instance for a byte vector field + * + * @param knnQuery the knn query to be seeded + * @param seed a query seed to initiate the vector format search + * @return a new SeededKnnVectorQuery instance + * @lucene.experimental + */ + public static SeededKnnVectorQuery fromByteQuery(KnnByteVectorQuery knnQuery, Query seed) { + return new SeededKnnVectorQuery(knnQuery, seed, null); + } + + SeededKnnVectorQuery(AbstractKnnVectorQuery knnQuery, Query seed, Weight seedWeight) { + super(knnQuery.field, knnQuery.k, knnQuery.filter); + this.seed = Objects.requireNonNull(seed); + this.delegate = knnQuery; + this.seedWeight = seedWeight; Review Comment: minor/subjective: init order to match member declaration order ```suggestion this.seedWeight = seedWeight; this.delegate = knnQuery; ``` -- 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