Skip to main content
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

Extend hb.Entity and declare typed fields. Use hb.field(...) when a field needs metadata, defaults, placement, or compute Hooks.
HeavenBase derives the identifier 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-facing object_id. If it is omitted, HeavenBase derives a deterministic id from the row’s name.
Declare 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.
Compute callables are part of application behavior. Keep them deterministic, small, and importable when the schema must be reconstructed.

6. Build from JSON

Agents and external clients can create the same logical schema from a JSON-compatible mapping.
The generated class behaves like an ordinary 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.

Further Exploration

Related resources:
  • Workspace — Register schemas in an application boundary
  • Routing — Place fields on Backends
  • Query — Read and aggregate Entity rows
  • Catalog — Discover concrete objects after writes