Problem/Motivation

When setting up AI Search, when you configure the AWS Bedrock embedding model, you get an error:

Could not load the embeddings engine to get the dimensions. Please check the configuration.Error executing "InvokeModel" on "https://bedrock-runtime.us-east-1.amazonaws.com/model/amazon.titan-embed-text-v2%3A0/invoke"; AWS HTTP error: Client error: `POST https://bedrock-runtime.us-east-1.amazonaws.com/model/amazon.titan-embed-text-v2%3A0/invoke` resulted in a `400 Bad Request` response: {"message":"Malformed input request: #: only 1 subschema matches out of 2, please reformat your input and try again."} ValidationException (client): Malformed input request: #: only 1 subschema matches out of 2, please reformat your input and try again. - {"message":"Malformed input request: #: only 1 subschema matches out of 2, please reformat your input and try again."}

Titan Text Embeddings V2 is now the only option on AWS Bedrock.

Steps to reproduce

When I try to create a server using AWS Bedrock and Milvus I get the above error. I'm trying to use the Titan Text Embeddings V2 (amazon.titan-embed-text-v2.0) model.

Proposed resolution

Is this really happening because the formatInput method in TitanEmbeddings.php lists amazon.titan-embed-text-v1 in it?

If I change it to v2 the error goes away and I can index things into Milvus.

public static function formatInput($input = "", $image = NULL, $config = [], $model_id = '') {
    if ($input) {
      $payload['inputText'] = $input;
    }
    elseif ($image && strpos($model_id, 'amazon.titan-embed-image') === 0) {
      $payload['inputImage'] = $image->getAsBase64EncodedString('');
    }
    else {
      throw new AiBadRequestException('You need to give an input text or an image or you used as image in a none-image embeddings model.');
    }
    if (strpos($model_id, 'amazon.titan-embed-image') === 0) {
      $payload['embeddingConfig']['outputEmbeddingLength'] = (int) $config['outputEmbeddingLength'];
    }
    elseif (strpos($model_id, 'amazon.titan-embed-text-v2') !== 0) {
      $payload['dimensions'] = (int) $config['dimensions'];
    }
    return $payload;
  }
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

keiserjb created an issue. See original summary.

danielveza’s picture

I've just run into this as well, it would be good to get this committed if we no longer need to support v1. Otherwise we might need to alter the if statements to check both v1 and v2.

I wonder if we can turn these into plugins or do something a little nicer than elseifs checking strings. But I think thats something to think about later.

kim.pepper’s picture

Title: Could not load the embeddings engine to get the dimensions. Please check the configuration.Error executing "InvokeModel" on "https://bedrock-runtime.us-east-1.amazonaws.com/model/amazon.titan-embed-text-v2%3A0/invoke"; » Cannot load embeddings due to hard-coded Titan V1 model
Priority: Normal » Critical
Issue summary: View changes

I think this is critical as the Titan V1 embedding model doesn't work at all.

kim.pepper’s picture

Issue summary: View changes

marcus_johansson made their first commit to this issue’s fork.

marcus_johansson’s picture

Status: Active » Needs review
Issue tags: +Needs backport to 1.0.x

Its a general problem with AWS that each model works differently, so we have to map the configuration into their own class. There is no record of them deprecating the old model, but I could replicate the issue that its not listed as a on-demand model anymore at least.

I did a small fix to the code from @danielveza, thank you. As soon as that is approved I will push a new version of both 1.0.x and 1.1.x versions.

As a note - in general we are looking for maintainers for any provider module, so if you are using it and want to be a maintainer let us know.

marcus_johansson’s picture

kim.pepper’s picture

Thanks @marcus_johansson. Can't speak for @danielveza but I will put my hand up for maintainership.

kim.pepper’s picture

I like @danielveza 's idea of

I wonder if we can turn these into plugins or do something a little nicer than elseifs checking strings.

kim.pepper’s picture

Re #10 this was done in #3546084: Convert models to plugins, remove hardcoded model string checks and merged to 1.x.

I have rebased this MR on 1.x

keiserjb’s picture

Glad to see the activity here with the Bedrock provider. I went back to primarily using OpenAI but may return. Thanks to @kimpepper and @danielveza for stepping up.