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

Create integration test for vector unmatched size(insert/find) #503

Merged
merged 2 commits into from
Aug 18, 2023
Merged
Changes from 1 commit
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 @@ -34,6 +34,7 @@ public class VectorSearchIntegrationTest extends AbstractNamespaceIntegrationTes

private static final String collectionName = "my_collection";
private static final String bigVectorCollectionName = "big_vector_collection";
private static final String vectorSizeTestCollectionName = "vector_size_test_collection";

// Just has to be bigger than maximum array size
private static final int BIG_VECTOR_SIZE = 1000;
Expand Down Expand Up @@ -1315,6 +1316,123 @@ public void deleteOne() {
.body("status", is(nullValue()))
.body("errors", is(nullValue()));
}

@Test
@Order(8)
public void insertVectorWithUnmatchedSize() {
createVectorCollection(namespaceName, vectorSizeTestCollectionName, 5);
// Insert data with $vector array size less than vector index defined size.
final String vectorStrCount3 = buildVectorElements(0, 3);
String jsonVectorStrCount3 =
"""
{
"insertOne": {
"document": {
"_id": "shortHandedVectorElements",
"name": "shortHandedVectorElements",
"description": "this document should have vector size as 5",
"$vector": [ %s ]
}
}
}
"""
.formatted(vectorStrCount3);

given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(jsonVectorStrCount3)
.when()
.post(CollectionResource.BASE_PATH, namespaceName, vectorSizeTestCollectionName)
.then()
.statusCode(200)
.body("errors", is(notNullValue()))
.body("errors[0].message", endsWith("Expected vector of 5 size, but received 3"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe better to say "expected vector of length 5", "5 size" reads a bit awkwardly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Fixed that.


// Insert data with $vector array size greater than vector index defined size.
final String vectorStrCount7 = buildVectorElements(0, 7);
String jsonVectorStrCount7 =
"""
{
"insertOne": {
"document": {
"_id": "excessVectorElements",
"name": "excessVectorElements",
"description": "this document should have vector size as 5",
"$vector": [ %s ]
}
}
}
"""
.formatted(vectorStrCount7);

given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(jsonVectorStrCount7)
.when()
.post(CollectionResource.BASE_PATH, namespaceName, vectorSizeTestCollectionName)
.then()
.statusCode(200)
.body("errors", is(notNullValue()))
.body("errors[0].message", endsWith("Expected vector of 5 size, but received 7"));
}

@Test
@Order(9)
public void findVectorWithUnmatchedSize() {
// Sort clause with $vector array size greater than vector index defined size.
final String vectorStrCount3 = buildVectorElements(0, 3);
String jsonVectorStrCount3 =
"""
{
"find": {
"sort" : {"$vector" : [ %s ]},
"options" : {
"limit" : 5
}
}
}
"""
.formatted(vectorStrCount3);

given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(jsonVectorStrCount3)
.when()
.post(CollectionResource.BASE_PATH, namespaceName, vectorSizeTestCollectionName)
.then()
.statusCode(200)
.body("errors", is(notNullValue()))
.body("errors[0].message", endsWith("Expected vector of 5 size, but received 3"));

// Insert data with $vector array size greater than vector index defined size.
final String vectorStrCount7 = buildVectorElements(0, 7);
String jsonVectorStrCount7 =
"""
{
"find": {
"sort" : {"$vector" : [ %s ]},
"options" : {
"limit" : 5
}
}
}
"""
.formatted(vectorStrCount7);

given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(jsonVectorStrCount7)
.when()
.post(CollectionResource.BASE_PATH, namespaceName, vectorSizeTestCollectionName)
.then()
.statusCode(200)
.body("errors", is(notNullValue()))
.body("errors[0].message", endsWith("Expected vector of 5 size, but received 7"));
}
}

@Nested
Expand Down