Zep for Data Extraction (Video)

An end-to-end walkthrough demonstrating how to quickly and accurately extract data from chat histories stored in Zep.

Zep for Data Extraction (Video)
Looking for the source code for this example? Visit the Zep By Example repo.

Next Steps

  1. Learn more in the Zep Structured Data Guide.
  2. Sign up for Zep's Long-term Memory Service for AI Assistants.



Hi there - I'm Daniel, the founder of Zep. Today I'm going to demonstrate how to use Zep's structured data extraction features. Unlike your LLM provider's JSON mode, Zep extracts data from user dialog quickly and accurately, guaranteeing data field formatting and guarding against hallucination.


We start off by defining a model of the data we'd like to extract. Zep offers many field types for building your model, from text, date, to different number formats, phone, email, and zip code primitives.


Each field has a description detailing what should be extracted from the dialog.


The Regex field type is versatile, and can be used to create e-nums,


and even comma separated value fields.


Let's save a dialog between a user and an ecommerce bot into Zep's long-term memory store. The user mentions brand preferences, shoe size, their budget, and selects a shoe to purchase.


Let's review the model again. We'll be extracting data in the dialog for each of the fields. We'll also be telling Zep how many of the most recent messages it should pass to the extractor to populate the model.


Let's run our first extraction. We're passing in our model, the last n just discussed, and the current date and time in the user's timezone. I'll speak to this in more depth a little later.


That completed in less than 500 milliseconds when accounting for overhead. Far faster than using an LLM provider such as OpenAI.


Note that fields where there is no data in the dialog context have not been hallucinated. They're not set.


If we have the user provide their email address and run the extraction again, the model is updated. As mentioned, Zep guarantees the format of email and similar fields. Note that we've also inferred the user's first name from the email address.


Let's pause and take a quick look at this merge_models function. Each extraction call returns a new model with data extracted from the LAST N trailing window of messages. We won't be able to extract data from messages prior to this window. If we run extraction on every chat turn, we'll want to merge newly extracted model values with the model from a prior extraction. This little helper function does just this.


We'll add several additional messages with new information, and watch as the model is populated with this new data.


Lastly, let's look at Zep's relative and partial date support. I mentioned earlier that we pass in to the extractor the user's current date and time. If the user or assistant mentions a relative or partial date, such as "tomorrow at 1pm", Zep understands this, and provides us with the value in Python Datetime format.


I've walked you through using Zep for low-latency and accurate data extraction. We used Python for this example. Zep's TypeScript SDK also offers the same functionality.