Abstraction for Project in MemoryClient (#3067)

This commit is contained in:
Dev Khant
2025-07-08 11:33:20 +05:30
committed by GitHub
parent aae5989e78
commit 70d6f9231b
11 changed files with 1071 additions and 39 deletions

View File

@@ -60,6 +60,128 @@ const client = new MemoryClient({organizationId: "YOUR_ORG_ID", projectId: "YOUR
</Tab>
</Tabs>
### Project Management Methods
The Mem0 client provides comprehensive project management capabilities through the `client.project` interface:
#### Get Project Details
Retrieve information about the current project:
```python
# Get all project details
project_info = client.project.get()
# Get specific fields only
project_info = client.project.get(fields=["name", "description", "custom_categories"])
```
#### Create a New Project
Create a new project within your organization:
```python
# Create a project with name and description
new_project = client.project.create(
name="My New Project",
description="A project for managing customer support memories"
)
```
#### Update Project Settings
Modify project configuration including custom instructions, categories, and graph settings:
```python
# Update project with custom categories
client.project.update(
custom_categories=[
{"customer_preferences": "Customer likes, dislikes, and preferences"},
{"support_history": "Previous support interactions and resolutions"}
]
)
# Update project with custom instructions
client.project.update(
custom_instructions="..."
)
# Enable graph memory for the project
client.project.update(enable_graph=True)
# Update multiple settings at once
client.project.update(
custom_instructions="...",
custom_categories=[
{"personal_info": "User personal information and preferences"},
{"work_context": "Professional context and work-related information"}
],
enable_graph=True
)
```
#### Delete Project
<Note>
This action will remove all memories, messages, and other related data in the project. This operation is irreversible.
</Note>
Remove a project and all its associated data:
```python
# Delete the current project (irreversible)
result = client.project.delete()
```
#### Member Management
Manage project members and their access levels:
```python
# Get all project members
members = client.project.get_members()
# Add a new member as a reader
client.project.add_member(
email="colleague@company.com",
role="READER" # or "OWNER"
)
# Update a member's role
client.project.update_member(
email="colleague@company.com",
role="OWNER"
)
# Remove a member from the project
client.project.remove_member(email="colleague@company.com")
```
#### Member Roles
- **READER**: Can view and search memories, but cannot modify project settings or manage members
- **OWNER**: Full access including project modification, member management, and all reader permissions
#### Async Support
All project methods are also available in async mode:
```python
from mem0 import AsyncMemoryClient
async def manage_project():
client = AsyncMemoryClient(org_id='YOUR_ORG_ID', project_id='YOUR_PROJECT_ID')
# All methods support async/await
project_info = await client.project.get()
await client.project.update(enable_graph=True)
members = await client.project.get_members()
# To call the async function properly
import asyncio
asyncio.run(manage_project())
```
## Getting Started
To begin using the Mem0 API, you'll need to:

View File

@@ -81,7 +81,7 @@ retrieval_criteria = [
Once defined, register the criteria to your project:
```python
client.update_project(retrieval_criteria=retrieval_criteria)
client.project.update(retrieval_criteria=retrieval_criteria)
```
Criteria apply project-wide. Once set, they affect all searches using `version="v2"`.
@@ -187,7 +187,7 @@ If no criteria are defined for a project, `version="v2"` behaves like normal sea
## How It Works
1. **Criteria Definition**: Define custom criteria with a name, description, and weight. These describe what matters in a memory (e.g., joy, urgency, empathy).
2. **Project Configuration**: Register these criteria using `update_project()`. They apply at the project level and influence all searches using `version="v2"`.
2. **Project Configuration**: Register these criteria using `project.update()`. They apply at the project level and influence all searches using `version="v2"`.
3. **Memory Retrieval**: When you perform a search with `version="v2"`, Mem0 first retrieves relevant memories based on the query and your defined criteria.
4. **Weighted Scoring**: Each retrieved memory is evaluated and scored against the defined criteria and weights.
@@ -202,7 +202,7 @@ Criteria retrieval is currently supported only in search v2. Make sure to use `v
## Summary
- Define what “relevant” means using criteria
- Apply them per project via `update_project()`
- Apply them per project via `project.update()`
- Use `version="v2"` to activate criteria-aware search
- Build agents that reason not just with relevance, but **contextual importance**

View File

@@ -35,7 +35,7 @@ new_categories = [
{"personal_information": "Basic information about the user including name, preferences, and personality traits"}
]
response = client.update_project(custom_categories = new_categories)
response = client.project.update(custom_categories=new_categories)
print(response)
```
@@ -75,7 +75,7 @@ You can also retrieve the current custom categories:
<CodeGroup>
```python Code
# Get current custom categories
categories = client.get_project(fields=["custom_categories"])
categories = client.project.get(fields=["custom_categories"])
print(categories)
```
@@ -185,11 +185,11 @@ Name is Alice (personal_details)
```
</CodeGroup>
You can check whether default categories are being used by calling `get_project()`. If `custom_categories` returns `None`, it means the default categories are being used.
You can check whether default categories are being used by calling `project.get()`. If `custom_categories` returns `None`, it means the default categories are being used.
<CodeGroup>
```python Code
client.get_project(["custom_categories"])
client.project.get(["custom_categories"])
```
```json Output

View File

@@ -50,7 +50,7 @@ Guidelines:
- Focus solely on health-related content.
- Maintain clarity and context accuracy while recording.
"""
response = client.update_project(custom_instructions=prompt)
response = client.project.update(custom_instructions=prompt)
print(response)
```
@@ -66,7 +66,7 @@ You can also retrieve the current custom instructions:
<CodeGroup>
```python Code
# Retrieve current custom instructions
response = client.get_project(fields=["custom_instructions"])
response = client.project.get(fields=["custom_instructions"])
print(response)
```

View File

@@ -297,7 +297,7 @@ client = MemoryClient(
)
# Enable graph memory for all operations in this project
client.update_project(enable_graph=True, version="v1")
client.project.update(enable_graph=True)
# Now all add operations will use graph memory by default
messages = [