To define custom entities and edges in the Zep ontology, you should subclass EntityModel or EdgeModel and use the provided annotated types for field properties. These annotated types ensure that your Python models are correctly serialized into the JSON schema format expected by the Zep API.
Supported Property Types
When defining fields, use these specific annotated types to ensure correct type mapping (Text, Int, Float, or Boolean):
EntityText: For string values.EntityInt: For integer values.EntityFloat: For floating-point values.EntityBoolean: For boolean values.
Conversion to API Schema
Once your models are defined, use entity_model_to_api_schema or edge_model_to_api_schema to convert your Pydantic models into the dictionary format required by the Zep API for EntityType or EntityEdge definitions.
from zep_cloud.external_clients.ontology import EntityModel, EdgeModel, EntityText, EntityInt
class UserEntity(EntityModel):
"""A representation of a user in the system"""
user_id: EntityText
age: EntityInt
class FollowsEdge(EdgeModel):
"""Represents a follow relationship between users"""
strength: EntityInt
# Convert to API-ready schema
user_schema = entity_model_to_api_schema(UserEntity, "User")
edge_schema = edge_model_to_api_schema(FollowsEdge, "Follows")