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

[Indexing options] Changes for find collections to return indexing option #779

Merged
merged 8 commits into from
Jan 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public record CreateCollectionCommand(
public record Options(

// limit of returned documents
@Schema(
@JsonInclude(JsonInclude.Include.NON_NULL)
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also use JsonInclude.Include.NON_EMPTY which would exclude empty Collections.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah., got it I will change it.

@Schema(
description = "Vector search index configuration for the collection",
type = SchemaType.OBJECT,
implementation = VectorSearchConfig.class)
Expand Down Expand Up @@ -84,14 +85,14 @@ public VectorSearchConfig(Integer dimension, String metric) {
}

public record IndexingConfig(
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Schema(
description = "List of allowed indexing fields",
type = SchemaType.ARRAY,
implementation = String.class)
@Nullable
List<String> allow,
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Schema(
description = "List of denied indexing fields",
type = SchemaType.ARRAY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import io.smallrye.mutiny.Uni;
import io.stargate.sgv2.jsonapi.api.model.command.CommandContext;
import io.stargate.sgv2.jsonapi.api.model.command.CommandResult;
Expand Down Expand Up @@ -97,8 +98,10 @@ public CommandResult get() {
.map(
collectionProperty -> {
CreateCollectionCommand.Options options = null;
CreateCollectionCommand.Options.VectorSearchConfig vectorSearchConfig = null;
CreateCollectionCommand.Options.VectorizeConfig vectorizeConfig = null;
CreateCollectionCommand.Options.IndexingConfig indexingConfig = null;
if (collectionProperty.vectorEnabled()) {
CreateCollectionCommand.Options.VectorizeConfig vectorizeConfig = null;
if (collectionProperty.modelName() != null
&& collectionProperty.vectorizeServiceName() != null) {
CreateCollectionCommand.Options.VectorizeConfig.VectorizeOptions
Expand All @@ -109,14 +112,27 @@ public CommandResult get() {
new CreateCollectionCommand.Options.VectorizeConfig(
collectionProperty.vectorizeServiceName(), vectorizeOptions);
}
CreateCollectionCommand.Options.VectorSearchConfig vectorSearchConfig =

vectorSearchConfig =
new CreateCollectionCommand.Options.VectorSearchConfig(
collectionProperty.vectorSize(),
collectionProperty.similarityFunction().name().toLowerCase());
}

if (collectionProperty.indexingConfig() != null) {
indexingConfig =
new CreateCollectionCommand.Options.IndexingConfig(
Lists.newArrayList(collectionProperty.indexingConfig().allowed()),
Lists.newArrayList(collectionProperty.indexingConfig().denied()));
}
if (vectorSearchConfig != null
|| vectorizeConfig != null
|| indexingConfig != null) {
options =
new CreateCollectionCommand.Options(
vectorSearchConfig, vectorizeConfig, null);
vectorSearchConfig, vectorizeConfig, indexingConfig);
}

// CreateCollectionCommand object is created for convenience to generate json
// response. The code is not creating a collection here.
return new CreateCollectionCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public void happyPathWithExplain() {
"vector": {
"dimension": 5,
"metric": "cosine"
},
"indexing": {
"deny" : ["comment"]
}
}
}
Expand Down Expand Up @@ -117,6 +120,8 @@ public void happyPathWithExplain() {
"vector": {
"dimension": 5,
"metric": "cosine"
},"indexing": {
"deny" : ["comment"]
}
}
}
Expand Down Expand Up @@ -304,6 +309,77 @@ public void notExistingNamespace() {
"errors[0].message",
is("Unknown namespace should_not_be_there, you must create it first."));
}

@Test
@Order(7)
public void happyPathIndexingWithExplain() {
String json =
"""
{
"createCollection": {
"name": "%s",
"options": {
"indexing": {
"deny" : ["comment"]
}
}
}
}
"""
.formatted("collection4");

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));

String expected1 = """
{"name":"TableName"}
""";
String expected2 = """
{"name":"collection1"}
""";
String expected3 =
"""
{"name":"collection2", "options": {"vector": {"dimension":5, "metric":"cosine"}, "indexing":{"deny":["comment"]}}}
""";
String expected4 =
"""
{"name":"collection4", "options":{"indexing":{"deny":["comment"]}}}
""";
json =
"""
{
"findCollections": {
"options": {
"explain" : true
}
}
}
""";

given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(json)
.when()
.post(NamespaceResource.BASE_PATH, namespaceName)
.then()
.statusCode(200)
.body("status.collections", hasSize(4))
.body(
"status.collections",
containsInAnyOrder(
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we only expect 'expected4' here.
No need for expected1, expected2, expected3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

find collection returns all the collection created thus far. So add all 4.

jsonEquals(expected1),
jsonEquals(expected2),
jsonEquals(expected3),
jsonEquals(expected4)));
}
}

@Nested
Expand Down