-
Notifications
You must be signed in to change notification settings - Fork 83
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 filter function for NeuralQueryBuilder and HybridQueryBuilder and… #1206
base: main
Are you sure you want to change the base?
Conversation
src/main/java/org/opensearch/neuralsearch/query/HybridQueryBuilder.java
Outdated
Show resolved
Hide resolved
if (!validateFilterParams(filter)) { | ||
return this; | ||
} | ||
HybridQueryBuilder compoundQueryBuilder = new HybridQueryBuilder(); |
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 do we have to create a new query builder instead of returning this
?
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 cannot find validateFilterParams method. Besides that the naming is confusing, if you conclude validity of the object based on return value that needs to be in the name, something like isValidFilterParams
. Also change negation to an explicit == false
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 method is added in core. opensearch-project/OpenSearch#17409
Should we have to use that method? Can we just do null check explicitly here instead of relying on the method?
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.
Hi the validateFilterParams is in the core package, inside the AbstractQueryBuilder class. https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/java/org/opensearch/index/query/AbstractQueryBuilder.java#L94
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 do we have to create a new query builder instead of returning
this
?
Because I saw the the queries of HybridQueryBuilder is marked as final. https://github.com/opensearch-project/neural-search/blob/main/src/main/java/org/opensearch/neuralsearch/query/HybridQueryBuilder.java#L56
So I think as we need to reassign a list of queries to the queries variable inside the HybridQueryBuilder. So we can only create a new HybridQueryBuilder to solve this?
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.
Wouldn't this double the filters sizes? Like if there are two filters, when we add(query.filter(filter)), wouldn't this create duplicate filters?
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.
Thanks Martin for the comment! Actually the function name
validateFilterParams
was suggested by Daniel in the pull request of core package. opensearch-project/OpenSearch#17409 , is it okay to leave as what it is for now?if method is already there let's utilize it. Please use == false syntax instead of negation, I see you've used it in other places in your PR
Yep. Updated in the newer commit
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.
Quote reply
I think the filter input check is common across all the query builders. Although current check is simple of whether it equals to null, adding a function here can allow complicated logic changes in the future
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 you can do something like queries.set(i, queries.get(i).filter(filter));
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.
Gotcha!
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.
if (!validateFilterParams(filter)) { | ||
return this; | ||
} | ||
HybridQueryBuilder compoundQueryBuilder = new HybridQueryBuilder(); |
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 cannot find validateFilterParams method. Besides that the naming is confusing, if you conclude validity of the object based on return value that needs to be in the name, something like isValidFilterParams
. Also change negation to an explicit == false
Got it, makes sense then. Can you please mention same in the PR description and also update the link to the feature request issue under "Related issues"? If the filtering feature requires multiple PRs/building blocks I suggest you create a high-level meta issue and host smaller PRs under that meta issue. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1206 +/- ##
============================================
+ Coverage 81.80% 81.90% +0.09%
+ Complexity 2606 1312 -1294
============================================
Files 190 95 -95
Lines 8922 4482 -4440
Branches 1520 765 -755
============================================
- Hits 7299 3671 -3628
+ Misses 1032 514 -518
+ Partials 591 297 -294 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Gotcha. Thanks! |
* } | ||
*/ | ||
@SneakyThrows | ||
public void testQueryWithBoostAndFilterApplied() { |
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 add this IT? I think the filter function is an existing feature for neural query?
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.
Here we are testing whether adding another filter on NeuralQuery would be function as expected.
} | ||
}*/ | ||
@SneakyThrows | ||
private void testRangeQueryAsFilter(String indexName) { |
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 add this IT in PostFilterIT? Filter is different from post filter. I think we should either add it to the HybridQueryIT or create a new HybridQueryFilterIT.
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.
Do you plan to raise another PR to add tests for BWC? BWC tests are under the qa folder.
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 add this IT in PostFilterIT? Filter is different from post filter. I think we should either add it to the HybridQueryIT or create a new HybridQueryFilterIT.
+1, better add new class HybridQueryFilterIT
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.
Do you plan to raise another PR to add tests for BWC? BWC tests are under the qa folder.
I think the current bwc tests is blocking the merge. So I will do the bwc tests here in the same PR
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 add this IT in PostFilterIT? Filter is different from post filter. I think we should either add it to the HybridQueryIT or create a new HybridQueryFilterIT.
Sure. Will create a new HybridQueryFilterIT
… modify fromXContent function in HybridQueryBuilder to support filter field. Signed-off-by: Chloe Gao <chloewq@amazon.com>
… modify fromXContent function in HybridQueryBuilder to support filter field.
Description
Add filter function to NeuralQueryBuilder and HybridQueryBuilder, which allows to push down non null filter. One exception is that when HybridQueryBuilder has a nested HybridQueryBuilder, then calling the filter function will cause UnsupportedOperationException
Related Issues
Resolves #1206
Related: #282, #1135
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.