changes to docs for custom categories (#2146)
This commit is contained in:
@@ -5,75 +5,30 @@ description: 'Enhance your product experience by adding custom categories tailor
|
||||
|
||||
## How to set custom categories?
|
||||
|
||||
Users can now create custom categories tailored to their specific needs, in addition to the default categories such as travel, sports, music, and more. When custom categories are provided, they will override the default categories.
|
||||
To setup the custom categories, user has to specify the category name and a description of what that category signifies.
|
||||
Here’s how you can do it:
|
||||
You can now create custom categories tailored to your specific needs, instead of using the default categories such as travel, sports, music, and more (see [default categories](#default-categories) below). **When custom categories are provided, they will override the default categories.**
|
||||
|
||||
```python
|
||||
from mem0 import MemoryClient
|
||||
There are two ways to set custom categories:
|
||||
|
||||
m = MemoryClient(api_key="xxx")
|
||||
### 1. Project Level
|
||||
|
||||
custom_categories = [
|
||||
{"cooking": "For users interested in cooking, including recipes, cooking tips, and culinary experiences."},
|
||||
{"fitness": "Includes content related to fitness, such as workouts, exercises, and fitness tips."}
|
||||
]
|
||||
|
||||
messages = [
|
||||
{"role" : "user", "content" : "Hi, my name is Alice. I love to play badminton."},
|
||||
{"role" : "assistant", "content" : "Hello Alice! It's nice to meet you. Badminton is such an amazing sport. How can I assist you today?"},
|
||||
{"role" : "user", "content" : "I am a fitness freak, I go to gym daily."},
|
||||
{"role" : "assistant", "content" : "That's great! Regular exercise is very beneficial for health."},
|
||||
{"role" : "user", "content" : "Because of my gym plan, I mostly cook at home."},
|
||||
{"role" : "assistant", "content" : "Cooking at home is a good way to ensure you have a balanced diet."}
|
||||
]
|
||||
```
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
client.add(messages, user_id="alice", custom_categories=custom_categories)
|
||||
```
|
||||
|
||||
```markdown Memories with categories
|
||||
User's name is Alice (personal_details)
|
||||
Loves playing badminton (sports)
|
||||
User is a fitness freak. (fitness)
|
||||
Likes to go to gym daily. (fitness)
|
||||
Mostly cook at home because of gym plan. (fitness, cooking)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
<Note> The more detailed the description of categories is, the better output the user will receive. When custom categories are provided in the `add` API call, they will completely replace the default categories and will be directly assigned to the memory, so make sure to include all categories you want to use. </Note>
|
||||
|
||||
|
||||
## Setting Project-Level Custom Categories
|
||||
|
||||
You can also set custom categories at the project level, which will be applied to all memories added within that project. We will automatically assign relevant categories from your custom set to new memories based on their content.
|
||||
You can set custom categories at the project level, which will be applied to all memories added within that project. Mem0 will automatically assign relevant categories from your custom set to new memories based on their content. Setting custom categories at the project level will override the default categories.
|
||||
|
||||
Here's how to set custom categories:
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
from mem0 import MemoryClient
|
||||
|
||||
client = MemoryClient(api_key="<your_mem0_api_key>")
|
||||
|
||||
# Update custom categories
|
||||
new_categories = [
|
||||
{
|
||||
"cooking": "For users interested in cooking and culinary experiences. Includes recipes, cooking tips, meal prep ideas, healthy eating guides, kitchen hacks, and recommendations for cooking tools or ingredients."
|
||||
},
|
||||
{
|
||||
"gym": "Captures all the gym and workout-related content. Includes fitness plans, weightlifting techniques, cardio routines, yoga practices, recovery tips, and recommendations for gym equipment or supplements."
|
||||
},
|
||||
{
|
||||
"office-work": "Includes all the work-related content, focusing on productivity tips, team collaboration strategies, email management, remote work setup advice, time management techniques, and tools for boosting efficiency in a professional setting."
|
||||
},
|
||||
{
|
||||
"personal-life": "Includes all the personal life-related content, such as self-care routines, relationship advice, mindfulness practices, hobbies, life goals, and tips for maintaining a work-life balance."
|
||||
},
|
||||
{
|
||||
"cricket": "Captures all the cricket-related content. Includes match analysis, player statistics, tournament schedules, game highlights, tips for playing cricket, and updates on domestic and international cricket leagues."
|
||||
}
|
||||
{"lifestyle_management_concerns": "Tracks daily routines, habits, hobbies and interests including cooking, time management and work-life balance"},
|
||||
{"seeking_structure": "Documents goals around creating routines, schedules, and organized systems in various life areas"},
|
||||
{"personal_information": "Basic information about the user including name, preferences, and personality traits"}
|
||||
]
|
||||
|
||||
response = client.update_project(custom_categories=new_categories)
|
||||
response = client.update_custom_instructions_and_categories({"custom_categories": new_categories})
|
||||
print(response)
|
||||
```
|
||||
|
||||
@@ -84,14 +39,34 @@ print(response)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
This is how you will use these custom categories during the `add` API call:
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
messages = [
|
||||
{"role": "user", "content": "My name is Alice. I need help organizing my daily schedule better. I feel overwhelmed trying to balance work, exercise, and social life."},
|
||||
{"role": "assistant", "content": "I understand how overwhelming that can feel. Let's break this down together. What specific areas of your schedule feel most challenging to manage?"},
|
||||
{"role": "user", "content": "I want to be more productive at work, maintain a consistent workout routine, and still have energy for friends and hobbies."},
|
||||
{"role": "assistant", "content": "Those are great goals for better time management. What's one small change you could make to start improving your daily routine?"},
|
||||
]
|
||||
|
||||
# Add memories with custom categories
|
||||
client.add(messages, user_id="alice"))
|
||||
```
|
||||
|
||||
```python Memories with categories
|
||||
# Following categories will be created for the memories added
|
||||
Wants to have energy for friends and hobbies (lifestyle_management_concerns)
|
||||
Wants to maintain a consistent workout routine (seeking_structure, lifestyle_management_concerns)
|
||||
Wants to be more productive at work (lifestyle_management_concerns, seeking_structure)
|
||||
Name is Alice (personal_information)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
You can also retrieve the current custom categories:
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
from mem0 import MemoryClient
|
||||
|
||||
client = MemoryClient(api_key="xxx")
|
||||
|
||||
# Get current custom categories
|
||||
categories = client.get_project(fields=["custom_categories"])
|
||||
print(categories)
|
||||
@@ -100,21 +75,9 @@ print(categories)
|
||||
```json Output
|
||||
{
|
||||
"custom_categories": [
|
||||
{
|
||||
"cooking": "For users interested in cooking and culinary experiences. Includes recipes, cooking tips, meal prep ideas, healthy eating guides, kitchen hacks, and recommendations for cooking tools or ingredients."
|
||||
},
|
||||
{
|
||||
"gym": "Captures all the gym and workout-related content. Includes fitness plans, weightlifting techniques, cardio routines, yoga practices, recovery tips, and recommendations for gym equipment or supplements."
|
||||
},
|
||||
{
|
||||
"office-work": "Includes all the work-related content, focusing on productivity tips, team collaboration strategies, email management, remote work setup advice, time management techniques, and tools for boosting efficiency in a professional setting."
|
||||
},
|
||||
{
|
||||
"personal-life": "Includes all the personal life-related content, such as self-care routines, relationship advice, mindfulness practices, hobbies, life goals, and tips for maintaining a work-life balance."
|
||||
},
|
||||
{
|
||||
"cricket": "Captures all the cricket-related content. Includes match analysis, player statistics, tournament schedules, game highlights, tips for playing cricket, and updates on domestic and international cricket leagues."
|
||||
}
|
||||
{"lifestyle_management_concerns": "Tracks daily routines, habits, hobbies and interests including cooking, time management and work-life balance"},
|
||||
{"seeking_structure": "Documents goals around creating routines, schedules, and organized systems in various life areas"},
|
||||
{"personal_information": "Basic information about the user including name, preferences, and personality traits"}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -123,9 +86,46 @@ print(categories)
|
||||
|
||||
These project-level categories will be automatically applied to all new memories added to the project.
|
||||
|
||||
## Default Categories
|
||||
Here is the list of **default categories**. Ensure you review these before creating custom categories to prevent duplication.
|
||||
|
||||
|
||||
### 2. During the `add` API call
|
||||
You can also set custom categories during the `add` API call. This will override any project-level custom categories for that specific memory addition. For example, if you want to use different categories for food-related memories, you can provide custom categories like "food" and "user_preferences" in the `add` call. These custom categories will be used instead of the project-level categories when categorizing those specific memories.
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
from mem0 import MemoryClient
|
||||
|
||||
client = MemoryClient(api_key="<your_mem0_api_key>")
|
||||
|
||||
custom_categories = [
|
||||
{"seeking_structure": "Documents goals around creating routines, schedules, and organized systems in various life areas"},
|
||||
{"personal_information": "Basic information about the user including name, preferences, and personality traits"}
|
||||
]
|
||||
|
||||
messages = [
|
||||
{"role": "user", "content": "My name is Alice. I need help organizing my daily schedule better. I feel overwhelmed trying to balance work, exercise, and social life."},
|
||||
{"role": "assistant", "content": "I understand how overwhelming that can feel. Let's break this down together. What specific areas of your schedule feel most challenging to manage?"},
|
||||
{"role": "user", "content": "I want to be more productive at work, maintain a consistent workout routine, and still have energy for friends and hobbies."},
|
||||
{"role": "assistant", "content": "Those are great goals for better time management. What's one small change you could make to start improving your daily routine?"},
|
||||
]
|
||||
|
||||
client.add(messages, user_id="alice", custom_categories=custom_categories)
|
||||
```
|
||||
|
||||
```python Memories with categories
|
||||
# Following categories will be created for the memories added
|
||||
Wants to have energy for friends and hobbies (seeking_structure)
|
||||
Wants to maintain a consistent workout routine (seeking_structure)
|
||||
Wants to be more productive at work (seeking_structure)
|
||||
Name is Alice (personal_information)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
<Note>Providing more detailed and specific category descriptions will lead to more accurate and relevant memory categorization.</Note>
|
||||
|
||||
|
||||
## Default Categories
|
||||
Here is the list of **default categories**. If you don't specify any custom categories using the above methods, these will be used as default categories.
|
||||
```
|
||||
- personal_details
|
||||
- family
|
||||
@@ -144,6 +144,48 @@ Here is the list of **default categories**. Ensure you review these before creat
|
||||
- misc
|
||||
```
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
from mem0 import MemoryClient
|
||||
|
||||
client = MemoryClient(api_key="<your_mem0_api_key>")
|
||||
|
||||
messages = [
|
||||
{"role": "user", "content": "Hi, my name is Alice."},
|
||||
{"role": "assistant", "content": "Hi Alice, what sports do you like to play?"},
|
||||
{"role": "user", "content": "I love playing badminton, football, and basketball. I'm quite athletic!"},
|
||||
{"role": "assistant", "content": "That's great! Alice seems to enjoy both individual sports like badminton and team sports like football and basketball."},
|
||||
{"role": "user", "content": "Sometimes, I also draw and sketch in my free time."},
|
||||
{"role": "assistant", "content": "That's cool! I'm sure you're good at it."}
|
||||
]
|
||||
|
||||
# Add memories with default categories
|
||||
client.add(messages, user_id='alice')
|
||||
```
|
||||
|
||||
```python Memories with categories
|
||||
# Following categories will be created for the memories added
|
||||
Sometimes draws and sketches in free time (hobbies)
|
||||
Is quite athletic (sports)
|
||||
Loves playing badminton, football, and basketball (sports)
|
||||
Name is Alice (personal_details)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
You can check whether default categories are being used by calling `get_custom_instructions_and_categories()`. If `custom_categories` returns `None`, it means the default categories are being used.
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
client.get_custom_instructions_and_categories(["custom_categories"])
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
'custom_categories': None
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
Reference in New Issue
Block a user