-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[docs]: graph memory platform #2144
Open
spike-spiegel-21
wants to merge
7
commits into
main
Choose a base branch
from
graph_platform_docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
52bd1a4
docs added
spike-spiegel-21 d5481f3
docs changed for graph
spike-spiegel-21 2871e87
Update docs/features/graph-memory.mdx
spike-spiegel-21 beeffc8
Update docs/features/graph-memory.mdx
spike-spiegel-21 83e691c
Update docs/features/graph-memory.mdx
spike-spiegel-21 7a49124
Update docs/features/graph-memory.mdx
spike-spiegel-21 2743551
Update docs/features/graph-memory.mdx
spike-spiegel-21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
--- | ||
title: Graph Memory | ||
description: 'Knowledge Graph of your memories' | ||
--- | ||
|
||
|
||
Mem0 uses a graph database to store memories in a knowledge graph. This allows for more complex queries and relationships between memories. | ||
|
||
## Add | ||
|
||
To create an knowledge graph of your memories, you can use the `enable_graph` param in the `add()` method. | ||
|
||
```python | ||
from mem0 import MemoryClient | ||
|
||
m = MemoryClient(api_key="your_api_key") | ||
|
||
m.add( | ||
messages=[ | ||
{"role": "user", "content": "I like to eat pizza"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make the example better. |
||
], | ||
user_id="sam", | ||
agent_id="agent_1", | ||
enable_graph=True, | ||
) | ||
``` | ||
This will create a knowledge graph of the memories and store it in the graph database. | ||
|
||
|
||
## Search | ||
|
||
Use the `search()` method with the `enable_graph` params to get the knowledge graph of the memories. | ||
|
||
```python | ||
result = m.search( | ||
query="preferences of sam", | ||
user_id="sam", | ||
agent_id="agent_1", | ||
enable_graph=True, | ||
output_format="v1.1" | ||
) | ||
print(result) | ||
``` | ||
|
||
<Note type="info"> | ||
The `output_format` parameter is mandatory to get the graph results. If not provided, the graph search will not work. | ||
</Note> | ||
|
||
This will return the nodes and relationships that are related to the query "preferences of sam". | ||
|
||
<CodeGroup> | ||
```json Output | ||
{ | ||
'results': [{'id': '438fb702-b839-4ffc-9fb4-2bead4efaf1c', 'memory': 'Likes to play cricket', 'agent_id': 'agent_1', 'user_id': 'sam', 'hash': '5e86143436d3842514f63aab4a8335a9', 'metadata': None, 'categories': None, 'created_at': '2025-01-12T21:10:20.044056-08:00', 'updated_at': '2025-01-12T21:10:20.044092-08:00', 'score': 0.37636341138324625}], | ||
'relations': [{'source': 'sam', 'source_type': 'person', 'relationship': 'likes_to_eat', 'target': 'pizza', 'target_type': 'food'}] | ||
} | ||
``` | ||
</CodeGroup> | ||
|
||
## Get All | ||
|
||
Use the `get_all()` method with the `enable_graph` property to get all the memories in the graph database. | ||
|
||
```python | ||
result = client.get_all( | ||
user_id="sam", | ||
agent_id="agent_1", | ||
enable_graph=True, | ||
output_format="v1.1" | ||
) | ||
print(result) | ||
``` | ||
|
||
This will return all the memories in the graph database. | ||
|
||
<CodeGroup> | ||
```json Output | ||
{ | ||
'results': [ | ||
{'id': 'e3a2bd50-bef8-45a3-9ee0-f97dc4e981c2', 'memory': 'Likes to eat pizza', 'agent_id': 'agent_1', 'user_id': 'sam', 'hash': 'e0b64254f555327eca2f7fd606dbb680', 'metadata': None, 'categories': None, 'created_at': '2025-01-12T22:42:24.200506-08:00', 'updated_at': '2025-01-12T22:42:24.200556-08:00'}, | ||
{'id': '438fb702-b839-4ffc-9fb4-2bead4efaf1c', 'memory': 'Likes to play cricket', 'agent_id': 'agent_1', 'user_id': 'sam', 'hash': '5e86143436d3842514f63aab4a8335a9', 'metadata': None, 'categories': None, 'created_at': '2025-01-12T21:10:20.044056-08:00', 'updated_at': '2025-01-12T21:10:20.044092-08:00'}, | ||
{'id': 'b2e0c620-04c1-4cd5-a644-9c344b8b9495', 'memory': 'Likes to play football', 'agent_id': 'agent_1', 'user_id': 'sam', 'hash': '8d562874903746a692f53eb4e5d6de92', 'metadata': None, 'categories': None, 'created_at': '2025-01-12T21:03:56.876662-08:00', 'updated_at': '2025-01-12T21:03:56.876688-08:00'}], | ||
'relations': [ | ||
{'source': 'sam', 'source_type': 'person', 'relationship': 'likes_to_eat', 'target': 'pizza', 'target_type': 'food'}, | ||
{'source': 'sam', 'source_type': 'person', 'relationship': 'likes_to_play', 'target': 'cricket', 'target_type': 'sport'} | ||
] | ||
} | ||
``` | ||
</CodeGroup> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also show the response of this function.