Adding Memory
You can add both messages and business data to User Graphs.
Adding Messages
Add your chat history to Zep using the thread.add_messages
method. thread.add_messages
is thread-specific and expects data in chat message format, including a name
(e.g., user’s real name), role
(AI, human, tool), and message content
. Zep stores the chat history and builds a user-level knowledge graph from the messages.
For best results, add chat history to Zep on every chat turn. That is, add both the AI and human messages in a single operation and in the order that the messages were created.
The example below adds messages to Zep’s memory for the user in the given thread:
You can find additional arguments to thread.add_messages
in the SDK reference. Notably, for latency sensitive applications, you can set return_context
to true which will make thread.add_messages
return a context block in the way that thread.get_user_context
does (discussed below).
Ignore Assistant Messages
You can also pass in a list of roles to ignore when adding messages to a User Graph using the ignore_roles
argument. For example, you may not want assistant messages to be added to the user graph; providing the assistant messages in the thread.add_messages
call while setting ignore_roles
to include “assistant” will make it so that only the user messages are ingested into the graph, but the assistant messages are still used to contextualize the user messages. This is important in case the user message itself does not have enough context, such as the message “Yes.” Additionally, the assistant messages will still be added to the thread’s message history.
Adding Business Data
You can also add JSON or unstructured text as memory to a User Graph using our Graph API.
Customizing Memory Creation
Zep offers two ways to customize how memory is created. You can read more about these features at their guide pages:
- Custom entity and edge types: Feature allowing use of Pydantic-like classes to customize creation/retrieval of entities and relations in the knowledge graph.
- Fact ratings: Feature for rating and filtering facts by relevance to your use case.