Skip to content

Commit 40dcd8f

Browse files
committed
tweaks
1 parent f56973c commit 40dcd8f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

server/src/main/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapper.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -991,24 +991,30 @@ public abstract VectorData parseKnnVector(
991991

992992
public abstract ByteBuffer createByteBuffer(IndexVersion indexVersion, int numBytes);
993993

994+
/**
995+
* Checks the input {@code vector} is one of the {@code possibleTypes},
996+
* and returns the first type that it matches
997+
*/
994998
public static ElementType checkValidVector(float[] vector, ElementType... possibleTypes) {
995999
assert possibleTypes.length != 0;
9961000
// we're looking for one valid allowed type
9971001
StringBuilder[] errors = new StringBuilder[possibleTypes.length];
9981002
for (int i = 0; i < possibleTypes.length; i++) {
9991003
StringBuilder error = possibleTypes[i].checkVectorErrors(vector);
10001004
if (error == null) {
1001-
// this one works - all ok
1005+
// this one works - use it
10021006
return possibleTypes[i];
10031007
} else {
10041008
errors[i] = error;
10051009
}
10061010
}
10071011

1008-
// oh dear, none of the types work with this vector. Generate the error message and throw.
1012+
// oh dear, none of the possible types work with this vector. Generate the error message and throw.
10091013
StringBuilder message = new StringBuilder();
10101014
for (int i = 0; i < possibleTypes.length; i++) {
1011-
if (i > 0) message.append(" ");
1015+
if (i > 0) {
1016+
message.append(" ");
1017+
}
10121018
message.append("Vector is not a ").append(possibleTypes[i]).append(" vector: ").append(errors[i]);
10131019
}
10141020
throw new IllegalArgumentException(appendErrorElements(message, vector).toString());

server/src/main/java/org/elasticsearch/script/VectorScoreScriptUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public FloatDenseVectorFunction(
138138
queryMagnitude += value * value;
139139
}
140140
queryMagnitude = Math.sqrt(queryMagnitude);
141-
DenseVectorFieldMapper.ElementType.FLOAT.checkVectorBounds(this.queryVector);
141+
field.getElementType().checkVectorBounds(this.queryVector);
142142

143143
if (normalizeQuery) {
144144
for (int dim = 0; dim < this.queryVector.length; dim++) {

0 commit comments

Comments
 (0)