-
Notifications
You must be signed in to change notification settings - Fork 226
Add model version to model metadata and change model metadata reads to be from cluster metadata #2005
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
Merged
naveentatikonda
merged 13 commits into
opensearch-project:main
from
ryanbogan:add_model_version
Sep 5, 2024
Merged
Add model version to model metadata and change model metadata reads to be from cluster metadata #2005
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
71f4fe9
Add model version to model metadata
55881f8
Add model version to model metadata and change model metadata reads t…
5d64e01
Add changelog entry
368d88a
Set version from config context
e3159ce
Fix spotless
5f2d6a6
Update model index mappings
255c566
Merge branch 'main' into add_model_version
e316842
Merge branch 'main' into add_model_version
884a9e2
Change field mapper to read model version
66a6f69
Merge branch 'main' into add_model_version
dc66414
Fix tests
28ddef8
remove println
jmazanec15 dda1f0d
Merge branch 'main' into add_model_version
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| import lombok.extern.log4j.Log4j2; | ||
| import org.apache.commons.lang.builder.EqualsBuilder; | ||
| import org.apache.commons.lang.builder.HashCodeBuilder; | ||
| import org.opensearch.Version; | ||
| import org.opensearch.common.xcontent.json.JsonXContent; | ||
| import org.opensearch.core.common.io.stream.StreamInput; | ||
| import org.opensearch.core.common.io.stream.StreamOutput; | ||
|
|
@@ -59,14 +60,14 @@ public class ModelMetadata implements Writeable, ToXContentObject { | |
| private String error; | ||
| @Getter | ||
| private final CompressionLevel compressionLevel; | ||
| private final Version version; | ||
|
|
||
| /** | ||
| * Constructor | ||
| * | ||
| * @param in Stream input | ||
| */ | ||
| public ModelMetadata(StreamInput in) throws IOException { | ||
| String tempTrainingNodeAssignment; | ||
| this.knnEngine = KNNEngine.getEngine(in.readString()); | ||
| this.spaceType = SpaceType.getSpace(in.readString()); | ||
| this.dimension = in.readInt(); | ||
|
|
@@ -96,7 +97,6 @@ public ModelMetadata(StreamInput in) throws IOException { | |
| } else { | ||
| this.vectorDataType = VectorDataType.DEFAULT; | ||
| } | ||
|
|
||
| if (IndexUtil.isVersionOnOrAfterMinRequiredVersion(in.getVersion(), KNNConstants.MINIMAL_MODE_AND_COMPRESSION_FEATURE)) { | ||
| this.mode = Mode.fromName(in.readOptionalString()); | ||
| this.compressionLevel = CompressionLevel.fromName(in.readOptionalString()); | ||
|
|
@@ -105,6 +105,11 @@ public ModelMetadata(StreamInput in) throws IOException { | |
| this.compressionLevel = CompressionLevel.NOT_CONFIGURED; | ||
| } | ||
|
|
||
| if (IndexUtil.isVersionOnOrAfterMinRequiredVersion(in.getVersion(), KNNConstants.MODEL_VERSION)) { | ||
| this.version = Version.fromString(in.readString()); | ||
| } else { | ||
| this.version = Version.V_EMPTY; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -133,7 +138,8 @@ public ModelMetadata( | |
| MethodComponentContext methodComponentContext, | ||
| VectorDataType vectorDataType, | ||
| Mode mode, | ||
| CompressionLevel compressionLevel | ||
| CompressionLevel compressionLevel, | ||
| Version version | ||
| ) { | ||
| this.knnEngine = Objects.requireNonNull(knnEngine, "knnEngine must not be null"); | ||
| this.spaceType = Objects.requireNonNull(spaceType, "spaceType must not be null"); | ||
|
|
@@ -159,6 +165,7 @@ public ModelMetadata( | |
| this.vectorDataType = Objects.requireNonNull(vectorDataType, "vector data type must not be null"); | ||
| this.mode = Objects.requireNonNull(mode, "Mode must not be null"); | ||
| this.compressionLevel = Objects.requireNonNull(compressionLevel, "Compression level must not be null"); | ||
| this.version = Objects.requireNonNull(version, "model version must not be null"); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -246,6 +253,14 @@ public VectorDataType getVectorDataType() { | |
| return vectorDataType; | ||
| } | ||
|
|
||
| /** | ||
| * Getter for the model version | ||
| * @return version | ||
| */ | ||
| public Version getModelVersion() { | ||
| return version; | ||
| } | ||
|
|
||
| /** | ||
| * setter for model's state | ||
| * | ||
|
|
@@ -279,7 +294,8 @@ public String toString() { | |
| methodComponentContext.toClusterStateString(), | ||
| vectorDataType.getValue(), | ||
| mode.getName(), | ||
| compressionLevel.getName() | ||
| compressionLevel.getName(), | ||
| version.toString() | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -317,6 +333,7 @@ public int hashCode() { | |
| .append(getVectorDataType()) | ||
| .append(getMode()) | ||
| .append(getCompressionLevel()) | ||
| .append(getModelVersion()) | ||
| .toHashCode(); | ||
| } | ||
|
|
||
|
|
@@ -329,15 +346,15 @@ public int hashCode() { | |
| public static ModelMetadata fromString(String modelMetadataString) { | ||
| String[] modelMetadataArray = modelMetadataString.split(DELIMITER, -1); | ||
| int length = modelMetadataArray.length; | ||
|
|
||
| if (length < 7 || length > 12) { | ||
| if (length < 7 || length > 13) { | ||
| throw new IllegalArgumentException( | ||
| "Illegal format for model metadata. Must be of the form " | ||
| + "\"<KNNEngine>,<SpaceType>,<Dimension>,<ModelState>,<Timestamp>,<Description>,<Error>\" or " | ||
| + "\"<KNNEngine>,<SpaceType>,<Dimension>,<ModelState>,<Timestamp>,<Description>,<Error>,<NodeAssignment>\" or " | ||
| + "\"<KNNEngine>,<SpaceType>,<Dimension>,<ModelState>,<Timestamp>,<Description>,<Error>,<NodeAssignment>,<MethodContext>\" or " | ||
| + "\"<KNNEngine>,<SpaceType>,<Dimension>,<ModelState>,<Timestamp>,<Description>,<Error>,<NodeAssignment>,<MethodContext>,<VectorDataType>\". or " | ||
| + "\"<KNNEngine>,<SpaceType>,<Dimension>,<ModelState>,<Timestamp>,<Description>,<Error>,<NodeAssignment>,<MethodContext>,<VectorDataType>,<Mode>,<CompressionLevel>\"." | ||
| + "\"<KNNEngine>,<SpaceType>,<Dimension>,<ModelState>,<Timestamp>,<Description>,<Error>,<NodeAssignment>,<MethodContext>,<VectorDataType>,<Mode>,<CompressionLevel>\" or " | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FAR: since Mode, CLevel and Version are all same release, we can simplify this. |
||
| + "\"<KNNEngine>,<SpaceType>,<Dimension>,<ModelState>,<Timestamp>,<Description>,<Error>,<NodeAssignment>,<MethodContext>,<VectorDataType>,<Mode>,<CompressionLevel>,<Version>\"." | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -357,6 +374,7 @@ public static ModelMetadata fromString(String modelMetadataString) { | |
| CompressionLevel compressionLevel = length > 11 | ||
| ? CompressionLevel.fromName(modelMetadataArray[11]) | ||
| : CompressionLevel.NOT_CONFIGURED; | ||
| Version version = length > 12 ? Version.fromString(modelMetadataArray[12]) : Version.V_EMPTY; | ||
|
|
||
| log.debug(getLogMessage(length)); | ||
|
|
||
|
|
@@ -372,7 +390,8 @@ public static ModelMetadata fromString(String modelMetadataString) { | |
| methodComponentContext, | ||
| vectorDataType, | ||
| mode, | ||
| compressionLevel | ||
| compressionLevel, | ||
| version | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -386,9 +405,10 @@ private static String getLogMessage(int length) { | |
| return "Model metadata contains training node assignment and method context."; | ||
| case 10: | ||
| return "Model metadata contains training node assignment, method context and vector data type."; | ||
| case 11: | ||
| case 12: | ||
| return "Model metadata contains mode and compression level"; | ||
| case 13: | ||
| return "Model metadata contains training node assignment, method context, vector data type, and version"; | ||
| default: | ||
| throw new IllegalArgumentException("Unexpected metadata array length: " + length); | ||
| } | ||
|
|
@@ -423,6 +443,7 @@ public static ModelMetadata getMetadataFromSourceMap(final Map<String, Object> m | |
| Object vectorDataType = modelSourceMap.get(KNNConstants.VECTOR_DATA_TYPE_FIELD); | ||
| Object mode = modelSourceMap.get(KNNConstants.MODE_PARAMETER); | ||
| Object compressionLevel = modelSourceMap.get(KNNConstants.COMPRESSION_LEVEL_PARAMETER); | ||
| Object version = modelSourceMap.get(KNNConstants.MODEL_VERSION); | ||
|
|
||
| if (trainingNodeAssignment == null) { | ||
| trainingNodeAssignment = ""; | ||
|
|
@@ -447,6 +468,10 @@ public static ModelMetadata getMetadataFromSourceMap(final Map<String, Object> m | |
| vectorDataType = VectorDataType.DEFAULT.getValue(); | ||
| } | ||
|
|
||
| if (version == null) { | ||
| version = Version.V_EMPTY; | ||
| } | ||
|
|
||
| ModelMetadata modelMetadata = new ModelMetadata( | ||
| KNNEngine.getEngine(objectToString(engine)), | ||
| SpaceType.getSpace(objectToString(space)), | ||
|
|
@@ -459,7 +484,8 @@ public static ModelMetadata getMetadataFromSourceMap(final Map<String, Object> m | |
| (MethodComponentContext) methodComponentContext, | ||
| VectorDataType.get(objectToString(vectorDataType)), | ||
| Mode.fromName(objectToString(mode)), | ||
| CompressionLevel.fromName(objectToString(compressionLevel)) | ||
| CompressionLevel.fromName(objectToString(compressionLevel)), | ||
| Version.fromString(version.toString()) | ||
| ); | ||
| return modelMetadata; | ||
| } | ||
|
|
@@ -486,6 +512,9 @@ public void writeTo(StreamOutput out) throws IOException { | |
| out.writeOptionalString(mode.getName()); | ||
| out.writeOptionalString(compressionLevel.getName()); | ||
| } | ||
| if (IndexUtil.isVersionOnOrAfterMinRequiredVersion(out.getVersion(), KNNConstants.MODEL_VERSION)) { | ||
| out.writeString(version.toString()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -517,6 +546,13 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws | |
| builder.field(KNNConstants.COMPRESSION_LEVEL_PARAMETER, compressionLevel.getName()); | ||
| } | ||
| } | ||
| if (IndexUtil.isClusterOnOrAfterMinRequiredVersion(KNNConstants.MODEL_VERSION)) { | ||
| String versionString = "unknown"; | ||
| if (version != Version.V_EMPTY) { | ||
| versionString = version.toString(); | ||
| } | ||
| builder.field(KNNConstants.MODEL_VERSION, versionString); | ||
| } | ||
| return builder; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,9 @@ | |
| }, | ||
| "compression_level": { | ||
| "type": "keyword" | ||
| }, | ||
| "model_version": { | ||
| "type": "keyword" | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.