Skip to content

Commit

Permalink
Add support: Custom instruction/categories for projects (#2134)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev-Khant authored Jan 11, 2025
1 parent ac8cf59 commit 7f0d766
Show file tree
Hide file tree
Showing 7 changed files with 658 additions and 191 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: 'Get Custom Instructions and Categories'
openapi: get /api/v1/orgs/organizations/{org_id}/projects/{project_id}/custom-instructions-and-categories/
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: 'Update Custom Instructions and Categories'
openapi: post /api/v1/orgs/organizations/{org_id}/projects/{project_id}/custom-instructions-and-categories/
---

Please refer to the [how to use custom instructions/categories](/features/custom-instructions) for more information.
50 changes: 49 additions & 1 deletion docs/features/custom-categories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,55 @@ Mostly cook at home because of gym plan. (fitness, cooking)

<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>

<Note> We will soon release a feature that allows users to set custom categories in `project`. This will allow the functionality where relevant categories are automatically assigned to the memory based on the input text provided. </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"},
{"fitness": "Content related to fitness and exercise"}
]
response = client.update_custom_instructions_and_categories({"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_custom_instructions_and_categories(["custom_categories"])
print(categories)
```

```json Output
{
"custom_categories": [
{"cooking": "For users interested in cooking and culinary experiences"},
{"fitness": "Content related to fitness and exercise"}
]
}
```
</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.
Expand Down
59 changes: 59 additions & 0 deletions docs/features/custom-instructions.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: Custom Instructions
description: 'Enhance your product experience by adding custom instructions tailored to your needs'
---

## Introduction to Custom Instructions

Custom instructions allow you to define specific guidelines for your project. This feature helps ensure consistency and provides clear direction for handling project-specific requirements.

Custom instructions are particularly useful when you want to:
- Define how information should be extracted from conversations
- Specify what types of data should be captured or ignored
- Set rules for categorizing and organizing memories
- Maintain consistent handling of project-specific requirements

When custom instructions are set at the project level, they will be applied to all new memories added within that project. This ensures that your data is processed according to your defined guidelines across your entire project.

## Setting Custom Instructions

You can set custom instructions for your project using the following method:

<CodeGroup>
```python Code
# Update custom instructions
prompt = """
Your task is to extract ONLY health-related information from conversations, including:
- Medical conditions, symptoms, diagnoses
- Medications, treatments, procedures
- Diet, exercise, sleep habits
- Doctor visits and appointments
- Health metrics (weight, blood pressure, etc)
"""
response = client.update_custom_instructions_and_categories({"custom_instructions": prompt})
print(response)
```

```json Output
{
"message": "Updated custom instructions"
}
```
</CodeGroup>

You can also retrieve the current custom instructions:

<CodeGroup>
```python Code
# Retrieve current custom instructions
response = client.get_custom_instructions_and_categories(["custom_instructions"])
print(response)
```

```json Output
{
"custom_instructions": "Your task is to extract ONLY health-related information from conversations, including:\n\n- Medical conditions, symptoms, diagnoses\n- Medications, treatments, procedures\n- Diet, exercise, sleep habits\n- Doctor visits and appointments\n- Health metrics (weight, blood pressure, etc)"
}
```
</CodeGroup>
4 changes: 3 additions & 1 deletion docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"platform/quickstart",
{
"group": "Features",
"pages": ["features/selective-memory", "features/custom-categories", "features/direct-import", "features/async-client", "features/memory-export"]
"pages": ["features/selective-memory", "features/custom-categories", "features/custom-instructions", "features/direct-import", "features/async-client", "features/memory-export"]
},
"features/langchain-tools"
]
Expand Down Expand Up @@ -197,6 +197,8 @@
"api-reference/project/get-project",
"api-reference/project/create-project",
"api-reference/project/delete-project",
"api-reference/project/get-instructions-and-categories",
"api-reference/project/update-instructions-and-categories",
{
"group": "Members APIs",
"pages":[
Expand Down
Loading

0 comments on commit 7f0d766

Please sign in to comment.