{"record":{"id":"19e8a6536e5c91c4","repo":"mem0ai/mem0","slug":"error-getting-embedding-from-aws-bedrock-model-t","errorCode":null,"errorMessage":"Error getting embedding from AWS Bedrock model ${this.model}: ${message}","messagePattern":"Error getting embedding from AWS Bedrock model (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/embeddings/aws_bedrock.ts","lineNumber":233,"sourceCode":"  ): Promise<number[][]> {\n    const { sdk, client } = await this.getClient();\n\n    let payload: BedrockEmbeddingResponse;\n    try {\n      const response = await client.send(\n        new sdk.InvokeModelCommand({\n          modelId: this.model,\n          contentType: \"application/json\",\n          accept: \"application/json\",\n          body: new TextEncoder().encode(\n            JSON.stringify(this.buildRequestBody(texts, memoryAction)),\n          ),\n        }),\n      );\n      payload = JSON.parse(new TextDecoder().decode(response.body));\n    } catch (error) {\n      const message = error instanceof Error ? error.message : String(error);\n      throw new Error(\n        `Error getting embedding from AWS Bedrock model ${this.model}: ${message}`,\n      );\n    }\n\n    // Validated outside the try so this message is not re-wrapped by the catch.\n    // Cohere v3 replies with a flat `embeddings` array; v4 (when\n    // embedding_types is requested) nests it under `.float`.\n    const embeddings = this.isCohereModel()\n      ? Array.isArray(payload.embeddings)\n        ? payload.embeddings\n        : payload.embeddings?.float\n      : payload.embedding && [payload.embedding];\n\n    // `[]` is truthy, so a lone zero-length vector must be checked for\n    // explicitly -- otherwise it passes the length check and hands the\n    // caller an empty embedding instead of an error.\n    if (\n      !embeddings ||","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/embeddings/aws_bedrock.ts#L215-L251","documentation":"Thrown by the AWS Bedrock embedder when the bedrock-runtime SendCommand/InvokeModel call fails or the response body cannot be parsed. The underlying error message is appended (e.g. AccessDeniedException, throttling, model-not-enabled, invalid manifest, DNS failure), so the suffix identifies the root cause. This wraps every failure in the invoke() path — request construction, transport, and JSON decode.","triggerScenarios":"Model not enabled/subscribed in the region (ValidationException: model with ID ... is not accessible); missing bedrock:InvokeModel IAM permission (AccessDeniedException); throttling (TooManyRequestsException/ServiceUnavailable); wrong region in config; cross-region endpoint mismatch; malformed input for the model family.","commonSituations":"IAM role lacks bedrock:InvokeModel for the model ARN; Bedrock model access not yet granted in the console (requires requesting access per model); region set to one where the model is unavailable; throttling under burst load with no backoff.","solutions":["Read the appended original message — it names the AWS exception and points at the fix","Grant bedrock:InvokeModel on the model ARN and request model access in the Bedrock console for the configured region","Verify region/model pairing (e.g. cohere.embed-english-v3 availability) and that config.model matches an inference profile ID if your account requires profile ARNs","Add exponential backoff for throttling exceptions before retrying the add/search operation"],"exampleFix":"// before\nembedder: { provider: 'aws_bedrock', config: { model: 'cohere.embed-english-v3', region: 'us-east-1' } }\n// -> 'Error getting embedding from AWS Bedrock model cohere.embed-english-v3: User is not authorized...'\n\n// after\n// 1. IAM: allow bedrock:InvokeModel on arn:aws:bedrock:us-east-1::foundation-model/cohere.embed-english-v3\n// 2. Bedrock console: Model access -> request access for Cohere Embed\nembedder: { provider: 'aws_bedrock', config: { model: 'cohere.embed-english-v3', region: 'us-east-1' } }","handlingStrategy":"retry","validationCode":"// Pre-flight: cheap invoke before wiring memory into your app\nconst embedder = new AwsBedrockEmbedder(config);\nawait embedder.embed('ping'); // surfaces IAM/model-access errors at startup, not mid-request","typeGuard":null,"tryCatchPattern":"const isTransientBedrockError = (e: unknown) => {\n  const m = e instanceof Error ? e.message : String(e);\n  return /TooManyRequests|Throttling|ServiceUnavailable|timeout/i.test(m);\n};\ntry {\n  await embedder.embed(text);\n} catch (e) {\n  if (isTransientBedrockError(e)) await backoffRetry(() => embedder.embed(text));\n  else throw e; // AccessDenied / model-not-enabled need config or IAM changes, not retries\n}","preventionTips":["Warm up with a single embed() call at startup so IAM/model-access problems fail the deploy, not user traffic","Grant least-privilege bedrock:InvokeModel on the exact model ARN and request model access in-console before first use","Classify exceptions: throttle -> retry with backoff; access -> fix IAM; validation -> fix model ID/region"],"tags":["aws","bedrock","embeddings","network","iam","runtime"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}