Problems generating embeddings with Bedrock (nodejs/langchain/faiss)

0

I'm updating an existing piece of code to use Amazon Bedrock, and want to simply create embeddings from a set of documents and then store them in a Faiss vector store. I plan to maybe move this to OpenSearch once I get the basic code working.

The documents are created from a text file and the embeddings object is created using:

let embeddings = new BedrockEmbeddings({
                            region: process.env.BEDROCK_REGION,
                            credentials: {
                                accessKeyId: process.env.AWS_ACCESS_KEY_ID,
                                secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
                            },
                            model: "amazon.titan-embed-text-v1"
                        });

Both docs and embeddings look fine - as I'd expect given that the code is already working with other LLMs.

However, when I try to create the vector store with

 vectorStore = await FaissStore.fromDocuments(docs, embeddings);

I get the error below, which seems to suggest that the model identifier (amazon.titan-embed-text-v1) is wrong. Am I using a deprecated model or something?

{
  error: ResourceNotFoundException: Could not resolve the foundation model from the provided model identifier.
      at de_ResourceNotFoundExceptionRes (/var/www/src/conlucra/chat/node_modules/@aws-sdk/client-bedrock-runtime/dist-cjs/protocols/Aws_restJson1.js:260:23)
      at de_InvokeModelCommandError (/var/www/src/conlucra/chat/node_modules/@aws-sdk/client-bedrock-runtime/dist-cjs/protocols/Aws_restJson1.js:92:25)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /var/www/src/conlucra/chat/node_modules/@smithy/middleware-serde/dist-cjs/deserializerMiddleware.js:7:24
      at async /var/www/src/conlucra/chat/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@aws-sdk/middleware-signing/dist-cjs/awsAuthMiddleware.js:30:20
      at async /var/www/src/conlucra/chat/node_modules/@smithy/middleware-retry/dist-cjs/retryMiddleware.js:27:46
      at async /var/www/src/conlucra/chat/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:7:26
      at async /var/www/src/conlucra/chat/node_modules/langchain/dist/embeddings/bedrock.cjs:51:29
      at async RetryOperation._fn (/var/www/src/conlucra/chat/node_modules/p-retry/index.js:50:12) {
    '$fault': 'client',
    '$metadata': {
      httpStatusCode: 404,
      requestId: 'cf74894d-8a14-4b54-bb20-ad06ba56cf79',
      extendedRequestId: undefined,
      cfId: undefined,
      attempts: 1,
      totalRetryDelay: 0
    }
  }
}
dmb0058
asked 5 months ago475 views
1 Answer
0
Accepted Answer

For future reference I found the error: I hadn’t realised that I needed to manually request access to the Amazon Foundation Models through the AWS Console. Once I did this it all worked.

dmb0058
answered 5 months ago
profile picture
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions