Skip to content

Commit

Permalink
fix aliasing of vector scratch in quantized scorer
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Sokolov committed Nov 7, 2024
1 parent 5c2cb2d commit 4284360
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ private ByteScoringSupplier(

@Override
public RandomVectorScorer scorer(int ord) throws IOException {
ByteVectorValues.Bytes vectors1 = vectorValues.vectors();
ByteVectorValues.Bytes vectors2 = vectorValues.vectors();
byte[] query = vectorValues.vectors().get(ord);
ByteVectorValues.Bytes vectors = vectorValues.vectors();
return new RandomVectorScorer.AbstractRandomVectorScorer(vectorValues) {
@Override
public float score(int node) throws IOException {
return similarityFunction.compare(vectors1.get(ord), vectors2.get(node));
return similarityFunction.compare(query, vectors.get(node));
}
};
}
Expand All @@ -130,12 +130,12 @@ private FloatScoringSupplier(

@Override
public RandomVectorScorer scorer(int ord) throws IOException {
FloatVectorValues.Floats vectors1 = vectorValues.vectors();
FloatVectorValues.Floats vectors2 = vectorValues.vectors();
float[] query = vectorValues.vectors().get(ord);
FloatVectorValues.Floats vectors = vectorValues.vectors();
return new RandomVectorScorer.AbstractRandomVectorScorer(vectorValues) {
@Override
public float score(int node) throws IOException {
return similarityFunction.compare(vectors1.get(ord), vectors2.get(node));
return similarityFunction.compare(query, vectors.get(node));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,17 @@ private static final class ScalarQuantizedRandomVectorScorerSupplier

private final VectorSimilarityFunction vectorSimilarityFunction;
private final QuantizedByteVectorValues vectorValues;
private final QuantizedByteVectorValues.QuantizedBytes vectors;

public ScalarQuantizedRandomVectorScorerSupplier(
QuantizedByteVectorValues vectorValues, VectorSimilarityFunction vectorSimilarityFunction)
throws IOException {
this.vectorValues = vectorValues;
this.vectors = vectorValues.vectors();
this.vectorSimilarityFunction = vectorSimilarityFunction;
}

@Override
public RandomVectorScorer scorer(int ord) throws IOException {
QuantizedByteVectorValues.QuantizedBytes vectors = vectorValues.vectors();
byte[] vectorValue = vectors.get(ord);
float offsetCorrection = vectors.getScoreCorrectionConstant(ord);
return fromVectorSimilarity(
Expand Down

0 comments on commit 4284360

Please sign in to comment.