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.
"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
"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.
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,
}},
} 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
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.
from pretend_mem0 import memory, and lesson 19 changes two lines inside it to point at a real model, leaving every other lesson untouched.- Call
memory()twice and confirm the second one is empty, because each gets its own directory. - Set
embedding_model_dimsto 1536 and read the error you get. - Change the provider name from
langchaintopretendand read that error too.
You understood something today that you didn't yesterday.