Coding Quickstart
Familiarize yourself with Zep and the Zep Python SDK, culminating in building a simple chatbot.
For an introduction to Zep’s memory layer, Knowledge Graph, and other key concepts, see the Concepts Guide.
A Jupyter notebook version of this guide is available here.
In this guide, we’ll walk through a simple example of how to use Zep Cloud to build a chatbot. We’re going to upload a number of datasets to Zep, building a graph of data about a user.
Then we’ll use the Zep Python SDK to retrieve and search the data.
Finally, we’ll build a simple chatbot that uses Zep to retrieve and search data to respond to a user.
Set up your environment
-
Sign up for a Zep Cloud account.
-
Ensure you install required dependencies into your Python environment before running this notebook. See Installing Zep SDKs for more information. Optionally create your environment in a
virtualenv
.
- Ensure that you have a
.env
file in your working directory that includes yourZEP_API_KEY
andOPENAI_API_KEY
:
Zep API keys are specific to a project. You can create multiple keys for a
single project. Visit Project Settings
in the Zep dashboard to manage your
API keys.
Create User and add a Session
Users in Zep may have one or more chat sessions. These are threads of messages between the user and an agent.
Include the user’s full name and email address when creating a user. This improves Zep’s ability to associate data, such as emails or documents, with a user.
Datasets
We’re going to upload an assortment of data to Zep. These include past dialog with the agent, CRM support cases, and billing data.
Wait a minute or two!
We’ve batch uploaded a number of datasets that need to be ingested into Zep’s graph before they can be queried. In ordinary operation, this data would stream into Zep and ingestion latency would be negligible.
Retrieve data from Zep
We’ll start with getting a list of facts. We’ll see the temporal data associated with facts as well as the graph nodes the fact is related to.
The high-level memory
API provides an easy way to retrieve memory relevant to the current conversation by using the last 4 messages and their proximity to the User node.
The memory.get
method is a good starting point for retrieving relevant conversation context. It shortcuts passing recent messages to the graph.search
API and returns a context string, raw facts, and historical chat messages, providing everything needed for your agent’s prompts.
We can also use the graph.search
method to search facts for arbitrary text. This API offers more options, including the ability to search node summaries and various re-rankers.
Creating a simple Chatbot
In the next cells, Emily starts a new chat session with a support agent and complains that she can’t log in. Our simple chatbot will, given relevant facts retrieved from Zep’s graph, respond accordingly.
Here, the support agent is provided with Emily’s billing information and account status, which Zep retrieves as most relevant to Emily’s login issue.
Let’s look at the raw facts Zep retrieved for the above memory.get
call.