diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/projection/DocumentProjector.java b/src/main/java/io/stargate/sgv2/jsonapi/service/projection/DocumentProjector.java index a48f6231ac..e29260864a 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/projection/DocumentProjector.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/projection/DocumentProjector.java @@ -138,7 +138,8 @@ PathCollector collectFromObject(JsonNode ob, String parentPath) { ErrorCode.UNSUPPORTED_PROJECTION_PARAM.getMessage() + ": empty paths (and path segments) not allowed"); } - if (path.charAt(0) == '$') { + if (path.charAt(0) == '$' + && !path.equals(DocumentConstants.Fields.VECTOR_EMBEDDING_FIELD)) { // First: no operators allowed at root level if (parentPath == null) { throw new JsonApiException( diff --git a/src/test/java/io/stargate/sgv2/jsonapi/api/v1/VectorSearchIntegrationTest.java b/src/test/java/io/stargate/sgv2/jsonapi/api/v1/VectorSearchIntegrationTest.java index f8539eee58..b5d6bc2ff5 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/api/v1/VectorSearchIntegrationTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/api/v1/VectorSearchIntegrationTest.java @@ -392,6 +392,7 @@ public void happyPath() { { "find": { "sort" : {"$vector" : [0.15, 0.1, 0.1, 0.35, 0.55]}, + "projection" : {"_id" : 1, "$vector" : 1}, "options" : { "limit" : 5 } @@ -408,8 +409,11 @@ public void happyPath() { .then() .statusCode(200) .body("data.documents[0]._id", is("3")) + .body("data.documents[0].$vector", is(notNullValue())) .body("data.documents[1]._id", is("2")) + .body("data.documents[1].$vector", is(notNullValue())) .body("data.documents[2]._id", is("1")) + .body("data.documents[2].$vector", is(notNullValue())) .body("errors", is(nullValue())); } @@ -421,6 +425,7 @@ public void happyPathWithFilter() { { "find": { "filter" : {"_id" : "1"}, + "projection" : {"_id" : 1, "$vector" : 0}, "sort" : {"$vector" : [0.15, 0.1, 0.1, 0.35, 0.55]}, "options" : { "limit" : 5 @@ -438,6 +443,7 @@ public void happyPathWithFilter() { .then() .statusCode(200) .body("data.documents[0]._id", is("1")) + .body("data.documents[0].$vector", is(nullValue())) .body("errors", is(nullValue())); } diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/projection/DocumentProjectorTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/projection/DocumentProjectorTest.java index 20d57927e0..7721db0ede 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/projection/DocumentProjectorTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/projection/DocumentProjectorTest.java @@ -263,7 +263,8 @@ public void testSimpleIncludeWithId() throws Exception { }, "nested2" : { "z": 5 - } + }, + "$vector" : [0.11, 0.22, 0.33, 0.44] } """); DocumentProjector projection = @@ -275,7 +276,8 @@ public void testSimpleIncludeWithId() throws Exception { "x": 1 }, "nested.z": 1, - "nosuchprop": 1 + "nosuchprop": 1, + "$vector": 1 } """)); assertThat(projection.isInclusion()).isTrue(); @@ -289,7 +291,8 @@ public void testSimpleIncludeWithId() throws Exception { "nested" : { "x": 3, "z": -1 - } + }, + "$vector" : [0.11, 0.22, 0.33, 0.44] } """)); } @@ -392,7 +395,8 @@ public void excludeWithIdIncluded() throws Exception { }, "nested2" : { "z": 5 - } + }, + "$vector" : [0.11, 0.22, 0.33, 0.44] } """); DocumentProjector projection = @@ -405,7 +409,8 @@ public void excludeWithIdIncluded() throws Exception { "x": 0 }, "nested.z": 0, - "nosuchprop": 0 + "nosuchprop": 0, + "$vector": 0 } """)); assertThat(projection.isInclusion()).isFalse();