Skip to content

Commit

Permalink
user_id finalization
Browse files Browse the repository at this point in the history
  • Loading branch information
spike-spiegel-21 committed Dec 31, 2024
1 parent b898906 commit d5ad209
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/open-source/graph_memory/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ The Mem0's graph supports the following operations:

### Add Memories

<Note>
If you are using Mem0 with Graph Memory, it is recommended to pass `user_id`. The default value of `user_id` (in case of graph memory) is `user`.
</Note>

<CodeGroup>
```python Code
m.add("I like pizza", user_id="alice")
Expand Down
11 changes: 4 additions & 7 deletions mem0/memory/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,11 @@ def _add_to_vector_store(self, messages, metadata, filters):
def _add_to_graph(self, messages, filters):
added_entities = []
if self.api_version == "v1.1" and self.enable_graph:
if filters["user_id"]:
self.graph.user_id = filters["user_id"]
elif filters["agent_id"]:
self.graph.agent_id = filters["agent_id"]
elif filters["run_id"]:
self.graph.run_id = filters["run_id"]
if filters.get("user_id"):
filters["user_id"] = filters["user_id"]
else:
self.graph.user_id = "USER"
filters["user_id"] = "user"

data = "\n".join([msg["content"] for msg in messages if "content" in msg and msg["role"] != "system"])
added_entities = self.graph.add(data, filters)

Expand Down

0 comments on commit d5ad209

Please sign in to comment.