Mem0mem0ai 2.0.20 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
24 small wins to finish your pathNext lesson

Memory.from_config: all three pieces

Two stand-ins exist and neither is plugged in. The configuration is one dictionary with one entry per piece, and one detail in it is not obvious.

The detail

Mem0 picks a provider by name from a fixed list. You cannot add "pretend" to that list from outside: the validator raises Unsupported embedding provider. The supported way to pass your own object is the langchain provider, which takes an instance instead of a name.

python
"llm": {"provider": "langchain", "config": {"model": PretendModel()}},
"embedder": {"provider": "langchain", "config": {"model": PretendEmbedder()}},

That is why lesson 3 installed the langchain packages. They are not Mem0's dependency; they are the door your own code comes through.

The store

python
"vector_store": {"provider": "qdrant", "config": {
    "path": tempfile.mkdtemp(prefix="mem0-"),
    "embedding_model_dims": 64,
    "on_disk": False,
}},

Qdrant runs inside the process, so there is no server and no Docker. path is where it keeps its files and embedding_model_dims has to match the embedder from lesson 6. A fresh temporary directory each time means every lesson in this course starts empty, which is what makes their output the same every run.

The helper

Put together, that is a dictionary long enough to be worth writing once. This goes at the bottom of the same file as the two stand-ins.

python
def memory(**extra):
    """A Mem0 memory that uses the stand-ins and a fresh directory each time."""
    from mem0 import Memory

    config = {
        "llm": {"provider": "langchain", "config": {"model": PretendModel()}},
        "embedder": {"provider": "langchain", "config": {"model": PretendEmbedder()}},
        "vector_store": {"provider": "qdrant", "config": {
            "path": tempfile.mkdtemp(prefix="mem0-"),
            "embedding_model_dims": 64,
            "on_disk": False,
        }},
    }
python
    config.update(extra)
    return Memory.from_config(config)

extra lets a later lesson override one piece without repeating the rest, which lessons 17 and 18 both use.

All of it running

Example
from pretend_mem0 import memory

shop = memory()
result = shop.add("I prefer email updates, not SMS. Deliver to my office.",
                  user_id="ravi")
for stored in result["results"]:
    print(stored["event"], "|", stored["memory"])

Two memories out of one sentence, with no key and no network. Everything from here is what you can do with them.

Keep this file. The whole course imports it. Every later lesson starts with from pretend_mem0 import memory, and lesson 19 changes two lines inside it to point at a real model, leaving every other lesson untouched.
Try it yourself
  • Call memory() twice and confirm the second one is empty, because each gets its own directory.
  • Set embedding_model_dims to 1536 and read the error you get.
  • Change the provider name from langchain to pretend and read that error too.

You understood something today that you didn't yesterday.