Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checks in KNNVectorField / KNNVectorQuery to only allow non-null, non-empty and finite vectors #12281

Merged
merged 8 commits into from
Jun 13, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ public KnnByteVectorField(String name, byte[] vector, FieldType fieldType) {
+ " using byte[] but the field encoding is "
+ fieldType.vectorEncoding());
}
fieldsData = Objects.requireNonNull(vector, "vector value must not be null");
Objects.requireNonNull(vector, "vector value must not be null");
if (vector.length != fieldType.vectorDimension()) {
Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

throw new IllegalArgumentException(
"The number of vector dimensions does not match the field type");
}
fieldsData = vector;
}

/** Return the vector value of this field */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,12 @@ public KnnFloatVectorField(String name, float[] vector, FieldType fieldType) {
+ " using float[] but the field encoding is "
+ fieldType.vectorEncoding());
}
fieldsData =
VectorUtil.checkFinite(Objects.requireNonNull(vector, "vector value must not be null"));
Objects.requireNonNull(vector, "vector value must not be null");
if (vector.length != fieldType.vectorDimension()) {
throw new IllegalArgumentException(
"The number of vector dimensions does not match the field type");
}
fieldsData = VectorUtil.checkFinite(vector);
}

/** Return the vector value of this field */
Expand Down