Skip to content
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

Merged
merged 10 commits into from
Mar 15, 2024

Conversation

ryanbogan
Copy link
Member

@ryanbogan ryanbogan commented Mar 12, 2024

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

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed as per the DCO using --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.

Copy link

codecov bot commented Mar 12, 2024

Codecov Report

Attention: Patch coverage is 82.00000% with 27 lines in your changes are missing coverage. Please review.

Project coverage is 84.86%. Comparing base (b7bdda4) to head (f3a5521).
Report is 3 commits behind head on main.

Files Patch % Lines
...g/opensearch/knn/index/MethodComponentContext.java 80.00% 8 Missing and 11 partials ⚠️
...java/org/opensearch/knn/indices/ModelMetadata.java 82.97% 5 Missing and 3 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

CHANGELOG.md Outdated Show resolved Hide resolved
return stringBuilder.toString();
}

public static MethodComponentContext fromString(String in) {
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need "\"?

Copy link
Member Author

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 {

Copy link
Member

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.

Copy link
Member Author

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 ;


String[] outerMethodComponentContextArray = in.split("\\{", -1);

if (outerMethodComponentContextArray[index].isEmpty()) {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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

@jmazanec15
Copy link
Member

@ryanbogan In PR description, can you add longer description of the change?

@jmazanec15
Copy link
Member

@jmazanec15 jmazanec15 mentioned this pull request Mar 12, 2024
5 tasks
@ryanbogan ryanbogan changed the title Add MethodComponentContext to ModelMetadata Persist model definition in model metadata Mar 12, 2024
Signed-off-by: Ryan Bogan <[email protected]>
@ryanbogan
Copy link
Member Author

public static MethodComponentContext fromString(String in) {
int index = 0;

String[] outerMethodComponentContextArray = in.split("\\{", -1);
Copy link
Member

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;]};]}
Copy link
Member

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?

Copy link
Member Author

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.

Signed-off-by: Ryan Bogan <[email protected]>
Signed-off-by: Ryan Bogan <[email protected]>
return stringBuilder.toString();
}

public static MethodComponentContext fromString(String in) {
Copy link
Member

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]>
Signed-off-by: Ryan Bogan <[email protected]>
Signed-off-by: Ryan Bogan <[email protected]>
Signed-off-by: Ryan Bogan <[email protected]>
Copy link
Member

@jmazanec15 jmazanec15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm thanks!

@ryanbogan ryanbogan merged commit 4734d88 into opensearch-project:main Mar 15, 2024
50 of 51 checks passed
@ryanbogan ryanbogan deleted the model_definition branch March 15, 2024 18:24
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 1

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 base branch is 2.x and the compare/head branch is backport/backport-1527-to-2.x.

ryanbogan added a commit that referenced this pull request Mar 15, 2024
* 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)
ryanbogan added a commit that referenced this pull request Mar 15, 2024
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants