mikemccand commented on code in PR #15979:
URL: https://github.com/apache/lucene/pull/15979#discussion_r3691120147


##########
lucene/core/src/java/org/apache/lucene/codecs/lucene106/dedup/DedupFlatVectorsScorer.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.codecs.lucene106.dedup;
+
+import static org.apache.lucene.codecs.lucene106.dedup.DedupUtil.SCRATCH_SIZE;
+
+import java.io.IOException;
+import org.apache.lucene.codecs.hnsw.FlatVectorScorerUtil;
+import org.apache.lucene.codecs.hnsw.FlatVectorsScorer;
+import org.apache.lucene.codecs.lucene106.dedup.DedupUtil.DedupVectorValues;
+import org.apache.lucene.codecs.lucene106.dedup.DedupUtil.OrdToVecOrd;
+import org.apache.lucene.index.KnnVectorValues;
+import org.apache.lucene.index.VectorSimilarityFunction;
+import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.hnsw.RandomVectorScorer;
+import org.apache.lucene.util.hnsw.RandomVectorScorerSupplier;
+import org.apache.lucene.util.hnsw.UpdateableRandomVectorScorer;
+
+/**
+ * Scorer for de-duplicated vectors. Performs doc operations on the original 
vector values, but
+ * delegates vector operations to the underlying {@link 
DedupVectorValues#getGroupView()}, mapped to
+ * group ordinals via {@link DedupVectorValues#getOrdToVecOrd()}.
+ *
+ * @lucene.experimental
+ */
+final class DedupFlatVectorsScorer implements FlatVectorsScorer {
+  private static final FlatVectorsScorer SCORER =
+      FlatVectorScorerUtil.getLucene99FlatVectorsScorer();
+
+  @Override
+  public RandomVectorScorerSupplier getRandomVectorScorerSupplier(
+      VectorSimilarityFunction similarityFunction, KnnVectorValues 
vectorValues)
+      throws IOException {
+    if (vectorValues instanceof DedupVectorValues dedupValues) {
+      RandomVectorScorerSupplier fieldView =
+          SCORER.getRandomVectorScorerSupplier(similarityFunction, 
vectorValues);
+      RandomVectorScorerSupplier groupView =
+          SCORER.getRandomVectorScorerSupplier(similarityFunction, 
dedupValues.getGroupView());
+      return new RandomVectorScorerSupplierImpl(fieldView, groupView, 
dedupValues.getOrdToVecOrd());
+    }
+    return SCORER.getRandomVectorScorerSupplier(similarityFunction, 
vectorValues);
+  }
+
+  @Override
+  public RandomVectorScorer getRandomVectorScorer(
+      VectorSimilarityFunction similarityFunction, KnnVectorValues 
vectorValues, float[] target)
+      throws IOException {
+    if (vectorValues instanceof DedupVectorValues dedupValues) {
+      RandomVectorScorer fieldView =
+          SCORER.getRandomVectorScorer(similarityFunction, vectorValues, 
target);
+      RandomVectorScorer groupView =
+          SCORER.getRandomVectorScorer(similarityFunction, 
dedupValues.getGroupView(), target);
+      return new RandomVectorScorerImpl(fieldView, groupView, 
dedupValues.getOrdToVecOrd());
+    }
+    return SCORER.getRandomVectorScorer(similarityFunction, vectorValues, 
target);
+  }
+
+  @Override
+  public RandomVectorScorer getRandomVectorScorer(
+      VectorSimilarityFunction similarityFunction, KnnVectorValues 
vectorValues, byte[] target)
+      throws IOException {
+    if (vectorValues instanceof DedupVectorValues dedupValues) {
+      RandomVectorScorer fieldView =
+          SCORER.getRandomVectorScorer(similarityFunction, vectorValues, 
target);
+      RandomVectorScorer groupView =
+          SCORER.getRandomVectorScorer(similarityFunction, 
dedupValues.getGroupView(), target);
+      return new RandomVectorScorerImpl(fieldView, groupView, 
dedupValues.getOrdToVecOrd());
+    }
+    return SCORER.getRandomVectorScorer(similarityFunction, vectorValues, 
target);
+  }
+
+  @Override
+  public RandomVectorScorer getRandomVectorScorer(
+      VectorSimilarityFunction similarityFunction, KnnVectorValues 
vectorValues, short[] target)
+      throws IOException {
+    if (vectorValues instanceof DedupVectorValues dedupValues) {
+      RandomVectorScorer fieldView =
+          SCORER.getRandomVectorScorer(similarityFunction, vectorValues, 
target);
+      RandomVectorScorer groupView =
+          SCORER.getRandomVectorScorer(similarityFunction, 
dedupValues.getGroupView(), target);
+      return new RandomVectorScorerImpl(fieldView, groupView, 
dedupValues.getOrdToVecOrd());
+    }
+    return SCORER.getRandomVectorScorer(similarityFunction, vectorValues, 
target);
+  }
+
+  private record RandomVectorScorerSupplierImpl(
+      RandomVectorScorerSupplier fieldView,
+      RandomVectorScorerSupplier groupView,
+      OrdToVecOrd ordToVecOrd)
+      implements RandomVectorScorerSupplier {
+
+    @Override
+    public UpdateableRandomVectorScorer scorer() throws IOException {
+      return new UpdateableRandomVectorScorerImpl(
+          fieldView.scorer(), groupView.scorer(), ordToVecOrd);
+    }
+
+    @Override
+    public RandomVectorScorerSupplier copy() throws IOException {
+      return new RandomVectorScorerSupplierImpl(fieldView.copy(), 
groupView.copy(), ordToVecOrd);
+    }
+  }
+
+  private static class RandomVectorScorerImpl implements RandomVectorScorer {
+    private final RandomVectorScorer fieldView;
+    private final RandomVectorScorer groupView;
+    private final OrdToVecOrd ordToVecOrd;
+    private int[] scratch;
+
+    RandomVectorScorerImpl(
+        RandomVectorScorer fieldView, RandomVectorScorer groupView, 
OrdToVecOrd ordToVecOrd) {
+      this.fieldView = fieldView;
+      this.groupView = groupView;
+      this.ordToVecOrd = ordToVecOrd;
+      this.scratch = new int[SCRATCH_SIZE];
+    }
+
+    @Override
+    public int ordToDoc(int ord) {
+      return fieldView.ordToDoc(ord);
+    }
+
+    @Override
+    public Bits getAcceptOrds(Bits acceptDocs) {
+      return fieldView.getAcceptOrds(acceptDocs);
+    }
+
+    @Override
+    public float score(int node) throws IOException {
+      return groupView.score(ordToVecOrd.get(node));

Review Comment:
   LOL thanks, links back to my question / your answer ... history is repeating 
itself.  I am stuck in a loop now.



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

Reply via email to