fix(sdk): removing the enable graph flag and switching from snake case to camel case for client ts sdk (#4776)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -47,7 +47,6 @@ Provide at least one message or direct memory string. Most callers supply `messa
|
||||
| `messages` | array | No* | Conversation turns for Mem0 to infer memories from. Each object should include `role` and `content`. |
|
||||
| `metadata` | object | Optional | Custom key/value metadata (e.g., `{"topic": "preferences"}`). |
|
||||
| `infer` | boolean (default `true`) | Optional | Set to `false` to skip inference and store the provided text as-is. |
|
||||
| `enable_graph` | boolean (default `false`) | Optional | Set to `true` to create entity nodes and relationships for knowledge graph. |
|
||||
|
||||
> \* Provide at least one `messages` entry to describe what you are storing. For scoped memories, include `user_id`. You can also attach `agent_id`, `app_id`, `run_id`, `project_id`, or `org_id` to refine ownership.
|
||||
|
||||
@@ -82,20 +81,3 @@ Successful requests return an array of events queued for processing. Each event
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
## Graph relationships
|
||||
|
||||
Add Memories can enrich the knowledge graph on write. Set `enable_graph: true` to create entity nodes and relationships for the stored memory. Use this when you want downstream `get_all` or search calls to traverse connected entities.
|
||||
|
||||
<CodeGroup>
|
||||
```json Graph-aware request
|
||||
{
|
||||
"user_id": "alice",
|
||||
"messages": [
|
||||
{ "role": "user", "content": "I met with Dr. Lee at General Hospital." }
|
||||
],
|
||||
"enable_graph": true
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
The response follows the same format, and related entities become available in [Graph Memory](/platform/features/graph-memory) queries.
|
||||
|
||||
@@ -95,9 +95,6 @@ client.project.update(
|
||||
custom_instructions="..."
|
||||
)
|
||||
|
||||
# Enable graph memory for the project
|
||||
client.project.update(enable_graph=True)
|
||||
|
||||
# Use the input language for memory storage and retrieval
|
||||
client.project.update(multilingual=True)
|
||||
|
||||
@@ -108,7 +105,6 @@ client.project.update(
|
||||
{"personal_info": "User personal information and preferences"},
|
||||
{"work_context": "Professional context and work-related information"}
|
||||
],
|
||||
enable_graph=True,
|
||||
multilingual=True
|
||||
)
|
||||
```
|
||||
@@ -173,7 +169,7 @@ async def manage_project():
|
||||
|
||||
# All methods support async/await
|
||||
project_info = await client.project.get()
|
||||
await client.project.update(enable_graph=True)
|
||||
await client.project.update(multilingual=True)
|
||||
members = await client.project.get_members()
|
||||
|
||||
# To call the async function properly
|
||||
|
||||
@@ -137,7 +137,7 @@ With Mem0 and AWS services like Bedrock, OpenSearch, and Neptune Analytics, you
|
||||
<Card title="Neptune Analytics with Mem0" icon="database" href="/cookbooks/integrations/neptune-analytics">
|
||||
Explore graph-based memory storage with AWS Neptune Analytics.
|
||||
</Card>
|
||||
<Card title="Graph Memory Features" icon="sitemap" href="/platform/features/graph-memory">
|
||||
<Card title="Graph Memory Features" icon="sitemap" href="/open-source/features/graph-memory">
|
||||
Learn how to leverage knowledge graphs for entity relationships.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
@@ -172,7 +172,6 @@ For full list of supported fields, required formats, and advanced options, see t
|
||||
| Capability | Mem0 Platform | Mem0 OSS |
|
||||
| --- | --- | --- |
|
||||
| Conflict resolution | Automatic with dashboard visibility | SDK handles merges locally; you control storage |
|
||||
| Graph writes | Toggle per request (`enable_graph=True`) | Requires configuring a graph provider |
|
||||
| Rate limits | Managed quotas per workspace | Limited by your hardware and provider APIs |
|
||||
| Dashboard visibility | Yes — inspect memories visually | Inspect via CLI, logs, or custom UI |
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ import MemoryClient from 'mem0ai';
|
||||
|
||||
const client = new MemoryClient({ apiKey: "your-api-key" });
|
||||
|
||||
client.deleteAll({ user_id: "alice" })
|
||||
client.deleteAll({ userId: "alice" })
|
||||
.then(result => console.log(result))
|
||||
.catch(error => console.error(error));
|
||||
```
|
||||
@@ -162,12 +162,12 @@ import MemoryClient from 'mem0ai';
|
||||
const client = new MemoryClient({ apiKey: "your-api-key" });
|
||||
|
||||
// Delete all memories across every user in the project
|
||||
client.deleteAll({ user_id: "*" })
|
||||
client.deleteAll({ userId: "*" })
|
||||
.then(result => console.log(result))
|
||||
.catch(error => console.error(error));
|
||||
|
||||
// Full project wipe — all four filters must be explicitly set to "*"
|
||||
client.deleteAll({ user_id: "*", agent_id: "*", app_id: "*", run_id: "*" })
|
||||
client.deleteAll({ userId: "*", agentId: "*", appId: "*", runId: "*" })
|
||||
.then(result => console.log(result))
|
||||
.catch(error => console.error(error));
|
||||
```
|
||||
|
||||
+5
-2
@@ -78,7 +78,6 @@
|
||||
"group": "Advanced Features",
|
||||
"icon": "bolt",
|
||||
"pages": [
|
||||
"platform/features/graph-memory",
|
||||
"platform/features/graph-threshold",
|
||||
"platform/features/advanced-retrieval",
|
||||
"platform/advanced-memory-operations",
|
||||
@@ -633,6 +632,10 @@
|
||||
"source": "/open-source/features/custom-fact-extraction-prompt",
|
||||
"destination": "/open-source/features/custom-instructions"
|
||||
},
|
||||
{
|
||||
"source": "/platform/features/graph-memory",
|
||||
"destination": "/open-source/features/graph-memory"
|
||||
},
|
||||
{
|
||||
"source": "/changelog",
|
||||
"destination": "/changelog/highlights"
|
||||
@@ -987,7 +990,7 @@
|
||||
},
|
||||
{
|
||||
"source": "/features/graph-memory",
|
||||
"destination": "/platform/features/graph-memory"
|
||||
"destination": "/open-source/features/graph-memory"
|
||||
},
|
||||
{
|
||||
"source": "/features/:slug",
|
||||
|
||||
@@ -123,7 +123,6 @@ export NEO4J_PASSWORD="your-password"
|
||||
import { Memory } from "mem0ai/oss";
|
||||
|
||||
const config = {
|
||||
enableGraph: true,
|
||||
graphStore: {
|
||||
provider: "neo4j",
|
||||
config: {
|
||||
@@ -196,7 +195,6 @@ memory = Memory.from_config(config_dict=config)
|
||||
import { Memory } from "mem0ai/oss";
|
||||
|
||||
const config = {
|
||||
enableGraph: true,
|
||||
graphStore: {
|
||||
provider: "neo4j",
|
||||
config: {
|
||||
@@ -217,14 +215,6 @@ const memory = new Memory(config);
|
||||
|
||||
```python
|
||||
config["graph_store"]["config"]["threshold"] = 0.75
|
||||
```
|
||||
</Accordion>
|
||||
<Accordion title="Toggle graph writes per request">
|
||||
Disable graph writes or reads when you only want vector behaviour.
|
||||
|
||||
```python
|
||||
memory.add(messages, user_id="demo-user", enable_graph=False)
|
||||
results = memory.search("marketing partners", user_id="demo-user", enable_graph=False)
|
||||
```
|
||||
</Accordion>
|
||||
<Accordion title="Organize multi-agent graphs">
|
||||
@@ -257,9 +247,6 @@ Monitor graph growth, especially on free tiers, by periodically cleaning dormant
|
||||
<Accordion title="Neptune Analytics rejects requests">
|
||||
Ensure the graph identifier matches the vector dimension used by your embedder and that the IAM role allows `neptune-graph:*DataViaQuery` actions.
|
||||
</Accordion>
|
||||
<Accordion title="Graph store outage fallback">
|
||||
Catch the provider error and retry with `enable_graph=False` so vector-only search keeps serving responses while the graph backend recovers.
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## Decision Points
|
||||
@@ -280,7 +267,6 @@ Choose your backend and expand the matching panel for configuration details and
|
||||
import { Memory } from "mem0ai/oss";
|
||||
|
||||
const config = {
|
||||
enableGraph: true,
|
||||
graphStore: {
|
||||
provider: "neo4j",
|
||||
config: {
|
||||
|
||||
@@ -81,7 +81,7 @@ const messages = [
|
||||
}
|
||||
];
|
||||
|
||||
await client.add(messages, { user_id: "alice" });
|
||||
await client.add(messages, { userId: "alice" });
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
@@ -148,7 +148,7 @@ const messages = [
|
||||
}
|
||||
];
|
||||
|
||||
await client.add(messages, { user_id: "alice" });
|
||||
await client.add(messages, { userId: "alice" });
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
@@ -264,7 +264,7 @@ try {
|
||||
}
|
||||
}];
|
||||
|
||||
await client.add(messages, { user_id: "user123" });
|
||||
await client.add(messages, { userId: "user123" });
|
||||
console.log("Image processed successfully");
|
||||
} catch (error: any) {
|
||||
if (error.type === "invalid_image") {
|
||||
|
||||
@@ -209,14 +209,6 @@ Mem0 offers granular configuration across vector stores, LLMs, embedders, and hi
|
||||
| `topP` | Probability threshold | All |
|
||||
| `topK` | Token count to keep | All |
|
||||
| `openaiBaseUrl` | Base URL override | OpenAI |
|
||||
</Accordion>
|
||||
<Accordion title="Graph store">
|
||||
| Parameter | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| `provider` | Graph store provider (e.g., `"neo4j"`) | `"neo4j"` |
|
||||
| `url` | Connection URL | `process.env.NEO4J_URL` |
|
||||
| `username` | Username | `process.env.NEO4J_USERNAME` |
|
||||
| `password` | Password | `process.env.NEO4J_PASSWORD` |
|
||||
</Accordion>
|
||||
<Accordion title="Embedder">
|
||||
| Parameter | Description | Default |
|
||||
|
||||
@@ -81,7 +81,6 @@ result = await memory.add(
|
||||
conversation,
|
||||
user_id="traveler-42",
|
||||
metadata={"trip": "japan-2025", "preferences": ["boutique", "no-shellfish"]},
|
||||
enable_graph=True,
|
||||
run_id="planning-call-1",
|
||||
)
|
||||
```
|
||||
@@ -101,7 +100,6 @@ const conversation = [
|
||||
const result = await memory.add(conversation, {
|
||||
userId: "traveler-42",
|
||||
metadata: { trip: "japan-2025", preferences: ["boutique", "no-shellfish"] },
|
||||
enableGraph: true,
|
||||
runId: "planning-call-1",
|
||||
});
|
||||
```
|
||||
@@ -163,10 +161,6 @@ await memory.update(matches.results[0].id, {
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
<Tip>
|
||||
Need to pause graph writes on a per-request basis? Pass `enableGraph: false` (TypeScript) or `enable_graph=False` (Python) when latency matters more than relationship building.
|
||||
</Tip>
|
||||
|
||||
## Clean up
|
||||
|
||||
<Tabs>
|
||||
@@ -192,8 +186,6 @@ await memory.deleteAll({ userId: "traveler-42", runId: "planning-call-1" });
|
||||
|
||||
## Quick recovery
|
||||
|
||||
- `Missing required key enableGraph`: update the SDK to `mem0ai>=0.4.0`.
|
||||
- `Graph backend unavailable`: retry with `enableGraph=False` and inspect your graph provider status.
|
||||
- Empty results with filters: log `filters` values and confirm metadata keys match (case-sensitive).
|
||||
|
||||
<Warning>
|
||||
|
||||
@@ -50,7 +50,7 @@ const messages = [
|
||||
{"role": "user", "content": "Alice loves playing badminton"},
|
||||
{"role": "assistant", "content": "That's great! Alice is a fitness freak"},
|
||||
];
|
||||
await client.add(messages, { user_id: "alice" });
|
||||
await client.add(messages, { userId: "alice" });
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
@@ -66,7 +66,7 @@ await client.search("What is Alice's favorite sport?", user_id="alice")
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
await client.search("What is Alice's favorite sport?", { user_id: "alice" });
|
||||
await client.search("What is Alice's favorite sport?", { userId: "alice" });
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
@@ -118,7 +118,7 @@ await client.delete_all(user_id="alice")
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
await client.deleteAll({ user_id: "alice" });
|
||||
await client.deleteAll({ userId: "alice" });
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
@@ -25,7 +25,7 @@ const messages = [
|
||||
{"role": "assistant", "content": "Great! I'll remember your preference for Italian cuisine."}
|
||||
];
|
||||
|
||||
await client.add(messages, { user_id: "user123", version: "v2" });
|
||||
await client.add(messages, { userId: "user123", version: "v2" });
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
@@ -65,14 +65,14 @@ const messages1 = [
|
||||
{"role": "user", "content": "Hi, I'm Sarah from New York"},
|
||||
{"role": "assistant", "content": "Hello Sarah! Nice to meet you."}
|
||||
];
|
||||
await client.add(messages1, { user_id: "sarah", version: "v2" });
|
||||
await client.add(messages1, { userId: "sarah", version: "v2" });
|
||||
|
||||
// Later interaction - just send new messages
|
||||
const messages2 = [
|
||||
{"role": "user", "content": "I'm planning a trip to Italy next month"},
|
||||
{"role": "assistant", "content": "How exciting! Italy is beautiful this time of year."}
|
||||
];
|
||||
await client.add(messages2, { user_id: "sarah", version: "v2" });
|
||||
await client.add(messages2, { userId: "sarah", version: "v2" });
|
||||
// Mem0 automatically knows Sarah is from New York and can use this context
|
||||
```
|
||||
</CodeGroup>
|
||||
@@ -104,7 +104,7 @@ const messages = [
|
||||
{"role": "assistant", "content": "I've noted your allergies for future reference."}
|
||||
];
|
||||
|
||||
await client.add(messages, { user_id: "user123", version: "v2" });
|
||||
await client.add(messages, { userId: "user123", version: "v2" });
|
||||
// This allergy info will be available in ALL future interactions
|
||||
```
|
||||
</CodeGroup>
|
||||
@@ -143,21 +143,21 @@ const messages1 = [
|
||||
{"role": "user", "content": "I want to plan a 5-day trip to Tokyo"},
|
||||
{"role": "assistant", "content": "Perfect! Let's plan your Tokyo adventure."}
|
||||
];
|
||||
await client.add(messages1, { user_id: "user123", run_id: "tokyo-trip-2024", version: "v2" });
|
||||
await client.add(messages1, { userId: "user123", runId: "tokyo-trip-2024", version: "v2" });
|
||||
|
||||
// Later in the same trip planning session
|
||||
const messages2 = [
|
||||
{"role": "user", "content": "I prefer staying near Shibuya"},
|
||||
{"role": "assistant", "content": "Great choice! Shibuya is very convenient."}
|
||||
];
|
||||
await client.add(messages2, { user_id: "user123", run_id: "tokyo-trip-2024", version: "v2" });
|
||||
await client.add(messages2, { userId: "user123", runId: "tokyo-trip-2024", version: "v2" });
|
||||
|
||||
// Different session for work project (separate context)
|
||||
const workMessages = [
|
||||
{"role": "user", "content": "Let's discuss the Q4 marketing strategy"},
|
||||
{"role": "assistant", "content": "Sure! What are your main goals for Q4?"}
|
||||
];
|
||||
await client.add(workMessages, { user_id: "user123", run_id: "q4-marketing", version: "v2" });
|
||||
await client.add(workMessages, { userId: "user123", runId: "q4-marketing", version: "v2" });
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ Extract only health and wellness information:
|
||||
Exclude: Personal identifiers, financial data
|
||||
`;
|
||||
|
||||
await client.project.update({ custom_instructions: prompt });
|
||||
await client.project.update({ customInstructions: prompt });
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
@@ -60,11 +60,11 @@ print(response["custom_instructions"])
|
||||
|
||||
```javascript JavaScript
|
||||
// Set instructions for your project
|
||||
await client.project.update({ custom_instructions: "Your guidelines here..." });
|
||||
await client.project.update({ customInstructions: "Your guidelines here..." });
|
||||
|
||||
// Retrieve current instructions
|
||||
const response = await client.project.get({ fields: ["custom_instructions"] });
|
||||
console.log(response.custom_instructions);
|
||||
const response = await client.project.get({ fields: ["customInstructions"] });
|
||||
console.log(response.customInstructions);
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
@@ -145,7 +145,7 @@ Extract customer service information for better support:
|
||||
Exclude: Payment card numbers, passwords, personal identifiers.
|
||||
`;
|
||||
|
||||
await client.project.update({ custom_instructions: instructions });
|
||||
await client.project.update({ customInstructions: instructions });
|
||||
```
|
||||
</CodeGroup>
|
||||
</Tab>
|
||||
@@ -198,7 +198,7 @@ Extract learning-related information for personalized education:
|
||||
Exclude: Specific grades, personal identifiers, financial information.
|
||||
`;
|
||||
|
||||
await client.project.update({ custom_instructions: educationPrompt });
|
||||
await client.project.update({ customInstructions: educationPrompt });
|
||||
```
|
||||
</CodeGroup>
|
||||
</Tab>
|
||||
@@ -251,7 +251,7 @@ Extract financial planning information for advisory services:
|
||||
Exclude: Account numbers, SSNs, passwords, specific financial amounts.
|
||||
`;
|
||||
|
||||
await client.project.update({ custom_instructions: financePrompt });
|
||||
await client.project.update({ customInstructions: financePrompt });
|
||||
```
|
||||
</CodeGroup>
|
||||
</Tab>
|
||||
|
||||
@@ -1,333 +0,0 @@
|
||||
---
|
||||
title: Graph Memory
|
||||
description: "Enable graph-based memory retrieval for more contextually relevant results"
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
Graph Memory enhances the memory pipeline by creating relationships between entities in your data. It builds a network of interconnected information for more contextually relevant search results.
|
||||
|
||||
This feature allows your AI applications to understand connections between entities, providing richer context for responses. It's ideal for applications needing relationship tracking and nuanced information retrieval across related memories.
|
||||
|
||||
## How Graph Memory Works
|
||||
|
||||
The Graph Memory feature analyzes how each entity connects and relates to each other. When enabled:
|
||||
|
||||
1. Mem0 automatically builds a graph representation of entities
|
||||
2. Vector search returns the top semantic matches (with any reranker you configure)
|
||||
3. Graph relations are returned alongside those results to provide additional context—they do not reorder the vector hits
|
||||
|
||||
## Using Graph Memory
|
||||
|
||||
To use Graph Memory, you need to enable it in your API calls by setting the `enable_graph=True` parameter.
|
||||
|
||||
### Adding Memories with Graph Memory
|
||||
|
||||
When adding new memories, enable Graph Memory to automatically build relationships with existing memories:
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
from mem0 import MemoryClient
|
||||
|
||||
client = MemoryClient(api_key="your-api-key")
|
||||
|
||||
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"}
|
||||
]
|
||||
|
||||
# Enable graph memory when adding
|
||||
client.add(
|
||||
messages,
|
||||
user_id="joseph",
|
||||
enable_graph=True
|
||||
)
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
import { MemoryClient } from "mem0";
|
||||
|
||||
const client = new MemoryClient({ apiKey: "your-api-key" });
|
||||
|
||||
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" }
|
||||
];
|
||||
|
||||
// Enable graph memory when adding
|
||||
await client.add({
|
||||
messages,
|
||||
user_id: "joseph",
|
||||
enable_graph: true
|
||||
});
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"memory": "Name is Joseph",
|
||||
"event": "ADD",
|
||||
"id": "4a5a417a-fa10-43b5-8c53-a77c45e80438"
|
||||
},
|
||||
{
|
||||
"memory": "Is from Seattle",
|
||||
"event": "ADD",
|
||||
"id": "8d268d0f-5452-4714-b27d-ae46f676a49d"
|
||||
},
|
||||
{
|
||||
"memory": "Is a software engineer",
|
||||
"event": "ADD",
|
||||
"id": "5f0a184e-ddea-4fe6-9b92-692d6a901df8"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
The graph memory would look like this:
|
||||
|
||||
<Frame>
|
||||
<img src="/images/graph-platform.png" alt="Graph Memory Visualization showing relationships between entities" />
|
||||
</Frame>
|
||||
|
||||
<Caption>Graph Memory creates a network of relationships between entities, enabling more contextual retrieval</Caption>
|
||||
|
||||
|
||||
<Note>
|
||||
Response for the graph memory's `add` operation will not be available directly in the response. As adding graph memories is an asynchronous operation due to heavy processing, you can use the `get_all()` endpoint to retrieve the memory with the graph metadata.
|
||||
</Note>
|
||||
|
||||
|
||||
### Searching with Graph Memory
|
||||
|
||||
When searching memories, Graph Memory helps retrieve entities that are contextually important even if they're not direct semantic matches.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
# Search with graph memory enabled
|
||||
results = client.search(
|
||||
"what is my name?",
|
||||
user_id="joseph",
|
||||
enable_graph=True
|
||||
)
|
||||
|
||||
print(results)
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
// Search with graph memory enabled
|
||||
const results = await client.search({
|
||||
query: "what is my name?",
|
||||
user_id: "joseph",
|
||||
enable_graph: true
|
||||
});
|
||||
|
||||
console.log(results);
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"id": "4a5a417a-fa10-43b5-8c53-a77c45e80438",
|
||||
"memory": "Name is Joseph",
|
||||
"user_id": "joseph",
|
||||
"metadata": null,
|
||||
"categories": ["personal_details"],
|
||||
"immutable": false,
|
||||
"created_at": "2025-03-19T09:09:00.146390-07:00",
|
||||
"updated_at": "2025-03-19T09:09:00.146404-07:00",
|
||||
"score": 0.3621795393335552
|
||||
},
|
||||
{
|
||||
"id": "8d268d0f-5452-4714-b27d-ae46f676a49d",
|
||||
"memory": "Is from Seattle",
|
||||
"user_id": "joseph",
|
||||
"metadata": null,
|
||||
"categories": ["personal_details"],
|
||||
"immutable": false,
|
||||
"created_at": "2025-03-19T09:09:00.170680-07:00",
|
||||
"updated_at": "2025-03-19T09:09:00.170692-07:00",
|
||||
"score": 0.31212713194651254
|
||||
}
|
||||
],
|
||||
"relations": [
|
||||
{
|
||||
"source": "joseph",
|
||||
"source_type": "person",
|
||||
"relationship": "name",
|
||||
"target": "joseph",
|
||||
"target_type": "person",
|
||||
"score": 0.39
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
<Note>
|
||||
`results` always reflects the vector search order (optionally reranked). Graph Memory augments that response by adding related entities in the `relations` array; it does not re-rank the vector results automatically.
|
||||
</Note>
|
||||
|
||||
### Retrieving All Memories with Graph Memory
|
||||
|
||||
When retrieving all memories, Graph Memory provides additional relationship context:
|
||||
|
||||
<Callout type="warning" title="Filters Required">
|
||||
`get_all()` now requires filters to be specified.
|
||||
</Callout>
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
# Get all memories with graph context
|
||||
memories = client.get_all(
|
||||
filters={"AND": [{"user_id": "joseph"}]},
|
||||
enable_graph=True
|
||||
)
|
||||
|
||||
print(memories)
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
// Get all memories with graph context
|
||||
const memories = await client.getAll({
|
||||
filters: {"AND": [{"user_id": "joseph"}]},
|
||||
enable_graph: true
|
||||
});
|
||||
|
||||
console.log(memories);
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"id": "5f0a184e-ddea-4fe6-9b92-692d6a901df8",
|
||||
"memory": "Is a software engineer",
|
||||
"user_id": "joseph",
|
||||
"metadata": null,
|
||||
"categories": ["professional_details"],
|
||||
"immutable": false,
|
||||
"created_at": "2025-03-19T09:09:00.194116-07:00",
|
||||
"updated_at": "2025-03-19T09:09:00.194128-07:00",
|
||||
},
|
||||
{
|
||||
"id": "8d268d0f-5452-4714-b27d-ae46f676a49d",
|
||||
"memory": "Is from Seattle",
|
||||
"user_id": "joseph",
|
||||
"metadata": null,
|
||||
"categories": ["personal_details"],
|
||||
"immutable": false,
|
||||
"created_at": "2025-03-19T09:09:00.170680-07:00",
|
||||
"updated_at": "2025-03-19T09:09:00.170692-07:00",
|
||||
},
|
||||
{
|
||||
"id": "4a5a417a-fa10-43b5-8c53-a77c45e80438",
|
||||
"memory": "Name is Joseph",
|
||||
"user_id": "joseph",
|
||||
"metadata": null,
|
||||
"categories": ["personal_details"],
|
||||
"immutable": false,
|
||||
"created_at": "2025-03-19T09:09:00.146390-07:00",
|
||||
"updated_at": "2025-03-19T09:09:00.146404-07:00",
|
||||
}
|
||||
],
|
||||
"relations": [
|
||||
{
|
||||
"source": "joseph",
|
||||
"source_type": "person",
|
||||
"relationship": "name",
|
||||
"target": "joseph",
|
||||
"target_type": "person"
|
||||
},
|
||||
{
|
||||
"source": "joseph",
|
||||
"source_type": "person",
|
||||
"relationship": "city",
|
||||
"target": "seattle",
|
||||
"target_type": "city"
|
||||
},
|
||||
{
|
||||
"source": "joseph",
|
||||
"source_type": "person",
|
||||
"relationship": "job",
|
||||
"target": "software engineer",
|
||||
"target_type": "job"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
</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")
|
||||
|
||||
# Enable graph memory for all operations in this project
|
||||
client.project.update(enable_graph=True)
|
||||
|
||||
# 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"
|
||||
)
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
import { MemoryClient } from "mem0";
|
||||
|
||||
const client = new MemoryClient({ apiKey: "your-api-key" });
|
||||
|
||||
// Enable graph memory for all operations in this project
|
||||
await client.project.update({ enable_graph: true });
|
||||
|
||||
// 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"
|
||||
});
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
|
||||
## Best Practices
|
||||
|
||||
- Enable Graph Memory for applications where understanding context and relationships between memories is important.
|
||||
- Graph Memory works best with a rich history of related conversations.
|
||||
- Consider Graph Memory for long-running assistants that need to track evolving information.
|
||||
|
||||
## Performance Considerations
|
||||
|
||||
Graph Memory requires additional processing and may increase response times slightly for very large memory stores. However, for most use cases, the improved retrieval quality outweighs the minimal performance impact.
|
||||
|
||||
If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
@@ -206,5 +206,5 @@ config = {"graph_store": {"threshold": 0.7}} # Valid: 0.0 ≤ x ≤ 1.0
|
||||
|
||||
## Related
|
||||
|
||||
- [Graph Memory](/platform/features/graph-memory)
|
||||
- [Graph Memory](/open-source/features/graph-memory)
|
||||
- [Issue #3590](https://github.com/mem0ai/mem0/issues/3590)
|
||||
|
||||
@@ -134,7 +134,7 @@ const filters = {
|
||||
const responseWithInstructions = await client.createMemoryExport({
|
||||
schema: json_schema,
|
||||
filters: filters,
|
||||
export_instructions: export_instructions
|
||||
exportInstructions: export_instructions
|
||||
});
|
||||
|
||||
console.log(responseWithInstructions);
|
||||
@@ -176,10 +176,10 @@ print(response)
|
||||
|
||||
```javascript JavaScript
|
||||
// Retrieve using export ID
|
||||
const memory_export_id = "550e8400-e29b-41d4-a716-446655440000";
|
||||
const memoryExportId = "550e8400-e29b-41d4-a716-446655440000";
|
||||
|
||||
const response = await client.getMemoryExport({
|
||||
memory_export_id: memory_export_id
|
||||
memoryExportId: memoryExportId
|
||||
});
|
||||
|
||||
console.log(response);
|
||||
|
||||
@@ -67,7 +67,7 @@ const messages = [
|
||||
},
|
||||
]
|
||||
|
||||
await client.add(messages, { user_id: "alice" })
|
||||
await client.add(messages, { userId: "alice" })
|
||||
```
|
||||
|
||||
```json Output
|
||||
@@ -166,7 +166,7 @@ const imageMessage = {
|
||||
}
|
||||
};
|
||||
|
||||
await client.add([imageMessage], { user_id: "alice" })
|
||||
await client.add([imageMessage], { userId: "alice" })
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ Mem0 Platform features help managed deployments scale from basic filtering to gr
|
||||
<Card title="Go Real-Time with Async" icon="bolt" href="/platform/features/async-client">
|
||||
Non-blocking add/search requests for agents.
|
||||
</Card>
|
||||
<Card title="Unlock Graph Memory" icon="circle-nodes" href="/platform/features/graph-memory">
|
||||
<Card title="Unlock Graph Memory" icon="circle-nodes" href="/open-source/features/graph-memory">
|
||||
Relationship-aware recall across entities.
|
||||
</Card>
|
||||
<Card
|
||||
|
||||
@@ -76,7 +76,7 @@ const unixTimestamp = Math.floor(fiveDaysAgo.getTime() / 1000);
|
||||
const messages = [
|
||||
{"role": "user", "content": "I'm travelling to SF"}
|
||||
]
|
||||
client.add(messages, { user_id: "user1", timestamp: unixTimestamp })
|
||||
client.add(messages, { userId: "user1", timestamp: unixTimestamp })
|
||||
.then(response => console.log(response))
|
||||
.catch(error => console.error(error));
|
||||
```
|
||||
@@ -131,7 +131,7 @@ const january2023Timestamp = 1672531200; // Unix timestamp for 2023-01-01 00:00
|
||||
const messages = [
|
||||
{"role": "user", "content": "I'm travelling to SF"}
|
||||
]
|
||||
client.add(messages, { user_id: "user1", timestamp: january2023Timestamp })
|
||||
client.add(messages, { userId: "user1", timestamp: january2023Timestamp })
|
||||
.then(response => console.log(response))
|
||||
.catch(error => console.error(error));
|
||||
```
|
||||
|
||||
@@ -68,7 +68,7 @@ const messages = [
|
||||
{"role": "user", "content": "I'm a vegetarian and allergic to nuts."},
|
||||
{"role": "assistant", "content": "Got it! I'll remember your dietary preferences."}
|
||||
];
|
||||
await client.add(messages, { user_id: "user123" });
|
||||
await client.add(messages, { userId: "user123" });
|
||||
````
|
||||
|
||||
```bash cURL
|
||||
|
||||
Reference in New Issue
Block a user