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

Add dimensions parameter support for bedrock titan embedding v2 model #3136

Conversation

zane-neo
Copy link
Collaborator

Description

  1. Optimized the Function usage by adding a new interface PreProcessFunction as there isn't cases that the Function accepts different type of parameters. Currently it only accepts MLInput and Map<String, String>
  2. Add support for dimensions parameter introduced in titan embedding v2 model.

Related Issues

#3093

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

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.

@zane-neo zane-neo force-pushed the support-embedding-dimension-bedrock branch from 2d4c496 to ab2d736 Compare November 29, 2024 02:18
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env December 3, 2024 06:24 — with GitHub Actions Failure
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env December 3, 2024 06:24 — with GitHub Actions Failure
Signed-off-by: zane-neo <[email protected]>
@zane-neo zane-neo temporarily deployed to ml-commons-cicd-env December 3, 2024 12:24 — with GitHub Actions Inactive
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env December 3, 2024 12:24 — with GitHub Actions Failure
import org.opensearch.ml.common.dataset.TextDocsInputDataSet;
import org.opensearch.ml.common.dataset.remote.RemoteInferenceInputDataSet;
import org.opensearch.ml.common.input.MLInput;

import lombok.extern.slf4j.Slf4j;

@Slf4j
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we add @log4j instead to keep the consistency?

TextDocsInputDataSet inputData = (TextDocsInputDataSet) mlInput.getInputDataset();
// Amazon Titan Text Embeddings V2 model: https://docs.aws.amazon.com/bedrock/latest/userguide/titan-embedding-models.html
// Default dimension is 1024
int dimensions = Optional.ofNullable(connectorParams.get("dimensions")).map(x -> NumberUtils.toInt(x, 1024)).orElse(1024);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is BedrockEmbeddingPreProcessFunction only for titan models? What about other bedrock models?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also notice we have multimodal embedding model: https://docs.aws.amazon.com/bedrock/latest/userguide/titan-multiemb-models.html. Is the multimodal model using MultiModalConnectorPreProcessFunction, if so, can we also add dimension for this?

Copy link
Collaborator Author

@zane-neo zane-neo Dec 5, 2024

Choose a reason for hiding this comment

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

Is BedrockEmbeddingPreProcessFunction only for titan models? What about other bedrock models?

Currently this is a titan specific process function, but if in the future bedrock has another similar(similar means they have same request body, e.g. inputText & dimensions etc) text embedding model, then this can be reused to that one.
BedRock integrated with multiple models like anthropic, cohere, meta etc, currently we only have titan, cohere pre process functions in our code, from cohere API: https://docs.cohere.com/reference/embed I didn't see they support dimension parameter so it's fine.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In that case do we need to set the default dimension? If dimension is provided then we will add otherwise not?

@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env December 5, 2024 02:19 — with GitHub Actions Failure
Map inferenceResult = predictTextEmbeddingModelIgnoreFunctionName(modelId, mlInput);
String errorMsg = String
.format(Locale.ROOT, "Failing test case name: %s, inference result: %s", testCaseName, gson.toJson(inferenceResult));
assertTrue(errorMsg, inferenceResult.containsKey("inference_results"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why it is showing error here?

@zane-neo
Copy link
Collaborator Author

zane-neo commented Dec 9, 2024

After adding more details of the issue, this PR is not necessary and please check the new PR: #3262

@zane-neo zane-neo closed this Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants