Working with Chat History
Learn how to persist, retrieve, and search chat history using Zep’s Memory API
You are viewing the Zep Open Source v0.x documentation. This version is no longer supported, and documentation is provided as a reference only.
The current documentation for Zep Community Edition is available here.
Zep’s Memory API persists your app’s chat history and metadata to a Session
, enriches the memory, and enables vector similarity search over historical chat messages.
There are two approaches to populating your prompt with chat history:
- Retrieve the most recent N messages (and potentially a summary) from a
Session
and use them to construct your prompt. - Search over the
Session
’s chat history for messages that are relevant and use them to construct your prompt.
Both of these approaches may be useful, with the first providing the LLM with context as to the most recent interactions with a human. The second approach enables you to look back further in the chat history and retrieve messages that are relevant to the current conversation in a token-efficient manner.
Initializing the Zep Client
Please see the SDK documentation for more information on initializing the Zep client.
Note:
zep-python
supports async use. All methods are available as both sync and async, with the async methods prefixed witha
. For example,zep-python
has bothzep_client.memory.add_memory
andzep_client.memory.aadd_memory
methods.
Next Steps
- Working with Users and Sessions
- Persisting and Retrieving Memories
- Searching over Memories with Hybrid Search
Zep’s Memory Enrichment
You’ve likely noticed that alongside the role and content you provided to Zep when persisting a memory, Zep also returns a unique identifier, a summary, UUID, a timestamp, token count, extracted entities, and more. The token count is a useful tool to use when constructing prompts, while the extracted entities and other metadata may be useful for building more sophisticated applications.
Zep performs auto-summarization when a session exceeds the message window. This is returned in the summary
field of the memory when you call get_memory
and may be used when constructing prompts in order to provide your agent or chain with a longer-term memory of the conversation. Read more about the Summarizer Extractor.
Zep also automatically extracts Entities from, and runs an Intent Analysis on, messages in the conversation. The extracted entities and intents are stored in system metadata and available for hybrid searches (see Hybrid Search above).