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

Fixes #1332: separate out ErrorCode.VECTOR_SIZE_MISMATCH from INVALID_QUERY #1333

Merged
merged 3 commits into from
Aug 13, 2024
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 @@ -145,6 +145,7 @@ public enum ErrorCode {
VECTOR_SEARCH_INVALID_FUNCTION_NAME("Invalid vector search function name"),

VECTOR_SEARCH_TOO_BIG_VALUE("Vector embedding property '$vector' length too big"),
VECTOR_SIZE_MISMATCH("Length of vector parameter different from declared '$vector' dimension"),

VECTORIZE_FEATURE_NOT_AVAILABLE("Vectorize feature is not available in the environment"),
VECTORIZE_SERVICE_NOT_REGISTERED("Vectorize service name provided is not registered : "),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ public CommandResult.Error getCommandResultError(String message, Response.Status
DebugModeConfig debugModeConfig = config.getConfigMapping(DebugModeConfig.class);
final boolean debugEnabled = debugModeConfig.enabled();
final boolean extendError = config.getConfigMapping(OperationsConfig.class).extendError();
Map<String, Object> fields = null;
Map<String, Object> fields;

if (extendError) {
fields =
new HashMap<String, Object>(
new HashMap<>(
Map.of(
"id",
id,
Expand All @@ -178,7 +178,7 @@ public CommandResult.Error getCommandResultError(String message, Response.Status
"title",
title));
} else {
fields = new HashMap<String, Object>(Map.of("errorCode", errorCode.name()));
fields = new HashMap<>(Map.of("errorCode", errorCode.name()));
}

if (debugEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,15 @@ private static CommandResult.Error handleQueryValidationException(
.toApiException()
.getCommandResultError(ErrorCode.NO_INDEX_ERROR.getMessage(), Response.Status.OK);
}
String errorMessage =
message.contains("vector<float,") ? "Mismatched vector dimension" : message;
if (message.contains("vector<float,")) {
// It is tricky to find the actual vector dimension from the message, include as-is
return ErrorCode.VECTOR_SIZE_MISMATCH
.toApiException("root cause = (%s) %s", throwable.getClass().getSimpleName(), message)
.getCommandResultError(Response.Status.OK);
}
return ErrorCode.INVALID_QUERY
.toApiException()
.getCommandResultError(errorMessage, Response.Status.OK);
.getCommandResultError(message, Response.Status.OK);
}

/** Driver AllNodesFailedException a composite exception, peeling the errors from it */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ public void failWithEmptyVector() {
}

@Test
@Order(4)
@Order(5)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had duplicate for 4, fixing it.

public void failWithZerosVector() {
String json =
"""
Expand Down Expand Up @@ -1016,7 +1016,7 @@ public void failWithZerosVector() {
}

@Test
@Order(5)
@Order(6)
public void failWithInvalidVectorElements() {
String json =
"""
Expand Down Expand Up @@ -1045,7 +1045,7 @@ public void failWithInvalidVectorElements() {

// Vector columns can only use ANN, not regular filtering
@Test
@Order(6)
@Order(7)
public void failWithVectorFilter() {
String json =
"""
Expand Down Expand Up @@ -1619,8 +1619,12 @@ public void insertVectorWithUnmatchedSize() {
.post(CollectionResource.BASE_PATH, namespaceName, vectorSizeTestCollectionName)
.then()
.statusCode(200)
.body("errors", is(notNullValue()))
.body("errors[0].message", endsWith("Mismatched vector dimension"));
.body("errors", hasSize(1))
.body("errors[0].errorCode", is("VECTOR_SIZE_MISMATCH"))
.body(
"errors[0].message",
startsWith(
"Length of vector parameter different from declared '$vector' dimension: root cause ="));

// Insert data with $vector array size greater than vector index defined size.
final String vectorStrCount7 = buildVectorElements(0, 7);
Expand All @@ -1647,8 +1651,12 @@ public void insertVectorWithUnmatchedSize() {
.post(CollectionResource.BASE_PATH, namespaceName, vectorSizeTestCollectionName)
.then()
.statusCode(200)
.body("errors", is(notNullValue()))
.body("errors[0].message", endsWith("Mismatched vector dimension"));
.body("errors", hasSize(1))
.body("errors[0].errorCode", is("VECTOR_SIZE_MISMATCH"))
.body(
"errors[0].message",
startsWith(
"Length of vector parameter different from declared '$vector' dimension: root cause ="));
}

@Test
Expand Down Expand Up @@ -1677,8 +1685,12 @@ public void findVectorWithUnmatchedSize() {
.post(CollectionResource.BASE_PATH, namespaceName, vectorSizeTestCollectionName)
.then()
.statusCode(200)
.body("errors", is(notNullValue()))
.body("errors[0].message", endsWith("Mismatched vector dimension"));
.body("errors", hasSize(1))
.body("errors[0].errorCode", is("VECTOR_SIZE_MISMATCH"))
.body(
"errors[0].message",
startsWith(
"Length of vector parameter different from declared '$vector' dimension: root cause ="));

// Insert data with $vector array size greater than vector index defined size.
final String vectorStrCount7 = buildVectorElements(0, 7);
Expand All @@ -1703,8 +1715,12 @@ public void findVectorWithUnmatchedSize() {
.post(CollectionResource.BASE_PATH, namespaceName, vectorSizeTestCollectionName)
.then()
.statusCode(200)
.body("errors", is(notNullValue()))
.body("errors[0].message", endsWith("Mismatched vector dimension"));
.body("errors", hasSize(1))
.body("errors[0].errorCode", is("VECTOR_SIZE_MISMATCH"))
.body(
"errors[0].message",
startsWith(
"Length of vector parameter different from declared '$vector' dimension: root cause ="));
}
}

Expand Down