-
Notifications
You must be signed in to change notification settings - Fork 132
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
Add support for search using the "fields" parameter with knn_vector field #2314
base: main
Are you sure you want to change the base?
Add support for search using the "fields" parameter with knn_vector field #2314
Conversation
Signed-off-by: Ethan Emoto <[email protected]>
@e-emoto please fix the failing CIs |
Signed-off-by: Ethan Emoto <[email protected]>
Signed-off-by: Ethan Emoto <[email protected]>
Signed-off-by: Ethan Emoto <[email protected]>
@@ -51,7 +52,12 @@ public KNNVectorFieldType(String name, Map<String, String> metadata, VectorDataT | |||
|
|||
@Override | |||
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) { | |||
throw new UnsupportedOperationException("KNN Vector do not support fields search"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this format variable do? Do we have to add any check for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also do you see problem with backward compatibility? Does this work for index created before 2.19?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this format variable do? Do we have to add any check for that?
I'm not sure exactly what it does, in my testing it was always null when valueFetcher
was called for KNNVectorFieldType.
Also do you see problem with backward compatibility? Does this work for index created before 2.19?
I don't see any reason why it would have issues with backward compatibility, but how would I test this to confirm it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is change in query path, I don't see any reason why BWC will fail.
Signed-off-by: Ethan Emoto <[email protected]>
XContentBuilder builder = XContentFactory.jsonBuilder() | ||
.startObject() | ||
.field("fields", new String[] { "*" }) | ||
.startObject("query") | ||
.startObject("match_all") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we are using a match all query here? Since a query is a query and it will solve the purpose, I would recommend having both match_all and a k-NN query to ensure that all cases are covered.
can you add the manual testing result on the PR? |
@@ -51,7 +52,12 @@ public KNNVectorFieldType(String name, Map<String, String> metadata, VectorDataT | |||
|
|||
@Override | |||
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) { | |||
throw new UnsupportedOperationException("KNN Vector do not support fields search"); | |||
return new ArraySourceValueFetcher(name(), context) { | |||
@Override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a UT for this.
@@ -51,7 +52,12 @@ public KNNVectorFieldType(String name, Map<String, String> metadata, VectorDataT | |||
|
|||
@Override | |||
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) { | |||
throw new UnsupportedOperationException("KNN Vector do not support fields search"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is change in query path, I don't see any reason why BWC will fail.
@@ -900,6 +901,136 @@ public void testKNNIndex_whenBuildVectorGraphThresholdIsProvidedEndToEnd_thenBui | |||
deleteKNNIndex(indexName); | |||
} | |||
|
|||
public void testKNNIndexSearchFieldsParameter() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also lets add an IT test where some the docs don't have vector field and some have vector field in it.
Signed-off-by: Ethan Emoto <[email protected]>
Signed-off-by: Ethan Emoto <[email protected]>
Signed-off-by: Ethan Emoto <[email protected]>
Signed-off-by: Ethan Emoto <[email protected]>
Signed-off-by: Ethan Emoto <[email protected]>
return new ArraySourceValueFetcher(name(), context) { | ||
@Override | ||
protected Object parseSourceValue(Object value) { | ||
if (value instanceof ArrayList) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this, I am not sure what is exactly expected from this method. Im thinking maybe we follow what the completion mapper did and if its not a list, just wrap it in a list: https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/java/org/opensearch/index/mapper/CompletionFieldMapper.java#L394-L398.
@shatejas @navneet1v what do you guys think?
Description
This change implements valueFetcher in KNNVectorFieldType so search can support using the "fields" parameter when used with the knn_vector field type. ITs for this change were added to OpenSearchIT after the change was tested manually.
Manual Testing Output
Related Issues
Resolves #1633
Check List
--signoff
.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.