-
Notifications
You must be signed in to change notification settings - Fork 74
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 builder constructor in neural query builder #1047
add support for builder constructor in neural query builder #1047
Conversation
@@ -23,6 +23,7 @@ | |||
import java.util.Objects; | |||
import java.util.function.Supplier; | |||
|
|||
import lombok.Builder; |
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.
I think we want to validate the NeuralQueryBuilder before we create it like what we are doing in the KNNQueryBuilder. And to enforce this we will also need to either remove @NoArgsConstructor
@AllArgsConstructor or make them private.
Currently I think the builder is mainly used for our internal testing but I think it's good to enforce that only valid NeuralQueryBuilder can be created through our builder in case in future people accidentally use it create some invalid NeuralQueryBuilder in our business logic.
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.
Besides I think currently we are using AllArgsConstructor to create NeuralQueryBuilder for some tests can we replace them with the builder you add? In this way if we need to add a new field we don't need to modify the tests that don't care about the new field.
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.
+1 to @bzhangam's comment. You can have reference from kNN's query builder: https://github.com/opensearch-project/k-NN/blob/main/src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java#L142
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.
addressed in the newest commit
Please sign off your commits and add this PR to CHANGELOG. |
344c2ef
to
b98e6d0
Compare
src/main/java/org/opensearch/neuralsearch/query/NeuralQueryBuilder.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/neuralsearch/query/NeuralQueryBuilder.java
Outdated
Show resolved
Hide resolved
Signed-off-by: will-hwang <[email protected]>
…tantiation Signed-off-by: will-hwang <[email protected]>
Signed-off-by: will-hwang <[email protected]>
3b4fbf1
to
d8b7fe5
Compare
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 there are no changes in any of the callers? If we made both existing constructors private then I assume we should replace calls to that constructor(s) with the new builder class
src/main/java/org/opensearch/neuralsearch/query/NeuralQueryBuilder.java
Outdated
Show resolved
Hide resolved
public NeuralQueryBuilder build() { | ||
validateQueryParameters(fieldName, queryText, queryImage); | ||
int k = this.k == null ? DEFAULT_K : this.k; | ||
boolean queryTypeIsProvided = validateKNNQueryType(k, maxDistance, minScore); |
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're adding this logic here, it wasn't part of the original constructor?
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.
As part of this change, we wanted to add validation before instantiation so ensure that only valid NeuralSearchBuilder
can be instantiated. See previous comment here: #1047 (comment)
Let me know your thoughts!
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.
I'm rely on @junqiu-lei expertise here, I'm good if he's good
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.
I think we don't need int k = this.k == null ? DEFAULT_K : this.k;
at line 204.
If the default k is provided before validateKNNQueryType, when user use radial search parameter(only provide minScore or maxDistance), then validateKNNQueryType
will return false and set to use default k at line 207.
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.
The CI is failed in radial integ test due to this change:
NeuralQueryIT > testQueryWithBoostAndImageQueryAndRadialQuery FAILED
java.lang.IllegalArgumentException: Only one of k, max_distance, or min_score can be provided
at __randomizedtesting.SeedInfo.seed([D0122DFF0BE48EA8:885F5A920D6E8D5B]:0)
at org.opensearch.neuralsearch.query.NeuralQueryBuilder.validateKNNQueryType(NeuralQueryBuilder.java:540)
at org.opensearch.neuralsearch.query.NeuralQueryBuilder$Builder.build(NeuralQueryBuilder.java:205)
at org.opensearch.neuralsearch.query.NeuralQueryIT.testQueryWithBoostAndImageQueryAndRadialQuery(NeuralQueryIT.java:151)
@martin-gaievski All the callers have been changed to the new builder class. See the changes in all 14 files |
Those are all test classes; I mean classes related to application logic. I do see one reference that hasn't been changed (https://github.com/opensearch-project/neural-search/blob/main/src/main/java/org/opensearch/neuralsearch/plugin/NeuralSearch.java#L112). Do you have an idea why that hasn't been changed after you made the constructor private? |
Signed-off-by: will-hwang <[email protected]>
As per
the parameter expects a Reader type, not a NeuralSearchQuery instance. I believe this is why compiler allows |
The |
…earch into support_for_builder_in_neural_query_builder
Signed-off-by: will-hwang <[email protected]>
…_in_neural_query_builder
Signed-off-by: will-hwang <[email protected]>
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.
Looks good to me
* add support for builder constructor in neural query builder Signed-off-by: will-hwang <[email protected]> * create custom builder class to enforce valid neural query builder instantiation Signed-off-by: will-hwang <[email protected]> * refactor code to remove duplicate Signed-off-by: will-hwang <[email protected]> * include new constructor in qa packages Signed-off-by: will-hwang <[email protected]> * refactor code to remove unnecessary code Signed-off-by: will-hwang <[email protected]> * fix bug in neural query builder instantiation Signed-off-by: will-hwang <[email protected]> --------- Signed-off-by: will-hwang <[email protected]> (cherry picked from commit 2ecd32c)
…ch-project#1047) * add support for builder constructor in neural query builder Signed-off-by: will-hwang <[email protected]> * create custom builder class to enforce valid neural query builder instantiation Signed-off-by: will-hwang <[email protected]> * refactor code to remove duplicate Signed-off-by: will-hwang <[email protected]> * include new constructor in qa packages Signed-off-by: will-hwang <[email protected]> * refactor code to remove unnecessary code Signed-off-by: will-hwang <[email protected]> * fix bug in neural query builder instantiation Signed-off-by: will-hwang <[email protected]> --------- Signed-off-by: will-hwang <[email protected]> (cherry picked from commit 2ecd32c)
…ch-project#1047) * add support for builder constructor in neural query builder Signed-off-by: will-hwang <[email protected]> * create custom builder class to enforce valid neural query builder instantiation Signed-off-by: will-hwang <[email protected]> * refactor code to remove duplicate Signed-off-by: will-hwang <[email protected]> * include new constructor in qa packages Signed-off-by: will-hwang <[email protected]> * refactor code to remove unnecessary code Signed-off-by: will-hwang <[email protected]> * fix bug in neural query builder instantiation Signed-off-by: will-hwang <[email protected]> --------- Signed-off-by: will-hwang <[email protected]> (cherry picked from commit 2ecd32c)
…ch-project#1047) * add support for builder constructor in neural query builder Signed-off-by: will-hwang <[email protected]> * create custom builder class to enforce valid neural query builder instantiation Signed-off-by: will-hwang <[email protected]> * refactor code to remove duplicate Signed-off-by: will-hwang <[email protected]> * include new constructor in qa packages Signed-off-by: will-hwang <[email protected]> * refactor code to remove unnecessary code Signed-off-by: will-hwang <[email protected]> * fix bug in neural query builder instantiation Signed-off-by: will-hwang <[email protected]> --------- Signed-off-by: will-hwang <[email protected]> (cherry picked from commit 2ecd32c) Signed-off-by: will-hwang <[email protected]>
…ilder (#1084) * add support for builder constructor in neural query builder (#1047) Signed-off-by: will-hwang <[email protected]>
* add support for builder constructor in neural query builder Signed-off-by: will-hwang <[email protected]> * create custom builder class to enforce valid neural query builder instantiation Signed-off-by: will-hwang <[email protected]> * refactor code to remove duplicate Signed-off-by: will-hwang <[email protected]> * include new constructor in qa packages Signed-off-by: will-hwang <[email protected]> * refactor code to remove unnecessary code Signed-off-by: will-hwang <[email protected]> * fix bug in neural query builder instantiation Signed-off-by: will-hwang <[email protected]> --------- Signed-off-by: will-hwang <[email protected]>
* add support for builder constructor in neural query builder Signed-off-by: will-hwang <[email protected]> * create custom builder class to enforce valid neural query builder instantiation Signed-off-by: will-hwang <[email protected]> * refactor code to remove duplicate Signed-off-by: will-hwang <[email protected]> * include new constructor in qa packages Signed-off-by: will-hwang <[email protected]> * refactor code to remove unnecessary code Signed-off-by: will-hwang <[email protected]> * fix bug in neural query builder instantiation Signed-off-by: will-hwang <[email protected]> --------- Signed-off-by: will-hwang <[email protected]>
Description
Adds support for builder constructor for Neural Query Builder
This PR adds support for builder constructor with
@Builder
lombok annotation inNeuralQueryBuilder
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
#1025
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.