Customizing Graph Structure
Zep enables the use of rich, domain-specific data structures in graphs through Entity Types and Edge Types, replacing generic graph nodes and edges with detailed models.
Zep classifies newly created nodes/edges as one of the default or custom types or leaves them unclassified. For example, a node representing a preference is classified as a Preference node, and attributes specific to that type are automatically populated. You may restrict graph queries to nodes/edges of a specific type, such as Preference.
The default entity types are applied to all graphs by default, but you may define additional custom types as needed.
Each node/edge is classified as a single type only. Multiple classifications are not supported.
Default Entity Types
Definition
The default entity types are:
- User: A human that is part of the current chat thread.
- Preference: One of the User’s preferences.
- Procedure: A multi-step instruction informing the agent how to behave (e.g. ‘When the user asks for code, respond only with code snippets followed by a bullet point explanation’)
Default entity types only apply to user graphs (not group graphs). All nodes in any user graph will be classified into one of these types or none.
Adding Data
When we add data to the graph, default entity types are automatically created:
Searching
When searching nodes in the graph, you may provide a list of types to filter the search by. The provided types are ORed together. Search results will only include nodes that satisfy one of the provided types:
Custom Entity Types
Definition
In addition to the default entity types, you may specify your own custom entity types. You need to provide a description of the type and a description for each of the fields. The syntax for this is different for each language.
You may not create more than 10 custom EntityModels
per project. Each model may have up to 10 fields.
When creating custom entity types, you may not use the following attribute names (including in Go struct tags), as they conflict with default node attributes: uuid
, name
, group_id
, name_embedding
, summary
, and created_at
.
Setting Entity Types
You can then set these as the custom entity types for your current Zep project:
Adding Data
Now, when you add data to the graph, new nodes are classified into exactly one of the overall set of entity types or none:
Searching/Retrieving
Now that a graph with custom entity types has been created, you may filter node search results by entity type. In this case, you are able to get a structured answer (an ApartmentComplex
object) to an open ended query (the apartment complex the user previously resided in) where the answer required fusing together the chat history and the JSON data:
The search filter ORs together the provided types, so search results will only include nodes that satisfy one of the provided types.
You can also retrieve all nodes of a specific type:
Important Notes/Tips
Some notes regarding custom entity types:
- The
set_entity_types
method overwrites any previously defined custom entity types, so the set of custom entity types is always the list of types provided in the lastset_entity_types
method call - The overall set of entity types for a project includes both the custom entity types you set and the default entity types
- You can overwrite the default entity types by providing custom entity types with the same names
- Changing the custom entity types will not update previously created nodes. The classification and attributes of existing nodes will stay the same. The only thing that can change existing classifications or attributes is adding data that provides new information.
- When creating custom entity types, avoid using the following attribute names (including in Go struct tags), as they conflict with default node attributes:
uuid
,name
,group_id
,name_embedding
,summary
, andcreated_at
- Tip: Design custom entity types to represent entities/nouns as opposed to relationships/verbs. Your type might be represented in the graph as an edge more often than as a node
- Tip: If you have overlapping entity types (e.g. ‘Hobby’ and ‘Hiking’), you can prioritize one type over another by mentioning which to prioritize in the entity type descriptions
Custom Edge Types
Definition
In addition to custom entity types, you may specify your own custom edge types to represent types of facts/relationships as opposed to types of entities. Each custom edge type requires a description and a definition for each field. The syntax for defining edge types is different for each language.
You may not create more than 10 custom edge types per project. Each model may have up to 10 fields.
When creating custom edge types, you may not use the following attribute names (including in Go struct tags), as they conflict with default edge attributes: uuid
, name
, group_id
, name_embedding
, summary
, and created_at
.
Setting Edge Types
After defining your custom edge types, set them using the appropriate SDK method. This overwrites any previously defined custom edge types, so the set of edge types is always the list provided in the last set operation.
Note that you can require an edge type to have a source entity of a specific type and/or a target entity of a specific type. This ensures that an edge can only be classified as this edge type if it is between entities of the specified types. If a source/target entity type is not specified, then any entity is allowed for the source/target.
Adding Data
When you add data to the graph, edges are classified into exactly one of the overall set of edge types or none.
Searching/Retrieving
You may filter edge search results by edge type. This enables you to retrieve only those edges that match a specific type.
Important Notes/Tips
Some notes regarding custom edge types:
- The
set_entity_types
method overwrites any previously defined custom edge types, so the set of custom edge types is always the list of types provided in the lastset_entity_types
method call - There are no default edge types
- Changing the custom edge types will not update previously created edges. The classification and attributes of existing edges will stay the same. The only thing that can change existing classifications or attributes is adding data that provides new information.
- When creating custom edge types, avoid using the following attribute names (including in Go struct tags), as they conflict with default edge attributes:
uuid
,name
,group_id
,name_embedding
,summary
, andcreated_at
- Tip: Design custom edge types to represent relationships/verbs as opposed to entities/nouns. Your type might be represented in the graph as an edge more often than as a node
- Tip: If you have overlapping edge types (e.g. ‘NavigatesToRestaurant’ and ‘NavigatesToLocation’), you can prioritize one type over another by mentioning which to prioritize in the edge type descriptions