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

Default vector search function name to cosine. #485

Merged
merged 2 commits into from
Jul 31, 2023
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 @@ -48,6 +48,11 @@ public record VectorSearchConfig(
defaultValue = "cosine",
type = SchemaType.STRING,
implementation = String.class)
String function) {}
String function) {
public VectorSearchConfig(Integer size, String function) {
this.size = size;
this.function = function == null ? "cosine" : function;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,37 @@ public void happyPathVectorSearch() throws Exception {
assertThat(createCollection.options().vector().function()).isEqualTo("cosine");
});
}

@Test
public void happyPathVectorSearchDefaultFunction() throws Exception {
String json =
"""
{
"createCollection": {
"name": "some_name",
"options": {
"vector": {
"size": 5
}
}
}
}
""";

Command result = objectMapper.readValue(json, Command.class);

assertThat(result)
.isInstanceOfSatisfying(
CreateCollectionCommand.class,
createCollection -> {
String name = createCollection.name();
assertThat(name).isNotNull();
assertThat(createCollection.options()).isNotNull();
assertThat(createCollection.options().vector()).isNotNull();
assertThat(createCollection.options().vector().size()).isEqualTo(5);
assertThat(createCollection.options().vector().function()).isEqualTo("cosine");
});
}
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ public void happyPathVectorSearch() {
.statusCode(200)
.body("status.ok", is(1));
}

@Test
public void happyPathVectorSearchDefaultFunction() {
String json =
"""
{
"createCollection": {
"name" : "my_collection_default_function",
"options": {
"vector": {
"size": 5
}
}
}
}
""";
given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(json)
.when()
.post(NamespaceResource.BASE_PATH, namespaceName)
.then()
.statusCode(200)
.body("status.ok", is(1));
}
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,36 @@ public void happyPathVectorSearch() throws Exception {
assertThat(op.vectorFunction()).isEqualTo("cosine");
});
}

@Test
public void happyPathVectorSearchDefaultFunction() throws Exception {
String json =
"""
{
"createCollection": {
"name" : "my_collection",
"options": {
"vector": {
"size": 4
}
}
}
}
""";

CreateCollectionCommand command = objectMapper.readValue(json, CreateCollectionCommand.class);
Operation result = resolver.resolveCommand(commandContext, command);

assertThat(result)
.isInstanceOfSatisfying(
CreateCollectionOperation.class,
op -> {
assertThat(op.name()).isEqualTo("my_collection");
assertThat(op.commandContext()).isEqualTo(commandContext);
assertThat(op.vectorSearch()).isEqualTo(true);
assertThat(op.vectorSize()).isEqualTo(4);
assertThat(op.vectorFunction()).isEqualTo("cosine");
});
}
}
}