Declare an ontology with Python classes again - #345
Merged
Conversation
set_ontology takes lists of EntityType and EdgeType, so building an ontology by hand means repeating every property's name, type and description as data. v3 let a caller declare it once as Pydantic classes and derived the payload; that layer targeted v3 types and was dropped when this branch moved to generated output. Adds zep_cloud.ontology: annotate model fields with EntityText, EntityInt, EntityFloat or EntityBoolean, and build_ontology returns the two lists to hand to graph.set_ontology or project.set_ontology. Two differences from the v3 layer, both deliberate. It is a function rather than a client subclass: the generated clients expose sub-clients as read-only properties and already define set_ontology, so subclassing collided with both, and a function needs one frozen file instead of five. And the property type comes off an annotation marker rather than a JSON-schema round trip, which is shorter and keeps the wire spelling in one place. An unannotated field is an error naming the field, rather than being dropped: silently omitting a declared property would ship an ontology missing part of what the caller wrote. Also drops two stale .fern/replay entries from .fernignore. The lock file was removed when Replay was reset, and Fern owns that state.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
set_ontologytakes lists ofEntityTypeandEdgeType, so building an ontology by hand means repeating every property's name, type and description as data. Earlier SDK versions let you declare it once as Pydantic classes and derived the payload; that layer targeted the old types and was dropped when this branch moved to generated output.Usage
The same output goes to
client.project.set_ontologyfor the project default. The class docstring becomes the type description; a field'sdescriptionbecomes the property description.Two deliberate differences from the old layer
A function, not a client subclass. The generated clients expose sub-clients as read-only properties and already define
set_ontology, so subclassing collided with both. A function also means one hand-written file to preserve instead of five.The property type comes off an annotation marker, not a JSON-schema round trip. Shorter, and it keeps the wire spelling in a single place — which matters because the generated
EntityPropertyTypeis aLiteralunion rather than an enum, so there are no members to reference.Behavior worth noting
An unannotated field raises, naming the field:
Silently dropping it would ship an ontology missing a property the caller declared.
Verification
mypyclean across 168 files; 7 new tests covering type derivation, each annotation's wire value, field descriptions, source targets present and absent, the unannotated-field error, and empty input.Adds
src/zep_cloud/ontology.pyandtests/ontology/to.fernignore— everything it builds on (EntityType,EdgeType,EntityProperty) stays generated. Also drops two stale.fern/replayentries whose file no longer exists.