Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom prompt override in memory.add function #1998

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: add documentation for prompt parameter in memory.add function
Zncl2222 committed Jan 12, 2025
commit 52494efb582e03d1ed0a74bdcbbc9993e078b9fe
17 changes: 17 additions & 0 deletions docs/features/custom-prompts.mdx
Original file line number Diff line number Diff line change
@@ -107,3 +107,20 @@ m.add("I like going to hikes", user_id="alice")
}
```
</CodeGroup>


## Customizing Prompts per Memory Addition

In addition to setting a default prompt in the configuration, you can also override prompts for individual memory entries by using the prompt and graph_prompt parameters in m.add(). This allows you to tailor specific entries without changing the overall configuration.

For example, to add a memory with a custom prompt:

```python Code
m.add("Yesterday, I ordered a laptop, the order id is 12345", user_id="alice", prompt=custom_prompt)
```

You can also use graph_prompt to customize the prompt specifically for graph memory entries:

```python Code
m.add("Yesterday, I ordered a laptop, the order id is 12345", user_id="alice", graph_prompt=graph_prompt)
```
6 changes: 6 additions & 0 deletions docs/open-source/graph_memory/features.mdx
Original file line number Diff line number Diff line change
@@ -33,6 +33,12 @@ config = {
m = Memory.from_config(config_dict=config)
```

You can also **override prompts** for individual memory additions by using the `graph_prompt` parameter in `m.add()`

```python Code
m.add("Yesterday, I ordered a laptop, the order id is 12345", user_id="alice", graph_prompt=graph_prompt)
```

If you want to use a managed version of Mem0, please check out [Mem0](https://mem0.dev/pd). If you have any questions, please feel free to reach out to us using one of the following methods:

<Snippet file="get-help.mdx" />
2 changes: 1 addition & 1 deletion mem0/memory/main.py
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ def add(
metadata (dict, optional): Metadata to store with the memory. Defaults to None.
filters (dict, optional): Filters to apply to the search. Defaults to None.
prompt (str, optional): Prompt to use for memory deduction. Defaults to None.
prompt (str, optional): Prompt to use for graph memory deduction. Defaults to None.
graph_prompt (str, optional): Prompt to use for graph memory deduction. Defaults to None.

Returns:
dict: A dictionary containing the result of the memory addition operation.