Working with Memory


Facts are extracted from the Chat History as a conversation unfolds.

What are Facts?

Facts are observations about a user and their interaction with your Assistant. They are derived from the Chat History as new Messages are added to a Session.

A Fact Table is continuously updated as the conversation unfolds. Facts are deconflicted and deduplicated, and the relationship between conflicting information is preserved.

A stylized example below:

Robbie only wears Nike shoes.Robbie used to only wear Nike shoes, but she now prefers Adidas.
Robbie’s Nikes fell apart, so she prefers Adidas.Robbie’s Nike shoes fell apart.

Rating Facts for Relevancy

Available to Subscription customers only.

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.

Adding spurious Facts to your prompt may result in the LLM hallucinating or exhibiting other undesired behavior.

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
1fact_rating_instruction = """Rate the facts by poignancy. Highly poignant
2facts have a significant emotional impact or relevance to the user.
3Low poignant facts are minimally relevant or of little emotional
5fact_rating_examples = FactRatingExamples(
6 high="The user received news of a family member's serious illness.",
7 medium="The user completed a challenging marathon.",
8 low="The user bought a new brand of toothpaste.",
10await zep.memory.add_session(
11 user_id=user_id,
12 session_id=session_id,
13 fact_rating_instruction=FactRatingInstruction(
14 instruction=fact_rating_instruction,
15 examples=fact_rating_examples,
16 ),

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.

Fact Ratings
Fact Ratings in the Zep Web App

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.

1result = await client.memory.get(session_id, min_rating=0.7)

It’s also possible to filter search results by Fact Rating by setting the min_fact_rating parameter when searching Sessions.

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.

You can customize the contents and format of facts by providing Custom Instructions when persisting a Memory to a Session.

1custom_instructions = """
2Focus on the user's family and friend relationships.
3Identify life goals and interests.
4Note any standout characteristics or traits about the user.
7result = await client.memory.add(
8 session_id,
9 messages=messages,
10 fact_instruction=custom_instructions

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.