Entity Types
Zep enables the use of rich, domain-specific data structures through Entity Types, replacing generic graph nodes with detailed models. Zep classifies newly created nodes as one of the default or custom entity 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 of a specific type, such as Preference.
The default entity types are applied to all nodes by default, but you may define additional custom types as needed.
Each node is classified as a single entity type only. Multiple classifications are not supported.
Default Entity Types
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.
When we add data to the graph, default entity types are automatically created:
When searching nodes in the graph, you can 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
In addition to the default entity types, you can specify your own custom entity types. You need to provide a description of the type and a description for each of the fields. Note that the syntax for this is different for each language:
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
, and created_at
.
You can then set these as the custom entity types for your current Zep project:
Now, when we add data to the graph, new nodes are classified into exactly one of the overall set of entity types or none:
Now that we have created a graph with custom entity types, we can filter node search results by entity type. In this case, we 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