Facts
Facts are extracted from the Chat History as a conversation unfolds.
Facts are observations about a user and their interaction with your Assistant. They are derived from user interactions, such as chat history, and business data added to Zep.
Zep autonomously builds a knowledge graph from user interaction and business data while handling changing relationships and maintaining historical context. Zep generates facts from relationships identified in the graph. As Zep incorporates new information, outdated facts are marked as invalid. Retaining a history of facts enables agents to reason with changing user state.
Zep supports two APIs for adding data:
- The Memory API which supports adding structured chat messages.
- The Graph Add Data API which supports adding messages, text, or JSON data.
How Fact Retrieval Works
Relevant Facts can be retrieved via a Memory call, the Search API, or the Graph Search API.
When using the Memory API
to retrieve relevant Facts, the most recent messages in the Chat History are used to retrieve relevant facts. These facts are then reranked by graph distance from the user and returned.
The other two APIs will return graph edges, which contain an edge.fact
field as the relevant fact.
Rating Facts for Relevancy
Available to Subscription customers only.
Currently only supported for Legacy Fact-enabled accounts, and not accounts migrated to Zep’s new graph-based memory. We expect to add this feature to the new memory in the coming weeks.
Not all Facts are relevant to your application and users. For example, a realtionship coach app may need to recall important facts about a user’s family, but what the user ate for breakfast Friday last week is unimportant.
Fact Ratings are a way to help Zep understand the relevance of a Fact to your particular use case. After implementing Fact Ratings, you can specify a minimum rating when retrieving Facts from Zep, ensuring that prompt only contains high-signal context.
Implementing Fact Ratings
A Fact Rating framework consist of an Instruction and three example Facts, one for each of a “High”, “Medium”, and “Low” rating. This is passed into a Session
on creation.
Rating Facts for Poignancy
Use Case-Specific Fact Rating
Facts are rated on a scale between 0 and 1. You can review ratings for a Session by visiting the web app or retrieving all Facts for a Session.
Limiting Memory Recall to High-Rating Facts
Zep automatically returns relevant Facts when retrieving Memory. You can limit the returned Facts by Rating when setting the min_rating
parameter in the get
method.
It’s also possible to filter search results by Fact Rating by setting the min_fact_rating
parameter when searching Sessions.
Adding additional data to the graph
You can add additional data to the graph using the Add Data API. This can be used to add additional relevant business data that may not be present in the Chat History.
Unlike RAG, where documents in a vector index are static, facts extracted from data you add to a Session will be curated as the conversation with the user progresses. They may be updated, merged into new Facts, or invalidated as new information is learned from the user.
Creating Facts
Creating facts is deprecated and will not work with graph-based facts. Please use the Add Data API to add data to the graph instead.
You may have information about your user that would be helpful context when prompting an LLM. You can generate textual facts from this data and persist these to a Session. The data will be returned if relevant to the current conversation, alongside other facts gleaned from the Chat History.
Unlike RAG, where documents in a vector index are static, Facts you add to a Session will be curated as the conversation with the user progresses. They may be updated, merged into new Facts, or deleted as new information is learned from the user.
Python
TypeScript
Deleting Facts
You or your users may want to remove a fact from Zep’s memory. You can do this by deleting a fact by Fact UUID
.
Customizing Fact Generation
Available to Enterprise Plan customers only.
Customizing fact generation is deprecated and will not work with graph-based facts. We will be replacing this feature with new graph-native capabilities in the coming months. Contact us for more information.
You can customize the contents and format of facts by providing Custom Instructions when persisting a Memory to a Session.
Retrieving Facts
Facts are added to Memory responses when you retrieve a Session’s Memory. They’re also accessible the Search API and lower-level Session API and Graph Search API.