# Schema
This note covers `src/schema/*`.
## Why the schema exists
The schema is the contract that turns human-readable names into compact runtime ids and physical byte offsets. Without it, the engine would need string lookups and dynamic shape inspection on the hot path.
## `AttrType`
**Defined in:** `src/schema/attr.rs`
The type tag for one attribute slot.
### Variants
- `Int`
- `F32`
- `F64`
- `EnumStr`
- `RawStr`
- `IntArr`
- `F32Arr`
- `EnumStrArr`
### Key methods
- `slot_width()`
- `slot_align()`
### Why it matters
This enum drives both validation and physical layout.
## `Value<'a>`
**Defined in:** `src/schema/attr.rs`
The borrowed event-time representation of an attribute value.
### Variants
- `Int(i64)`
- `F32(f32)`
- `F64(f64)`
- `Str(&str)`
- `EnumCode(u32)`
- `IntArr(&[i64])`
- `F32Arr(&[f32])`
- `StrArr(&[&str])`
### Role
Used inside [[Modules/Events#AttrSet]] for updates and trigger payloads.
## `OwnedValue`
**Defined in:** `src/schema/attr.rs`
The owned counterpart to [[#Value]].
### Role
Used by [[Modules/Location State#LocationDef]] so reference data can outlive the request that supplied it.
## `SchemaBuilder`
**Defined in:** `src/schema/builder.rs`
The mutable builder used before startup completes.
### Important methods
- `new()`
- `kind(name, attrs)`
- `enum_value(s)`
- `build()`
### Main responsibility
Collect kind declarations, attr declarations, and value-interning state; then freeze all of that into a [[#Schema]].
## `ValueInterner`
**Defined in:** `src/schema/builder.rs`
A specialized value-level string interner returning `u32` codes.
### Role
This is separate from attr-name and kind-name interning so the id spaces stay conceptually distinct.
### Important methods
- `intern`
- `get`
- `lookup`
- `len`
## `Interner<Id>`
**Defined in:** `src/schema/interner.rs`
A generic string interner used for kind names and attribute names.
### Internal model
- `table: Vec<String>` for reverse lookup
- `index: AHashMap<String, u32>` for dedupe and forward lookup
### Why it matters
This is what makes `KindRef::Name("audience")` resolvable to `KindId(0)`.
## `Slot`
**Defined in:** `src/schema/layout.rs`
The physical placement of one attribute slot.
### Fields
- `offset: u32`
- `ty: AttrType`
### Meaning
`offset` is always relative to the beginning of the location's scalar buffer.
## `KindLayout`
**Defined in:** `src/schema/layout.rs`
The layout block for one kind.
### Fields
- `region_start`
- `region_len`
- `slots: Vec<Slot>`
- `attr_index: AHashMap<AttrId, usize>`
### Why it matters
This preserves declaration order while still allowing attr-id lookup inside a kind.
## `SlotLayout`
**Defined in:** `src/schema/layout.rs`
The full layout across all kinds.
### Fields
- `kinds: Vec<KindLayout>`
- `total_bytes: u32`
### Important method
- `resolve(kind, attr) -> Option<Slot>`
### Why it matters
Every update and every predicate slot-reference compilation goes through this mapping.
## `Schema`
**Defined in:** `src/schema/schema.rs`
The immutable, shared runtime schema.
### Fields
- `kind_names: Interner<KindId>`
- `attr_names: Interner<AttrId>`
- `value_interner: ValueInterner`
- `slot_layout: SlotLayout`
### Important methods
- `kind(name)`
- `attr(name)`
- `kind_name(id)`
- `attr_name(id)`
### Architectural importance
This type is the source of truth for:
- semantic names,
- runtime ids,
- memory layout,
- categorical value coding.
## Constants and guards
### `MAX_EMBEDDING_DIM`
Defined in `src/schema/attr.rs`.
A hard guardrail limiting `F32Arr` size to 512 for update-time writes and vector target registration.
## Practical summary
The schema subsystem does four jobs at once:
1. validates names,
2. interns names,
3. determines storage types,
4. assigns byte offsets.
Everything else in the crate depends on that frozen contract.