Add internal connectors to external ML providers (Bedrock/SageMaker, etc) in the ml_inference processor#6772
Conversation
| // When a built-in connector was resolved for the model_id, send directly to the | ||
| // model provider (e.g. Bedrock) via the typed RemoteConnectorExecutor. | ||
| // All other model IDs continue to use the existing ml-commons path. |
There was a problem hiding this comment.
Should we still be requiring the "host" opensearch endpoint for this processor? Or will we eventually not require it if the model id / model is resolved.
There was a problem hiding this comment.
This is a good catch. In this case using the build-in connector the host is not needed so we can make it optional. It's only required when you want to use a model_id from the ml plugin.
| @JsonProperty("pre_process_function") | ||
| private String preProcessFunction; | ||
|
|
||
| @JsonProperty("post_process_function") | ||
| private String postProcessFunction; |
There was a problem hiding this comment.
These are the functions to pre-process and post-process the input and output data to ensure it fits the interphase of the "text-embedding" processors in AOS. These are only needed for realtime predictions. For the batch inference, these are not relevant. But eventually we will support realtime predict as another Action too so this is still defined here in the connector.
|
Some checkstyle errors failing the build: |
dlvenable
left a comment
There was a problem hiding this comment.
Thanks @Zhangxunmt for this great new feature!
Also, I really like the approach you took with the annotations and JSON SubType for reading the JSON configurations.
| this.connectorExecutor = buildConnectorExecutor(mlProcessorConfig, awsCredentialsSupplier); | ||
| } | ||
|
|
||
| private static RemoteConnectorExecutor buildConnectorExecutor(final MLProcessorConfig config, |
There was a problem hiding this comment.
With my refactoring suggestion below this would go into a new class.
| /** | ||
| * Model ID for Amazon Bedrock Titan Multi-modal Embeddings V1. | ||
| */ | ||
| public static final String TITAN_MULTIMODAL_EMBED_V1_MODEL_ID = "amazon.titan-embed-image-v1"; |
There was a problem hiding this comment.
Your PR description lists this:
"amazon.nova-2-multimodal-embeddings-v1:0" – Multimodal (text + image) embeddings
But I don't see it here.
There was a problem hiding this comment.
Yeah this model is bedrock supported for batch inference but only in the IAD region so I thought it can be added later. I will add it in the revision anyways.
|
|
||
| final HttpExecuteRequest executeRequest = HttpExecuteRequest.builder() | ||
| .request(signedRequest) | ||
| .contentStreamProvider(request.contentStreamProvider().orElse(null)) |
There was a problem hiding this comment.
I believe this should be:
signedRequest.contentStreamProvider().orElse(null)
This is currently providing the unsigned request.
There was a problem hiding this comment.
Sure updated. But I believe only this .request(signedRequest) matters. The contentStreamProvider should be the same between signedRequest and request. This code has been verified running fine actually.
dlvenable
left a comment
There was a problem hiding this comment.
@Zhangxunmt , just one more comment from me.
| try { | ||
| final URI uri = dirUrl.toURI(); | ||
| if ("jar".equals(uri.getScheme())) { | ||
| try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap()); |
There was a problem hiding this comment.
I really like the overall change here to scan the classpath for these files. But the specific implementation is not ideal using newFileSystem. Instead, you can probably use reflections or spring-core.
Using reflections, it might be something like this:
new Reflections(RESOURCE_BASE).getResources(Pattern.compile(".*\\.json"))
With spring-core, you could look into PathMatchingResourcePatternResolver.
I'd probably say try using reflections. Data Prepper currently has both dependencies.
There was a problem hiding this comment.
Thanks for the call out. Updated to use the reflection lib. @dlvenable
Signed-off-by: Xun Zhang <xunzh@amazon.com>
Signed-off-by: Xun Zhang <xunzh@amazon.com>
…and add nova embedding model connector Signed-off-by: Xun Zhang <xunzh@amazon.com>
Signed-off-by: Xun Zhang <xunzh@amazon.com>
dlvenable
left a comment
There was a problem hiding this comment.
Thank you @Zhangxunmt for this great new feature!
Description
This PR integrates connectors and executors directly into the MLInferenceProcessor, eliminating the need to specify a model_id in the ml-commons plugin. Instead of configuring models externally, the processor now natively supports Amazon Bedrock-hosted models, streamlining deployment and removing manual model setup. In the future, ideally we only need to add new connector blueprints in the resources folder to enable new models.
Specifically, this update includes 3 Bedrock models out-of-the-box:
For other models, it's still required to setup model/connector in ml-commons as prerequisite to run the batch inference.
A new param "job_role_arn" is added in the processor config, which is the role passed to Bedrock/SageMaker to run the job. The role needs to have below Permissions
Issues Resolved
Resolves #[Issue number to be closed when this PR is merged]
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.