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 and Edge Types
Definition
In addition to the default entity types, you may specify your own custom entity and custom edge 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 entity types and 10 custom edge types per project. The limit of 10 custom entity types does not include the default types. Each model may have up to 10 fields.
When creating custom entity or edge 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 and Edge Types
You can then set these custom entity and edge types as the graph ontology for your current Zep project. Note that for custom edge types, you can require the source and destination nodes to be a certain type, or allow them to be any type:
Adding Data
Now, when you add data to the graph, new nodes and edges are classified into exactly one of the overall set of entity or edge types respectively, or no type:
Searching/Retrieving
Now that a graph with custom entity and edge types has been created, you may filter node search results by entity type, or edge search results by edge type.
Below, you can see the examples that were created from our data of each of the entity and edge types that we defined:
Additionally, you can provide multiple types in search filters, and the types will be ORed together:
Important Notes/Tips
Some notes regarding custom entity and edge types:
- The
set_ontology
method overwrites any previously defined custom entity and edge types, so the set of custom entity and edge types is always the list of types provided in the lastset_ontology
method call - The overall set of entity types for a project includes both the custom entity types you set and the default entity types
- There are no default edge types
- You can overwrite the default entity types by providing custom entity types with the same names
- Changing the custom entity or edge types will not update previously created nodes or edges. The classification and attributes of existing nodes and 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 entity or edge types, avoid using the following attribute names (including in Go struct tags), as they conflict with default attributes:
uuid
,name
,group_id
,name_embedding
,summary
, andcreated_at
- Tip: Design custom entity types to represent entities/nouns, and design custom edge types to represent relationships/verbs. Otherwise, your type might be represented in the graph as an edge more often than as a node or vice versa.
- Tip: If you have overlapping entity or edge types (e.g. ‘Hobby’ and ‘Hiking’), you can prioritize one type over another by mentioning which to prioritize in the entity or edge type descriptions