mem0ai / mem0

The Memory layer for your AI apps
https://mem0.ai
Apache License 2.0
21.6k stars 1.97k forks source link

Unable to configure custom embedding dimension for ChromaDB backend, resulted into embedding size mismatch #1700

Closed James4Ever0 closed 4 weeks ago

James4Ever0 commented 4 weeks ago

🐛 Describe the bug

According to the documentation, all other vector db backends have a parameter called embedding_model_dims while ChromaDB has not. It is hardcoded into 1536 and results into the following issue.

Code:

import os

os.environ['OPENAI_API_KEY'] = 'dummykey'

from mem0 import Memory

config = {
    "embedder": {
        "provider": "ollama",
        "config": {
            "model": "mxbai-embed-large",
        }
    },
    "llm": {
        "provider": "ollama",
        "config": {
            "model": "mistral:v0.3",
            "temperature": 0.5,
            "max_tokens": 2000,
        }
    },
    "vector_store": {
        "provider": "chroma",
        "config": {
            "collection_name": "test",
            "path": "test_db",
        }
    }
}

m = Memory.from_config(config)

uploaded_memory = m.add("I am working on improving my tennis skills. Suggest some online courses.", user_id="alice", metadata={"category": "hobbies"}) # {"message": "ok"}

m.get_all() # exception here

Exception:

*** chromadb.errors.InvalidDimensionException: Embedding dimension 1536 does not match collection dimensionality 1024
Dev-Khant commented 4 weeks ago

Hey @James4Ever0 Thank you for pointing out this issue. I have made the fix, so feel free to install the latest version for the package and see if works.

Let me know once you have tested or if you still face any issues.

James4Ever0 commented 4 weeks ago

Upgraded to version 0.0.19 and the issue has been fixed. Thank you.