Add support for configurable embedding model
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
@Dev-Khant Kindly request you to review the PR when you have a moment :)
Hey @kmitul, Thanks for working on this PR, I'll review it soon because first we need to fix CI flow.
@kmitul Can you please rebase your branch with main?
@Dev-Khant Done. For #1581 as well.
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.
Hey @Dev-Khant
I've added test script in description.
@kmitul What all providers are supported? Huggingface, Azure, OpenAI, Ollama and ?
Update : nvm got my answer (Huggingface, Azure, OpenAI, Ollama) are supported currently
Hey @Dev-Khant
Does it look good to you? Were you able to test em out?
Hey @kmitul, Please give me some time I'll test it out and let you know.
@kmitul Thanks for the contribution, this looks good.