Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

Doc: update for enable_graph and Version bump -> 0.1.103 (#2893)

Dev Khantbb14cc42a06b
diff --git a/docs/platform/features/graph-memory.mdx b/docs/platform/features/graph-memory.mdx
index 458a86897..d4080a6fc 100644
--- a/docs/platform/features/graph-memory.mdx
+++ b/docs/platform/features/graph-memory.mdx
@@ -281,6 +281,67 @@ console.log(memories);
</CodeGroup>
+### Setting Graph Memory at Project Level
+
+Instead of passing `enable_graph=True` to every add call, you can enable it once at the project level:
+
+<CodeGroup>
+
+```python Python
+from mem0 import MemoryClient
+
+client = MemoryClient(
+ api_key="your-api-key",
+ org_id="your-org-id",
+ project_id="your-project-id"
+)
+
+# Enable graph memory for all operations in this project
+client.update_project(enable_graph=True, version="v1")
+
+# Now all add operations will use graph memory by default
+messages = [
+ {"role": "user", "content": "My name is Joseph"},
+ {"role": "assistant", "content": "Hello Joseph, it's nice to meet you!"},
+ {"role": "user", "content": "I'm from Seattle and I work as a software engineer"}
+]
+
+client.add(
+ messages,
+ user_id="joseph",
+ output_format="v1.1"
+)
+```
+
+```javascript JavaScript
+import { MemoryClient } from "mem0";
+
+const client = new MemoryClient({
+ apiKey: "your-api-key",
+ org_id: "your-org-id",
+ project_id: "your-project-id"
+});
+
+# Enable graph memory for all operations in this project
+await client.updateProject({ enable_graph: true, version: "v1" });
+
+# Now all add operations will use graph memory by default
+const messages = [
+ { role: "user", content: "My name is Joseph" },
+ { role: "assistant", content: "Hello Joseph, it's nice to meet you!" },
+ { role: "user", content: "I'm from Seattle and I work as a software engineer" }
+];
+
+await client.add({
+ messages,
+ user_id: "joseph",
+ output_format: "v1.1"
+});
+```
+
+</CodeGroup>
+
+
## Best Practices
- Enable Graph Memory for applications where understanding context and relationships between memories is important
diff --git a/mem0/client/main.py b/mem0/client/main.py
index ae6dd5d6b..ce946e86c 100644
--- a/mem0/client/main.py
+++ b/mem0/client/main.py
@@ -504,12 +504,17 @@ class MemoryClient:
custom_instructions: Optional[str] = None,
custom_categories: Optional[List[str]] = None,
retrieval_criteria: Optional[List[Dict[str, Any]]] = None,
+ enable_graph: Optional[bool] = None,
+ version: Optional[str] = None,
) -> Dict[str, Any]:
"""Update the project settings.
Args:
custom_instructions: New instructions for the project
custom_categories: New categories for the project
+ retrieval_criteria: New retrieval criteria for the project
+ enable_graph: Enable or disable the graph for the project
+ version: Version of the project
Returns:
Dictionary containing the API response.
@@ -521,7 +526,7 @@ class MemoryClient:
if not (self.org_id and self.project_id):
raise ValueError("org_id and project_id must be set to update instructions or categories")
- if custom_instructions is None and custom_categories is None and retrieval_criteria is None:
+ if custom_instructions is None and custom_categories is None and retrieval_criteria is None and enable_graph is None and version is None:
raise ValueError(
"Currently we only support updating custom_instructions or custom_categories or retrieval_criteria, so you must provide at least one of them"
)
@@ -531,6 +536,8 @@ class MemoryClient:
"custom_instructions": custom_instructions,
"custom_categories": custom_categories,
"retrieval_criteria": retrieval_criteria,
+ "enable_graph": enable_graph,
+ "version": version,
}
)
response = self.client.patch(
@@ -545,6 +552,8 @@ class MemoryClient:
"custom_instructions": custom_instructions,
"custom_categories": custom_categories,
"retrieval_criteria": retrieval_criteria,
+ "enable_graph": enable_graph,
+ "version": version,
"sync_type": "sync",
},
)
@@ -1100,11 +1109,13 @@ class AsyncMemoryClient:
custom_instructions: Optional[str] = None,
custom_categories: Optional[List[str]] = None,
retrieval_criteria: Optional[List[Dict[str, Any]]] = None,
+ enable_graph: Optional[bool] = None,
+ version: Optional[str] = None,
) -> Dict[str, Any]:
if not (self.org_id and self.project_id):
raise ValueError("org_id and project_id must be set to update instructions or categories")
- if custom_instructions is None and custom_categories is None and retrieval_criteria is None:
+ if custom_instructions is None and custom_categories is None and retrieval_criteria is None and enable_graph is None and version is None:
raise ValueError(
"Currently we only support updating custom_instructions or custom_categories or retrieval_criteria, so you must provide at least one of them"
)
@@ -1114,6 +1125,8 @@ class AsyncMemoryClient:
"custom_instructions": custom_instructions,
"custom_categories": custom_categories,
"retrieval_criteria": retrieval_criteria,
+ "enable_graph": enable_graph,
+ "version": version,
}
)
response = await self.async_client.patch(
@@ -1128,6 +1141,8 @@ class AsyncMemoryClient:
"custom_instructions": custom_instructions,
"custom_categories": custom_categories,
"retrieval_criteria": retrieval_criteria,
+ "enable_graph": enable_graph,
+ "version": version,
"sync_type": "async",
},
)