Search Over Memory Artifacts

Find relevant Facts or individual Messages across a Session, User, or more.

Searching for Facts or Messages

Zep offers similarity search over Facts and Messages stored within a Session, select Sessions, across all Sessions of a User, or across your entire Zep Project. This enables you to populate prompts with past conversations and conversation artifacts that are contextually similar to a specific query, organizing the results by a similarity Score.

Choosing Between Facts and Messages

Zep supports searching over Facts and Messages. Since individual messages might have little contextual information (consider a message containing just “yes”), Facts typically yield higher quality search results.

Constructing Search Queries

Zep’s Collection and Memory search support semantic search queries, JSONPath-based metadata filters, and a combination of both.

Memory search also supports querying by message creation date.

Read more about constructing search queries.

1from zep_cloud.client import AsyncZep
2
3client = AsyncZep(
4 api_key=API_KEY,
5)
6
7# This uniquely identifies the user's session
8session_id = "my_session_id"
9data = await client.memory.search_sessions(
10 session_ids=[session_id],
11 text="Is Lauren Olamina a character in a book?",
12 search_scope="facts", # This could be facts or messages
13 search_type="mmr", # remove this if you'd prefer not to rerank results
14 mmr_lambda=0.5, # tune diversity vs relevance
15)
16
17for search_result in data.results:
18 print(search_result.message.dict())
19
20data = await client.memory.search_sessions(
21 session_ids=[session_id],
22 text="Is Lauren Olamina a character in a book?",
23 search_scope="facts", // This could be facts or messages
24 search_type="mmr", # remove this if you'd prefer not to rerank results
25 mmr_lambda=0.5, # tune diversity vs relevance
26)

Hybrid Search for Chat History with Metadata Filters

Besides the vector similarity search for Facts and Messages stored in Zep, you can also use metadata filters for your searches. You also have the option to conduct searches based purely on metadata.

1client.memory.search_sessions(
2 session_ids=[session_id],
3 text="I enjoy reading science fiction.",
4 record_filter={
5 "where": {"jsonpath": '$[*] ? (@.foo == "bar")'},
6 },
7)
1{
2 "dist": 0.7170433826192629,
3 "message": {
4 "content": "I've read many books written by Octavia Butler.",
5 "created_at": "2023-06-03T22:00:43.034056Z",
6 "metadata": {
7 "foo": "bar",
8 "system": {
9 "entities": [
10 {
11 "Label": "PERSON",
12 "Matches": [
13 {
14 "End": 46,
15 "Start": 32,
16 "Text": "Octavia Butler"
17 }
18 ],
19 "Name": "Octavia Butler"
20 }
21 ]
22 }
23 },
24 "role": "human",
25 "token_count": 13,
26 "uuid": "8f3a06dd-0625-41da-a2af-b549f2056b3f"
27 },
28 "metadata": null,
29}