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
Expand Up @@ -67,4 +67,11 @@ RandomVectorScorer getRandomVectorScorer(
RandomVectorScorer getRandomVectorScorer(
VectorSimilarityFunction similarityFunction, KnnVectorValues vectorValues, byte[] target)
throws IOException;

static void checkDimensions(int queryLen, int fieldLen) {
if (queryLen != fieldLen) {
throw new IllegalArgumentException(
"vector query dimension: " + queryLen + " differs from field dimension: " + fieldLen);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ public Lucene104ScalarQuantizedVectorScorer(FlatVectorsScorer nonQuantizedDelega
this.nonQuantizedDelegate = nonQuantizedDelegate;
}

static void checkDimensions(int queryLen, int fieldLen) {
if (queryLen != fieldLen) {
throw new IllegalArgumentException(
"vector query dimension: " + queryLen + " differs from field dimension: " + fieldLen);
}
}

@Override
public RandomVectorScorerSupplier getRandomVectorScorerSupplier(
VectorSimilarityFunction similarityFunction, KnnVectorValues vectorValues)
Expand All @@ -62,7 +55,7 @@ public RandomVectorScorer getRandomVectorScorer(
VectorSimilarityFunction similarityFunction, KnnVectorValues vectorValues, float[] target)
throws IOException {
if (vectorValues instanceof QuantizedByteVectorValues qv) {
checkDimensions(target.length, qv.dimension());
FlatVectorsScorer.checkDimensions(target.length, qv.dimension());
OptimizedScalarQuantizer quantizer = qv.getQuantizer();
Lucene104ScalarQuantizedVectorsFormat.ScalarEncoding scalarEncoding = qv.getScalarEncoding();
byte[] scratch = new byte[scalarEncoding.getDiscreteDimensions(qv.dimension())];
Expand Down Expand Up @@ -103,6 +96,7 @@ public float score(int node) throws IOException {
public RandomVectorScorer getRandomVectorScorer(
VectorSimilarityFunction similarityFunction, KnnVectorValues vectorValues, byte[] target)
throws IOException {
FlatVectorsScorer.checkDimensions(target.length, vectorValues.dimension());
return nonQuantizedDelegate.getRandomVectorScorer(similarityFunction, vectorValues, target);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static UpdateableRandomVectorScorer fromVectorSimilarity(
VectorSimilarityFunction sim,
float constMultiplier,
QuantizedByteVectorValues values) {
checkDimensions(targetBytes.length, values.dimension());
FlatVectorsScorer.checkDimensions(values.dimension(), targetBytes.length);
return switch (sim) {
case EUCLIDEAN -> new Euclidean(values, constMultiplier, targetBytes);
case COSINE, DOT_PRODUCT ->
Expand All @@ -115,13 +115,6 @@ static UpdateableRandomVectorScorer fromVectorSimilarity(
};
}

static void checkDimensions(int queryLen, int fieldLen) {
if (queryLen != fieldLen) {
throw new IllegalArgumentException(
"vector query dimension: " + queryLen + " differs from field dimension: " + fieldLen);
}
}

private static UpdateableRandomVectorScorer.AbstractUpdateableRandomVectorScorer
dotProductFactory(
byte[] targetBytes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private RandomVectorScorerSupplier getByteScorerSupplier(
public RandomVectorScorer getRandomVectorScorer(
VectorSimilarityFunction similarityType, KnnVectorValues vectorValues, float[] target)
throws IOException {
checkDimensions(target.length, vectorValues.dimension());
FlatVectorsScorer.checkDimensions(target.length, vectorValues.dimension());
if (vectorValues instanceof FloatVectorValues fvv
&& fvv instanceof HasIndexSlice floatVectorValues
&& floatVectorValues.getSlice() != null) {
Expand All @@ -102,7 +102,7 @@ public RandomVectorScorer getRandomVectorScorer(
public RandomVectorScorer getRandomVectorScorer(
VectorSimilarityFunction similarityType, KnnVectorValues vectorValues, byte[] queryVector)
throws IOException {
checkDimensions(queryVector.length, vectorValues.dimension());
FlatVectorsScorer.checkDimensions(queryVector.length, vectorValues.dimension());
// a quantized values here is a wrapping or delegation issue
assert !(vectorValues instanceof QuantizedByteVectorValues);
if (vectorValues instanceof ByteVectorValues bvv
Expand All @@ -118,13 +118,6 @@ public RandomVectorScorer getRandomVectorScorer(
return delegate.getRandomVectorScorer(similarityType, vectorValues, queryVector);
}

static void checkDimensions(int queryLen, int fieldLen) {
if (queryLen != fieldLen) {
throw new IllegalArgumentException(
"vector query dimension: " + queryLen + " differs from field dimension: " + fieldLen);
}
}

@Override
public String toString() {
return "Lucene99MemorySegmentFlatVectorsScorer()";
Expand Down
Loading