Repository: mem0ai/mem0
Pull request #2389 (2025-03-17 19:14:57)

Add infer param and version bump
## Description

Add an `infer` parameter to the `Add` method to store messages as they are in memory.. Also bumped up the version.


## Type of change

- [x] New feature (non-breaking change which adds functionality)
- [x] Documentation update

vercel[bot]: [vc]: #sMY+F1Lg+xkGkgGWr+OuWO/sCf6YzUkeaprzQeL6zTU=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJtdWx0aW1vZGFsLWRlbW8iLCJyb290RGlyZWN0b3J5IjoiZXhhbXBsZXMvbXVsdGltb2RhbC1kZW1vIiwiaW5zcGVjdG9yVXJsIjoiaHR0cHM6Ly92ZXJjZWwuY29tL21lbTAvbXVsdGltb2RhbC1kZW1vL0RGRlBXeWpadFZYSkhtbkxvYTlmRzhINnNNZXQiLCJwcmV2aWV3VXJsIjoibXVsdGltb2RhbC1kZW1vLWdpdC11c2VyLWRldmluZmVyLXBhcmFtLW1lbTAudmVyY2VsLmFwcCIsIm5leHRDb21taXRTdGF0dXMiOiJQRU5ESU5HIiwibGl2ZUZlZWRiYWNrIjp7InJlc29sdmVkIjowLCJ1bnJlc29sdmVkIjowLCJ0b3RhbCI6MCwibGluayI6Im11bHRpbW9kYWwtZGVtby1naXQtdXNlci1kZXZpbmZlci1wYXJhbS1tZW0wLnZlcmNlbC5hcHAifX1dfQ==
**The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)

| Name | Status | Preview | Comments | Updated (UTC) |
| :--- | :----- | :------ | :------- | :------ |
| **multimodal-demo** | 🔄 Building ([Inspect](https://vercel.com/mem0/multimodal-demo/DFFPWyjZtVXJHmnLoa9fG8H6sMet)) | [Visit Preview](https://multimodal-demo-git-user-devinfer-param-mem0.vercel.app) | 💬 [**Add feedback**](https://vercel.live/open-feedback/multimodal-demo-git-user-devinfer-param-mem0.vercel.app?via=pr-comment-feedback-link) | Mar 17, 2025 7:25pm |



Patch:
diff --git a/docs/open-source/python-quickstart.mdx b/docs/open-source/python-quickstart.mdx
index eec2b6c0..93db6def 100644
--- a/docs/open-source/python-quickstart.mdx
+++ b/docs/open-source/python-quickstart.mdx
@@ -85,14 +85,18 @@ m = Memory.from_config(config_dict=config)
 
 <CodeGroup>
 ```python Code
-const messages = [
+messages = [
     {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"},
     {"role": "assistant", "content": "How about a thriller movies? They can be quite engaging."},
     {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."},
     {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."}
 ]
 
+# Store inferred memories (default behavior)
 result = m.add(messages, user_id="alice", metadata={"category": "movie_recommendations"})
+
+# Store raw messages without inference
+# result = m.add(messages, user_id="alice", metadata={"category": "movie_recommendations"}, infer=False)
 ```
 
 ```json Output
diff --git a/mem0/memory/main.py b/mem0/memory/main.py
index e62d76a6..f95fe1f7 100644
--- a/mem0/memory/main.py
+++ b/mem0/memory/main.py
@@ -16,8 +16,12 @@ from mem0.memory.base import MemoryBase
 from mem0.memory.setup import setup_config
 from mem0.memory.storage import SQLiteManager
 from mem0.memory.telemetry import capture_event
-from mem0.memory.utils import (get_fact_retrieval_messages, parse_messages,
-                               parse_vision_messages, remove_code_blocks)
+from mem0.memory.utils import (
+    get_fact_retrieval_messages,
+    parse_messages,
+    parse_vision_messages,
+    remove_code_blocks,
+)
 from mem0.utils.factory import EmbedderFactory, LlmFactory, VectorStoreFactory
 
 # Setup user config
@@ -82,6 +86,7 @@ class Memory(MemoryBase):
         run_id=None,
         metadata=None,
         filters=None,
+        infer=True,
         prompt=None,
     ):
         """
@@ -94,6 +99,7 @@ class Memory(MemoryBase):
             run_id (str, optional): ID of the run creating the memory. Defaults to None.
             metadata (dict, optional): Metadata to store with the memory. Defaults to None.
             filters (dict, optional): Filters to apply to the search. Defaults to None.
+            infer (bool, optional): Whether to infer the memories. Defaults to True.
             prompt (str, optional): Prompt to use for memory deduction. Defaults to None.
 
         Returns:
@@ -132,7 +138,7 @@ class Memory(MemoryBase):
             messages = parse_vision_messages(messages)
 
         with concurrent.futures.ThreadPoolExecutor() as executor:
-            future1 = executor.submit(self._add_to_vector_store, messages, metadata, filters)
+            future1 = executor.submit(self._add_to_vector_store, messages, metadata, filters, infer)
             future2 = executor.submit(self._add_to_graph, messages, filters)
 
             concurrent.futures.wait([future1, future2])
@@ -158,7 +164,16 @@ class Memory(MemoryBase):
 
         return {"results": vector_store_result}
 
-    def _add_to_vector_store(self, messages, metadata, filters):
+    def _add_to_vector_store(self, messages, metadata, filters, infer):
+        if not infer:
+            returned_memories = []
+            for message in messages:
+                if message["role"] != "system":
+                    message_embeddings = self.embedding_model.embed(message["content"], "add")
+                    memory_id = self._create_memory(message["content"], message_embeddings, metadata)
+                    returned_memories.append({"id": memory_id, "memory": message["content"], "event": "ADD"})
+            return returned_memories
+
         parsed_messages = parse_messages(messages)
 
         if self.custom_prompt:
diff --git a/pyproject.toml b/pyproject.toml
index fd86f03a..a06a2c69 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "mem0ai"
-version = "0.1.68"
+version = "0.1.69"
 description = "Long-term memory for AI Agents"
 authors = ["Mem0 <founders@mem0.ai>"]
 exclude = [


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
index b1375310..b9021381 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -51,7 +51,7 @@ def test_add(memory_instance, version, enable_graph):
         assert result["results"] == [{"memory": "Test memory", "event": "ADD"}]
 
     memory_instance._add_to_vector_store.assert_called_once_with(
-        [{"role": "user", "content": "Test message"}], {"user_id": "test_user"}, {"user_id": "test_user"}
+        [{"role": "user", "content": "Test message"}], {"user_id": "test_user"}, {"user_id": "test_user"}, True
     )
 
     # Remove the conditional assertion for _add_to_graph