Adding Data to the Graph

Adding Data to the Graph

Each subscription tier has different limits on the amount of data that can be added to the graph (see here).

In addition to incorporating memory through chat history, Zep offers the capability to add data directly to the graph. Zep supports three distinct data types: message, text, and JSON.

The message type is ideal for adding data in the form of chat messages that are not directly associated with a Zep Session’s chat history. This encompasses any communication with a designated speaker, such as emails or previous chat logs.

The text type is designed for raw text data without a specific speaker attribution. This category includes content from internal documents, wiki articles, or company handbooks. It’s important to note that Zep does not process text directly from links or files.

The JSON type may be used to add any JSON document to Zep. This may include REST API responses or JSON-formatted business data.

The graph.add endpoint has a data size limit of 10,000 characters.

You can add data to either a user graph by providing a user_id, or to a group graph by specifying a group_id.

Here’s an example demonstrating how to add message data to the graph:

1from zep_cloud.client import AsyncZep
2
3client = AsyncZep(
4 api_key=API_KEY,
5)
6
7message = "Paul (user): I went to Eric Clapton concert last night"
8
9await client.graph.add(
10 user_id="user123", # Optional user ID
11 type="message", # Specify type as "message"
12 data=message
13)

Here’s an example demonstrating how to add text data to the graph:

1from zep_cloud.client import AsyncZep
2
3client = AsyncZep(
4 api_key=API_KEY,
5)
6
7await client.graph.add(
8 user_id="user123", # Optional user ID
9 type="text", # Specify type as "text"
10 data="The user is an avid fan of Eric Clapton"
11)

Here’s an example demonstrating how to add JSON data to the graph:

1from zep_cloud.client import AsyncZep
2
3client = AsyncZep(
4 api_key=API_KEY,
5)
6
7json_data = {"name": "Eric Clapton", "age": 78, "genre": "Rock"}
8json_string = json.dumps(json_data)
9await client.graph.add(
10 user_id=user_id,
11 type="json",
12 data=json_string,
13)
Built with