You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2022/05/17 22:33:45 UTC

[GitHub] [lucene] rmuir commented on a diff in pull request #899: Lucene 10577

rmuir commented on code in PR #899:
URL: https://github.com/apache/lucene/pull/899#discussion_r875319253


##########
lucene/core/src/java/org/apache/lucene/codecs/lucene92/ExpandingRandomAccessVectorValues.java:
##########
@@ -0,0 +1,57 @@
+package org.apache.lucene.codecs.lucene92;
+
+import org.apache.lucene.index.RandomAccessVectorValues;
+import org.apache.lucene.index.RandomAccessVectorValuesProducer;
+import org.apache.lucene.util.BytesRef;
+
+import java.io.IOException;
+
+public class ExpandingRandomAccessVectorValues implements RandomAccessVectorValuesProducer {
+
+  private final RandomAccessVectorValuesProducer delegate;
+  private final float scale;
+
+  /**
+   * Wraps an existing vector values producer. Floating point vector values will be produced by scaling
+   * byte-quantized values read from the values produced by the input.
+   */
+  protected ExpandingRandomAccessVectorValues(RandomAccessVectorValuesProducer in, float scale) {
+    this.delegate = in;
+    assert scale != 0;
+    this.scale = scale;
+  }
+
+  @Override
+  public RandomAccessVectorValues randomAccess() throws IOException {
+    RandomAccessVectorValues delegateValues = delegate.randomAccess();
+    float[] value  = new float[delegateValues.dimension()];;
+
+    return new RandomAccessVectorValues() {
+
+      @Override
+      public int size() {
+        return delegateValues.size();
+      }
+
+      @Override
+      public int dimension() {
+        return delegateValues.dimension();
+      }
+
+      @Override
+      public float[] vectorValue(int targetOrd) throws IOException {
+        BytesRef binaryValue = delegateValues.binaryValue(targetOrd);
+        byte[] bytes = binaryValue.bytes;
+        for (int i = 0, j = binaryValue.offset; i < value.length; i++, j++) {
+          value[i] = bytes[j] * scale;

Review Comment:
   Seems to me that moving dotProduct etc out of `org.apache.lucene.util` could help. It could be in the codec.
   
   at a glance, i would modify dotproduct vectors patch and try something like:
   ```
   FloatVector floats = ByteVector.fromArray(bytes).reinterpretAsFloats();
   floats = floats.mul(scale);
   ... remainder of existing algorithm from patch ...
   ```
   
   I have no idea how this would perform off the top of my head, but we can try it.



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