Skip to content

Commit

Permalink
MemorySegment scorer should ensure that the values is of the correct …
Browse files Browse the repository at this point in the history
…type (#13423)

This commit updates the MemorySegment scorer so that it ensures the values is of the correct type.

The offset calculations for vectors in RandomAccessQuantizedByteVectorValues will be different than that of non-quantized. We can generalise the implementation for quantized vectors later, but for now, passing a quantised values indicated bug in wrapping or delegation.
  • Loading branch information
ChrisHegarty committed May 27, 2024
1 parent 0ba07db commit 338f47b
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.lucene.util.hnsw.RandomAccessVectorValues;
import org.apache.lucene.util.hnsw.RandomVectorScorer;
import org.apache.lucene.util.hnsw.RandomVectorScorerSupplier;
import org.apache.lucene.util.quantization.RandomAccessQuantizedByteVectorValues;

public class Lucene99MemorySegmentFlatVectorsScorer implements FlatVectorsScorer {

Expand All @@ -39,6 +40,8 @@ private Lucene99MemorySegmentFlatVectorsScorer(FlatVectorsScorer delegate) {
public RandomVectorScorerSupplier getRandomVectorScorerSupplier(
VectorSimilarityFunction similarityType, RandomAccessVectorValues vectorValues)
throws IOException {
// a quantized values here is a wrapping or delegation issue
assert !(vectorValues instanceof RandomAccessQuantizedByteVectorValues);
// currently only supports binary vectors
if (vectorValues instanceof RandomAccessVectorValues.Bytes && vectorValues.getSlice() != null) {
var scorer =
Expand Down Expand Up @@ -68,6 +71,8 @@ public RandomVectorScorer getRandomVectorScorer(
byte[] queryVector)
throws IOException {
checkDimensions(queryVector.length, vectorValues.dimension());
// a quantized values here is a wrapping or delegation issue
assert !(vectorValues instanceof RandomAccessQuantizedByteVectorValues);
if (vectorValues instanceof RandomAccessVectorValues.Bytes && vectorValues.getSlice() != null) {
var scorer =
Lucene99MemorySegmentByteVectorScorer.create(
Expand Down

0 comments on commit 338f47b

Please sign in to comment.