Adding Data to the Graph
Overview
Requests to add data to the same graph are completed sequentially to ensure the graph is built correctly. A large number of calls to add data to the same graph may result in lengthy processing times.
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
.
Adding Message Data
Here’s an example demonstrating how to add message data to the graph:
Python
TypeScript
Adding Text Data
Here’s an example demonstrating how to add text data to the graph:
Python
TypeScript
Adding JSON Data
Here’s an example demonstrating how to add JSON data to the graph:
Python
TypeScript
Adding Custom Fact/Node Triplets
You can also add manually specified fact/node triplets to the graph. You need only specify the fact, the target node name, and the source node name. Zep will then create a new corresponding edge and nodes, or use an existing edge/nodes if they exist and seem to represent the same nodes or edge you send as input. And if this new fact invalidates an existing fact, it will mark the existing fact as invalid and add the new fact triplet.
Python
TypeScript
You can also specify the node summaries, edge temporal data, and UUIDs. See the associated SDK reference.
Managing Your Data on the Graph
The graph.add
method returns the episode that was created in the graph from adding that data. You can use this to maintain a mapping between your data and its corresponding episode in the graph and to delete specific data from the graph using the delete episode method.