mem0 icon indicating copy to clipboard operation
mem0 copied to clipboard

fix: appropriately handle overriding for aws LLM and embedding configurations

Open david-dest01 opened this issue 7 months ago • 2 comments

Description

I noticed the logic for aws bedrock is causing the configurations to not be respected.

AWSBedrockLLM will check if the attribute exists, which it does, and it will set the value from the environment variables to None. Same goes for AWSBedrockEmbedding.

Additionally the default to us-west-2 so the base configs (BaseEmbedderConfig, BaseLlmConfig) will default to us-west-2, so environment settings don't seem to be respected.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] Refactor (does not change functionality, e.g. code style improvements, linting)
  • [ ] Documentation update

How Has This Been Tested?

Tested locally using the following configuration. Testing with the PR updates seems to work. Testing without causes some issues - you can trace the logs of what values end up looking like to see the overriding.

import os

from mem0 import Memory
from mem0.configs.base import MemoryConfig
from mem0.llms.configs import LlmConfig
from mem0.embeddings.configs import EmbedderConfig

# os.environ['AWS_REGION'] = 'us-east-1'
# os.environ["AWS_ACCESS_KEY_ID"] = ""
# os.environ["AWS_SECRET_ACCESS_KEY"] = ""

llm_config = LlmConfig(
    provider="aws_bedrock",
    config={
        "model": "arn:aws:bedrock:us-east-1:{your-account-id}:inference-profile/us.anthropic.claude-3-5-sonnet-20241022-v2:0",
        "temperature": 0.2,
        "max_tokens": 2000,
    }
)

embedder_config = EmbedderConfig(
    provider="aws_bedrock",
    config={
        "model": "amazon.titan-embed-text-v1",
    }
)

mem_config = MemoryConfig(
    llm=llm_config,
    embedder=embedder_config
)

m = Memory(mem_config)

Please delete options that are not relevant.

  • [ ] Unit Test
  • [x] Test Script (please provide)

See above.

Checklist:

  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [x] New and existing unit tests pass locally with my changes
  • [ ] Any dependent changes have been merged and published in downstream modules
  • [x] I have checked my code and corrected any misspellings

Maintainer Checklist

  • [ ] closes #xxxx (Replace xxxx with the GitHub issue number)
  • [ ] Made sure Checks passed

david-dest01 avatar May 26 '25 16:05 david-dest01

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar May 26 '25 16:05 CLAassistant

If you explicitly set the aws_region to None in your config, then the current behavior should pick it up from the AWS_REGION environmental variable and then this code change is unneeded to get the desired behavior.

johnwlockwood avatar May 28 '25 01:05 johnwlockwood

If you explicitly set the aws_region to None in your config, then the current behavior should pick it up from the AWS_REGION environmental variable and then this code change is unneeded to get the desired behavior.

Ah that's correct - thanks @johnwlockwood. Can close this out.

david-dest01 avatar May 28 '25 11:05 david-dest01