An Entity gives data a passport before a Backend assigns it a hotel room.
1. Motivation
Applications need one durable description of what a row means. HeavenBase Entities keep that logical contract independent from physical storage, so the same schema can route across different Backends.2. Define a Logical Shape
Extendhb.Entity and declare typed fields.
Use hb.field(...) when a field needs metadata, defaults, placement, or compute Hooks.
document and injects the required object_id field when it is absent.
schema() returns a compiled EntitySchema; to_dict() and to_str() provide JSON-compatible and agent-readable views.
3. Choose Logical Types
Logical types describe meaning. Backends decide physical representation.
Use
Timestamp for instants and Date for calendar dates.
HeavenBase does not expose separate Datetime or Interval logical types.
4. Preserve Identity
Every Entity row has one user-facingobject_id.
If it is omitted, HeavenBase derives a deterministic id from the row’s name.
object_id explicitly when a different natural key should control identity.
Compute Hooks can derive that key from other fields.
5. Add Compute Hooks
Write-time compute Hooks derive stored values. Query-compute Hooks normalize a query value before routing, such as turning text into a vector.6. Build from JSON
Agents and external clients can create the same logical schema from a JSON-compatible mapping.hb.Entity subclass.
The same definition can also travel inside a workspace manifest.
Summary
- Entities define logical meaning and stable identity.
- Fields carry types, metadata, defaults, placement, and compute Hooks.
- Physical storage remains a routing concern.
- Python and JSON definitions compile to the same schema contract.

