Files
t6_mem0/docs/features/custom-categories.mdx
Dev Khant 82359774b7 Custom instructions API improvements (#2140)
Co-authored-by: Deshraj Yadav <deshrajdry@gmail.com>
2025-01-15 05:54:23 +05:30

149 lines
6.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Custom Categories
description: 'Enhance your product experience by adding custom categories tailored to your needs'
---
## 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.
Heres how you can do it:
```python
from mem0 import MemoryClient
m = MemoryClient(api_key="xxx")
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.
Here's how to set custom categories:
<CodeGroup>
```python Code
# 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."
}
]
response = client.update_project(custom_categories=new_categories)
print(response)
```
```json Output
{
"message": "Updated custom categories"
}
```
</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)
```
```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."
}
]
}
```
</CodeGroup>
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.
```
- personal_details
- family
- professional_details
- sports
- travel
- food
- music
- health
- technology
- hobbies
- fashion
- entertainment
- milestones
- user_preferences
- misc
```
If you have any questions, please feel free to reach out to us using one of the following methods:
<Snippet file="get-help.mdx" />