Doc: update for enable_graph and Version bump -> 0.1.103 (#2893)
This commit is contained in:
@@ -281,6 +281,67 @@ console.log(memories);
|
|||||||
|
|
||||||
</CodeGroup>
|
</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
|
## Best Practices
|
||||||
|
|
||||||
- Enable Graph Memory for applications where understanding context and relationships between memories is important
|
- Enable Graph Memory for applications where understanding context and relationships between memories is important
|
||||||
|
|||||||
@@ -504,12 +504,17 @@ class MemoryClient:
|
|||||||
custom_instructions: Optional[str] = None,
|
custom_instructions: Optional[str] = None,
|
||||||
custom_categories: Optional[List[str]] = None,
|
custom_categories: Optional[List[str]] = None,
|
||||||
retrieval_criteria: Optional[List[Dict[str, Any]]] = None,
|
retrieval_criteria: Optional[List[Dict[str, Any]]] = None,
|
||||||
|
enable_graph: Optional[bool] = None,
|
||||||
|
version: Optional[str] = None,
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""Update the project settings.
|
"""Update the project settings.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
custom_instructions: New instructions for the project
|
custom_instructions: New instructions for the project
|
||||||
custom_categories: New categories 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:
|
Returns:
|
||||||
Dictionary containing the API response.
|
Dictionary containing the API response.
|
||||||
@@ -521,7 +526,7 @@ class MemoryClient:
|
|||||||
if not (self.org_id and self.project_id):
|
if not (self.org_id and self.project_id):
|
||||||
raise ValueError("org_id and project_id must be set to update instructions or categories")
|
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(
|
raise ValueError(
|
||||||
"Currently we only support updating custom_instructions or custom_categories or retrieval_criteria, so you must provide at least one of them"
|
"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_instructions": custom_instructions,
|
||||||
"custom_categories": custom_categories,
|
"custom_categories": custom_categories,
|
||||||
"retrieval_criteria": retrieval_criteria,
|
"retrieval_criteria": retrieval_criteria,
|
||||||
|
"enable_graph": enable_graph,
|
||||||
|
"version": version,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
response = self.client.patch(
|
response = self.client.patch(
|
||||||
@@ -545,6 +552,8 @@ class MemoryClient:
|
|||||||
"custom_instructions": custom_instructions,
|
"custom_instructions": custom_instructions,
|
||||||
"custom_categories": custom_categories,
|
"custom_categories": custom_categories,
|
||||||
"retrieval_criteria": retrieval_criteria,
|
"retrieval_criteria": retrieval_criteria,
|
||||||
|
"enable_graph": enable_graph,
|
||||||
|
"version": version,
|
||||||
"sync_type": "sync",
|
"sync_type": "sync",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -1100,11 +1109,13 @@ class AsyncMemoryClient:
|
|||||||
custom_instructions: Optional[str] = None,
|
custom_instructions: Optional[str] = None,
|
||||||
custom_categories: Optional[List[str]] = None,
|
custom_categories: Optional[List[str]] = None,
|
||||||
retrieval_criteria: Optional[List[Dict[str, Any]]] = None,
|
retrieval_criteria: Optional[List[Dict[str, Any]]] = None,
|
||||||
|
enable_graph: Optional[bool] = None,
|
||||||
|
version: Optional[str] = None,
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
if not (self.org_id and self.project_id):
|
if not (self.org_id and self.project_id):
|
||||||
raise ValueError("org_id and project_id must be set to update instructions or categories")
|
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(
|
raise ValueError(
|
||||||
"Currently we only support updating custom_instructions or custom_categories or retrieval_criteria, so you must provide at least one of them"
|
"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_instructions": custom_instructions,
|
||||||
"custom_categories": custom_categories,
|
"custom_categories": custom_categories,
|
||||||
"retrieval_criteria": retrieval_criteria,
|
"retrieval_criteria": retrieval_criteria,
|
||||||
|
"enable_graph": enable_graph,
|
||||||
|
"version": version,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
response = await self.async_client.patch(
|
response = await self.async_client.patch(
|
||||||
@@ -1128,6 +1141,8 @@ class AsyncMemoryClient:
|
|||||||
"custom_instructions": custom_instructions,
|
"custom_instructions": custom_instructions,
|
||||||
"custom_categories": custom_categories,
|
"custom_categories": custom_categories,
|
||||||
"retrieval_criteria": retrieval_criteria,
|
"retrieval_criteria": retrieval_criteria,
|
||||||
|
"enable_graph": enable_graph,
|
||||||
|
"version": version,
|
||||||
"sync_type": "async",
|
"sync_type": "async",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user