benwtrent commented on code in PR #13181:
URL: https://github.com/apache/lucene/pull/13181#discussion_r1589212230


##########
lucene/core/src/java/org/apache/lucene/search/VectorScorer.java:
##########
@@ -18,64 +18,39 @@
 
 import java.io.IOException;
 import org.apache.lucene.index.ByteVectorValues;
-import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.FloatVectorValues;
-import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.VectorSimilarityFunction;
 
 /**
  * Computes the similarity score between a given query vector and different 
document vectors. This
- * is primarily used by {@link KnnFloatVectorQuery} to run an exact, 
exhaustive search over the
- * vectors.
+ * is used for exact searching and scoring
+ *
+ * @lucene.experimental
  */
-abstract class VectorScorer {
-  protected final VectorSimilarityFunction similarity;
+public interface VectorScorer {
 
   /**
-   * Create a new vector scorer instance.
+   * Compute the score for the current document ID.
    *
-   * @param context the reader context
-   * @param fi the FieldInfo for the field containing document vectors
-   * @param query the query vector to compute the similarity for
+   * @return the score for the current document ID
+   * @throws IOException if an exception occurs during score computation
    */
-  static FloatVectorScorer create(LeafReaderContext context, FieldInfo fi, 
float[] query)
-      throws IOException {
-    FloatVectorValues values = context.reader().getFloatVectorValues(fi.name);
-    if (values == null) {
-      FloatVectorValues.checkField(context.reader(), fi.name);
-      return null;
-    }
-    final VectorSimilarityFunction similarity = 
fi.getVectorSimilarityFunction();
-    return new FloatVectorScorer(values, query, similarity);
-  }
-
-  static ByteVectorScorer create(LeafReaderContext context, FieldInfo fi, 
byte[] query)
-      throws IOException {
-    ByteVectorValues values = context.reader().getByteVectorValues(fi.name);
-    if (values == null) {
-      ByteVectorValues.checkField(context.reader(), fi.name);
-      return null;
-    }
-    VectorSimilarityFunction similarity = fi.getVectorSimilarityFunction();
-    return new ByteVectorScorer(values, query, similarity);
-  }
-
-  VectorScorer(VectorSimilarityFunction similarity) {
-    this.similarity = similarity;
-  }
+  float score() throws IOException;
 
-  /** Compute the similarity score for the current document. */
-  abstract float score() throws IOException;
-
-  abstract boolean advanceExact(int doc) throws IOException;
+  /**
+   * @return a {@link DocIdSetIterator} over the documents.
+   */
+  DocIdSetIterator iterator();

Review Comment:
   I have been thinking more. 
   
   I think it would be good for the VectorScorer to use a "copy" of the 
iterator. This way the ONLY way to iterate is the iterator returned by the 
scorer.
   
   Allowing both the VectorValues and a iterator returned from the scorer refer 
to the same internal iterator seems trappy.
   
   Requiring iteration with the VectorScorer#iterator seems more natural and 
safer.
   
   I will update the PR accordingly soon.



-- 
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

Reply via email to