mem0ai/mem0 · error · ValueError

Error getting embedding from AWS Bedrock: {e}

Error message

Error getting embedding from AWS Bedrock: {e}

What it means

AWSBedrockEmbedding._get_embedding wraps the bedrock-runtime invoke_model call and response parsing in a broad `except Exception`, re-raising as ValueError with the underlying exception appended. The original cause can be an auth failure (botocore NoCredentialsError), a bad model ID (ValidationException), throttling, or a malformed response body — the suffix carries the real reason.

Source

Thrown at mem0/embeddings/aws_bedrock.py:98

        try:
            response = self.client.invoke_model(
                body=body,
                modelId=self.config.model,
                accept="application/json",
                contentType="application/json",
            )

            response_body = json.loads(response.get("body").read())

            if provider == "cohere":
                embeddings = response_body.get("embeddings")[0]
            else:
                embeddings = response_body.get("embedding")

            return embeddings
        except Exception as e:
            raise ValueError(f"Error getting embedding from AWS Bedrock: {e}")

    def embed(self, text, memory_action: Optional[Literal["add", "search", "update"]] = None):
        """
        Get the embedding for the given text using AWS Bedrock.

        Args:
            text (str): The text to embed.
            memory_action (optional): The type of embedding to use. Must be one of "add", "search", or "update". Defaults to None.
        Returns:
            list: The embedding vector.
        """
        return self._get_embedding(text)

View on GitHub (pinned to 001c235229)

Solutions

  1. Read the text after the colon — it names the underlying botocore/Bedrock error; fix that first
  2. Verify AWS credentials resolve: aws sts get-caller-identity in the same environment
  3. Confirm the model ID is available and access-enabled in the configured region (Bedrock console > Model access)
  4. For throttling, add backoff/retry around embed calls or reduce batch sizes

Example fix

# before
config = BaseEmbedderConfig(model="amazon.titan-embed-text-v1", aws_region="us-east-1")  # model access not enabled

# after
# enable model access in Bedrock console, or use an enabled model:
config = BaseEmbedderConfig(model="amazon.titan-embed-text-v2:0", aws_region="us-east-1")
Defensive patterns

Strategy: retry

Validate before calling

import subprocess
def bedrock_ready() -> bool:
    r = subprocess.run(["aws", "sts", "get-caller-identity"], capture_output=True)
    return r.returncode == 0

if not bedrock_ready():
    raise RuntimeError("AWS credentials not resolved; configure env/role first")

Try / catch

try:
    vec = embedding.embed(text)
except ValueError as e:
    msg = str(e)
    if "Throttling" in msg:
        backoff_and_retry()
    elif "credentials" in msg.lower():
        raise ConfigError("fix AWS auth") from e
    else:
        raise

Prevention

When it happens

Trigger: Calling .add()/.search() with the aws_bedrock embedder while AWS credentials are unresolved (NoCredentialsError); config.model naming a model not enabled in the region (ValidationException: could not resolve model); response.get('embedding') returning None for a provider whose payload key differs.

Common situations: Running outside an IAM role without AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY; using a cross-region model ARN with the wrong region_name; Bedrock model access not granted in the account; transient ThrottlingException under load.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/ff24d238555e63d4. Report an issue: GitHub.