mem0 icon indicating copy to clipboard operation
mem0 copied to clipboard

Add support for configurable embedding model

Open kmitul opened this issue 1 year ago • 9 comments

Description

Added a feature that allows users to specify the embedding model of their choice through embedder config.

Fixes #1626, #1593, #1590, #1544

Type of change

Please delete options that are not relevant.

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Please delete options that are not relevant.

  • [x] Unit Test
  • [x] Test Script

For Azure OpenAI Embedder

from mem0 import Memory

os.environ["AZURE_OPENAI_API_KEY"] = "your-api-key"
os.environ["AZURE_OPENAI_ENDPOINT"] = "your-api-base-url"
os.environ["OPENAI_API_VERSION"] = "version-to-use"

config = {
    "llm": {
        "provider": "azure_openai",
        "config": {
            "model": "gpt-4o", # or your custom deployment name
            "temperature": 0.2,
            "max_tokens": 1500,
        }
    },
    "embedder": {
        "provider": "azure_openai",
        "config": {
            "model": "text-embedding-3-small", # or your custom deployment name
        }
    }
}

m = Memory.from_config(config)

m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})

For Huggingface Embedder

from mem0 import Memory

config = {
    "llm": {
        "provider": "openai",
        "config": {
            "model": "gpt-4o",
            "temperature": 0.2,
            "max_tokens": 1500,
        }
    },
    "embedder": {
        "provider": "huggingface",
        "config": {
            "model": "multi-qa-MiniLM-L6-cos-v1",
            "model_kwargs": {
                "device": "cuda"
            },
            "embedding_dims": 384
        }
    },
    "vector_store": {
        "provider": "qdrant",
        "config":{
            "embedding_model_dims": 384,
        }
    }
}

m = Memory.from_config(config)

m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})

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
  • [x] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [x] 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
  • [x] 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

kmitul avatar Aug 01 '24 05:08 kmitul

@Dev-Khant Kindly request you to review the PR when you have a moment :)

kmitul avatar Aug 01 '24 06:08 kmitul

Hey @kmitul, Thanks for working on this PR, I'll review it soon because first we need to fix CI flow.

Dev-Khant avatar Aug 01 '24 08:08 Dev-Khant

@kmitul Can you please rebase your branch with main?

Dev-Khant avatar Aug 01 '24 16:08 Dev-Khant

@Dev-Khant Done. For #1581 as well.

kmitul avatar Aug 02 '24 00:08 kmitul

Hey @kmitul Can you please add a script in description to test Azure and Huggingface embedded, want to test it locally as we currently don't have pytests for embeddings.

Dev-Khant avatar Aug 04 '24 07:08 Dev-Khant

Hey @Dev-Khant
I've added test script in description.

kmitul avatar Aug 05 '24 01:08 kmitul

@kmitul What all providers are supported? Huggingface, Azure, OpenAI, Ollama and ?

Update : nvm got my answer (Huggingface, Azure, OpenAI, Ollama) are supported currently

criminact avatar Aug 07 '24 08:08 criminact

Hey @Dev-Khant
Does it look good to you? Were you able to test em out?

kmitul avatar Aug 08 '24 04:08 kmitul

Hey @kmitul, Please give me some time I'll test it out and let you know.

Dev-Khant avatar Aug 09 '24 05:08 Dev-Khant

@kmitul Thanks for the contribution, this looks good.

Dev-Khant avatar Aug 12 '24 09:08 Dev-Khant