You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "gf2121 (via GitHub)" <gi...@apache.org> on 2025/05/16 17:24:29 UTC

Re: [PR] Speed up exhaustive evaluation. [lucene]

gf2121 commented on code in PR #14679:
URL: https://github.com/apache/lucene/pull/14679#discussion_r2093432298


##########
lucene/core/src/java/org/apache/lucene/search/similarities/Similarity.java:
##########
@@ -208,6 +208,25 @@ protected SimScorer() {}
      */
     public abstract float score(float freq, long norm);
 
+    /**
+     * Batch-score documents. This method scores {@code size} documents at once. The default
+     * implementation can be found below:
+     *
+     * <pre class="prettyprint">
+     * for (int i = 0; i &lt; size; ++i) {
+     *   scores[i] = score(freqs[i], norms[i]);
+     * }
+     * </pre>
+     *
+     * @see #score(float, long)
+     * @lucene.internal
+     */
+    public void score(int size, int[] freqs, long[] norms, float[] scores) {
+      for (int i = 0; i < size; ++i) {
+        scores[i] = score(freqs[i], norms[i]);

Review Comment:
   > We may also be able to do a bit better than calling score in a loop
   
   Yeah! I played with`BM25` a bit and the result looks promising:
   
   ```
   Benchmark                               Mode  Cnt   Score   Error   Units
   VectorizedBM25Benchmark.scoreBaseline  thrpt    5  10.991 ± 0.356  ops/us
   VectorizedBM25Benchmark.scoreVector    thrpt    5  15.149 ± 0.029  ops/us
   ```
   ```
   public static void scoreBaseline(int size, int[] freqs, long[] norms, float[] scores, float[] cache, int weight, float[] buffer) {
     for (int i = 0; i < size; ++i) {
       float normInverse = cache[((byte) norms[i]) & 0xFF];
       scores[i] = weight - weight / (1f + freqs[i] * normInverse);
     }
   }
   
   public static void scoreVector(int size, int[] freqs, long[] norms, float[] scores, float[] cache, int weight, float[] buffer) {
     for (int i = 0; i < size; ++i) {
       buffer[i] = cache[((byte) norms[i]) & 0xFF];
     }
     for (int i = 0; i < size; ++i) {
       scores[i] = weight - weight / (1f + freqs[i] * buffer[i]);
     }
   }
   ```



-- 
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-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org