-
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 stats for radial search #1684
Conversation
f67c80e
to
c812547
Compare
@@ -566,4 +566,23 @@ private static void validateSingleQueryType(Integer k, Float distance, Float sco | |||
throw new IllegalArgumentException(String.format("[%s] requires exactly one of k, distance or score to be set", NAME)); | |||
} | |||
} | |||
|
|||
private static void updateQueryStats(Integer k, Float minScore, Float maxDistance, QueryBuilder 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.
nit: you can clean this up a bit more to reduce if else. every parameter similar to k or maxDistance we add, will add to the if else statements.
validateSingleQuery()
updateQueryStats(k, ...)
updateQueryStats(minScore, ...)
updateQueryStats(maxDistance, ...)
static <T> void updateQueryStats(T queyParam, QueryBuilder filter, queryCounter, filtercounter) {
if (queyParam != null) {
queryCounter.increment();
if (filter != null) {
filtercounter.increment();
}
}
}
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 @shatejas, this suggestion could reduce the function code itself, but looks like we still need extra multiple time calls at same place. Beside the k
is Integer type, maxDistance
and minScore
are Float type, we couldn't directly use parameter T queyParam
for all of them.
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.
@junqiu-lei Why not use Object?
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.
@VijayanB I don't see obviously benefit to introduce Object for this internal used function. Besides if we introduce the Object, we anyway need the condition check for which query type and query counter to use somewhere else.
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.
@junqiu-lei yeah extra calls is sometimes a good trade off for maintainability. the cost here shouldn't be high but correct me if I am missing something
@VijayanB On the object suggestion, a few thoughts - The method itself is doing quite a few things - parsing, building query builder, validating and adding stats. Its generally an indication to break it down. What we can actually do is start building query builder while parsing and once we build the KNNQueryBuilder we can validate the entire object as a whole and then update the stats for it as a whole, that way you don't need an extra object.
psuedo code to better understand
KnnQueryBuilder querybuilder = parseAndBuild(XContentparser) //Note there are no validations here
validate(querybuilder); //This throws if any of the validations fail
updateStats(querybuilder); //update stats
Having said this, its too much of a refactor so I wouldn't want to club it with this PR and can be punted till absolutely needed
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.
Just had offline sync with @shatejas, I've updated this method to use generic parameter for queryParam
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 check my comment: #1684 (comment)
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.
Updated PR on your comment @navneet1v
src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Junqiu Lei <[email protected]>
Signed-off-by: Junqiu Lei <[email protected]>
Signed-off-by: Junqiu Lei <[email protected]>
Signed-off-by: Junqiu Lei <[email protected]>
Signed-off-by: Junqiu Lei <[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.
One minor comment but overall looks good to me. Great job on abstracting the QueryType.
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-1684-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 9a52b2bcd4d7e0a05368d8d689b50971f44c6489
# Push it to GitHub
git push --set-upstream origin backport/backport-1684-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x Then, create a pull request where the |
Signed-off-by: Junqiu Lei <[email protected]> (cherry picked from commit 9a52b2b) Signed-off-by: Junqiu Lei <[email protected]>
(cherry picked from commit 9a52b2b) Signed-off-by: Junqiu Lei <[email protected]>
Signed-off-by: Junqiu Lei <[email protected]>
Signed-off-by: Junqiu Lei <[email protected]>
Description
Add radial search stats into k-NN plugin stats api, the new stats have:
Stats API example
Response details
Issues Resolved
[List any issues this PR will resolve]
Check List
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.