Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.simdvec;

import org.apache.lucene.util.quantization.QuantizedByteVectorValues;

public interface QuantizedByteVectorValuesAccess {
QuantizedByteVectorValues get();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.lucene.util.hnsw.UpdateableRandomVectorScorer;
import org.apache.lucene.util.quantization.QuantizedByteVectorValues;
import org.apache.lucene.util.quantization.ScalarQuantizedVectorSimilarity;
import org.elasticsearch.simdvec.QuantizedByteVectorValuesAccess;

import java.io.IOException;
import java.lang.foreign.MemorySegment;
Expand All @@ -23,7 +24,7 @@
import static org.apache.lucene.index.VectorSimilarityFunction.MAXIMUM_INNER_PRODUCT;
import static org.apache.lucene.util.quantization.ScalarQuantizedVectorSimilarity.fromVectorSimilarity;

public abstract sealed class Int7SQVectorScorerSupplier implements RandomVectorScorerSupplier {
public abstract sealed class Int7SQVectorScorerSupplier implements RandomVectorScorerSupplier, QuantizedByteVectorValuesAccess {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't you have this interface satisfied by regular scorer supplier as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to generalise it beyond QuantizedByteVectorValues? Or for the case of a non-int7 scorer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I guess this is the only "custom" one we provide right now. I was thinking that we had other RandomVectorScorerSupplier objects.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also have the same question as Ben, do we really need this QuantizedByteVectorValuesAccess? As we can get access to the quantized vectors through RandomVectorScorerSupplier -> values -> getSlice

Copy link
Contributor Author

@ldematte ldematte Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mayya-sharipova RandomVectorScorerSupplier does not have a values field or accessor; values is declared directly in Int7SQVectorScorerSupplier, which is an internal type we would like not to expose, hence QuantizedByteVectorValuesAccess (in a fashion similar to HasIndexSlice or MemorySegmentAccess).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benwtrent I see your point; we could actually generalize this a bit beyond QuantizedByteVectorValues, e.g. cover all our implementations of RandomVectorScorerSupplier (I count 4 of them in the ES codebase), and return ByteVectorValues.
Maybe it makes sense; eventually, we would like to get something similar into Lucene if possible...


static final byte BITS = 7;

Expand Down Expand Up @@ -107,6 +108,11 @@ public void setScoringOrdinal(int node) throws IOException {
};
}

@Override
public QuantizedByteVectorValues get() {
return values;
}

public static final class EuclideanSupplier extends Int7SQVectorScorerSupplier {

public EuclideanSupplier(MemorySegmentAccessInput input, QuantizedByteVectorValues values, float scoreCorrectionConstant) {
Expand Down