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

Support vector field in projection clause #481

Merged
merged 2 commits into from
Jul 28, 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 @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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()));
}

Expand All @@ -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
Expand All @@ -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()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ public void testSimpleIncludeWithId() throws Exception {
},
"nested2" : {
"z": 5
}
},
"$vector" : [0.11, 0.22, 0.33, 0.44]
}
""");
DocumentProjector projection =
Expand All @@ -275,7 +276,8 @@ public void testSimpleIncludeWithId() throws Exception {
"x": 1
},
"nested.z": 1,
"nosuchprop": 1
"nosuchprop": 1,
"$vector": 1
}
"""));
assertThat(projection.isInclusion()).isTrue();
Expand All @@ -289,7 +291,8 @@ public void testSimpleIncludeWithId() throws Exception {
"nested" : {
"x": 3,
"z": -1
}
},
"$vector" : [0.11, 0.22, 0.33, 0.44]
}
"""));
}
Expand Down Expand Up @@ -392,7 +395,8 @@ public void excludeWithIdIncluded() throws Exception {
},
"nested2" : {
"z": 5
}
},
"$vector" : [0.11, 0.22, 0.33, 0.44]
}
""");
DocumentProjector projection =
Expand All @@ -405,7 +409,8 @@ public void excludeWithIdIncluded() throws Exception {
"x": 0
},
"nested.z": 0,
"nosuchprop": 0
"nosuchprop": 0,
"$vector": 0
}
"""));
assertThat(projection.isInclusion()).isFalse();
Expand Down