-
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
Persist model definition in model metadata #1527
Persist model definition in model metadata #1527
Conversation
Signed-off-by: Ryan Bogan <[email protected]>
Signed-off-by: Ryan Bogan <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1527 +/- ##
============================================
- Coverage 85.20% 84.86% -0.34%
- Complexity 1299 1327 +28
============================================
Files 171 171
Lines 5293 5432 +139
Branches 505 527 +22
============================================
+ Hits 4510 4610 +100
- Misses 571 595 +24
- Partials 212 227 +15 ☔ View full report in Codecov by Sentry. |
src/main/java/org/opensearch/knn/index/MethodComponentContext.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/MethodComponentContext.java
Outdated
Show resolved
Hide resolved
return stringBuilder.toString(); | ||
} | ||
|
||
public static MethodComponentContext fromString(String in) { |
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.
This method will need a few comments describing what it will do. Also, lets add java doc
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.
Added a java doc with a small description. Let me know if I need to add more
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.
name this fromClusterStateString for consistency.
public static MethodComponentContext fromString(String in) { | ||
int index = 0; | ||
|
||
String[] outerMethodComponentContextArray = in.split("\\{", -1); |
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 need "\"?
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 split method takes a regex as an input. { is a special character in regex so the \ escapes it to just split by {
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.
Can we avoid this by just confirming the first and last character are {} and then building a substring from then which is processed.
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 split still needs to be there for the recursion to work. Otherwise, I can't pass the whole substring of a nested MethodComponentContext because it will be split by ;
src/main/java/org/opensearch/knn/index/MethodComponentContext.java
Outdated
Show resolved
Hide resolved
|
||
String[] outerMethodComponentContextArray = in.split("\\{", -1); | ||
|
||
if (outerMethodComponentContextArray[index].isEmpty()) { |
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.
Can we split this into a few methods? maybe parse name and parse parameters?
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.
Sure, I'll try to see if it works.
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.
Added a parse parameters method. Didn't add a parse name method because it's only two lines
@ryanbogan In PR description, can you add longer description of the change? |
Signed-off-by: Ryan Bogan <[email protected]>
public static MethodComponentContext fromString(String in) { | ||
int index = 0; | ||
|
||
String[] outerMethodComponentContextArray = in.split("\\{", -1); |
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.
Can we avoid this by just confirming the first and last character are {} and then building a substring from then which is processed.
* | ||
* Provides a String representation of MethodComponentContext | ||
* Sample return: | ||
* {name=ivf;parameters=[nlist=4;type=fp16;encoder={name=sq;parameters=[nprobes=2;clip=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.
why do we need { and } at beginning and end? can we not skip 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.
I added those to help with the recursion if there is a nested MethodComponentContext object. Otherwise, there is no way to differentiate the object from a normal field.
src/main/java/org/opensearch/knn/index/MethodComponentContext.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Ryan Bogan <[email protected]>
Signed-off-by: Ryan Bogan <[email protected]>
return stringBuilder.toString(); | ||
} | ||
|
||
public static MethodComponentContext fromString(String in) { |
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.
name this fromClusterStateString for consistency.
Signed-off-by: Ryan Bogan <[email protected]>
Signed-off-by: Ryan Bogan <[email protected]>
src/main/java/org/opensearch/knn/index/MethodComponentContext.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/MethodComponentContext.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Ryan Bogan <[email protected]>
src/main/java/org/opensearch/knn/index/MethodComponentContext.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/MethodComponentContext.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/MethodComponentContext.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/MethodComponentContext.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/MethodComponentContext.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/MethodComponentContext.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/MethodComponentContext.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/MethodComponentContext.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/MethodComponentContext.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Ryan Bogan <[email protected]>
Signed-off-by: Ryan Bogan <[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.
lgtm thanks!
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-1527-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 4734d88b8b12ff3edd676e3a1f337fc814c8932f
# Push it to GitHub
git push --set-upstream origin backport/backport-1527-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 |
* Add MethodComponentContext to ModelMetadata Signed-off-by: Ryan Bogan <[email protected]> * Add changelog Signed-off-by: Ryan Bogan <[email protected]> * Address PR Comments Signed-off-by: Ryan Bogan <[email protected]> * Address PR Comments Signed-off-by: Ryan Bogan <[email protected]> * Change fromString Signed-off-by: Ryan Bogan <[email protected]> * Address PR Comments Signed-off-by: Ryan Bogan <[email protected]> * Address PR Comments Signed-off-by: Ryan Bogan <[email protected]> * Address PR Comments Signed-off-by: Ryan Bogan <[email protected]> * Fix spotless Signed-off-by: Ryan Bogan <[email protected]> --------- Signed-off-by: Ryan Bogan <[email protected]> (cherry picked from commit 4734d88)
* Persist model definition in model metadata (#1527) * Add MethodComponentContext to ModelMetadata Signed-off-by: Ryan Bogan <[email protected]> * Add changelog Signed-off-by: Ryan Bogan <[email protected]> * Address PR Comments Signed-off-by: Ryan Bogan <[email protected]> * Address PR Comments Signed-off-by: Ryan Bogan <[email protected]> * Change fromString Signed-off-by: Ryan Bogan <[email protected]> * Address PR Comments Signed-off-by: Ryan Bogan <[email protected]> * Address PR Comments Signed-off-by: Ryan Bogan <[email protected]> * Address PR Comments Signed-off-by: Ryan Bogan <[email protected]> * Fix spotless Signed-off-by: Ryan Bogan <[email protected]> --------- Signed-off-by: Ryan Bogan <[email protected]> (cherry picked from commit 4734d88) * Fix compile errors Signed-off-by: Ryan Bogan <[email protected]> * Fix compile error Signed-off-by: Ryan Bogan <[email protected]> * Fix imports Signed-off-by: Ryan Bogan <[email protected]> --------- Signed-off-by: Ryan Bogan <[email protected]>
Description
Adds MethodComponentContext to ModelMetadata. This allows developers and users to more easily access the model definition after the model has been created.
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.