Schema
Schema defines the structure of interaction data. Before storing data, define how edges are structured, what properties they have, and how they can be queried.
See Core Concepts for background.
Schema Hierarchy
Section titled “Schema Hierarchy”Service (v3: Database)├── Label (v3: Table)│ ├── Schema (src, tgt, fields)│ └── Indices (v3: Indexes)└── Alias- Service groups related Labels and Aliases
- Label defines the schema for edges
- Alias provides an alternative name for a Label
Service (v3: Database)
Section titled “Service (v3: Database)”A namespace that contains labels and aliases.
| Property | Description |
|---|---|
| name | Service identifier (e.g., myservice) |
| desc | Description (v3: comment) |
| active | Whether active |
Example: an e-commerce service might contain labels for likes, recent_views, and purchases.
Label (v3: Table)
Section titled “Label (v3: Table)”Defines the schema for edges—src, tgt, fields, and indices.
| Property | Description |
|---|---|
| name | Format: service.label |
| desc | Description (v3: comment) |
| type | Label type (INDEXED, HASH, MULTI_EDGE) |
| schema | Edge structure (src, tgt, fields) |
| dirType | Direction type (v3: direction) |
| storage | Storage URI (e.g., datastore://<namespace>/<table>) |
| indices | Indices for querying (v3: indexes) |
| active | Whether active |
Schema Definition
Section titled “Schema Definition”- src (v3: source): source type (STRING, LONG) — who
- tgt (v3: target): target type (STRING, LONG) — what
- fields (v3: properties): each with name, type, nullable
Example: Recent Views
src: user_id (LONG)tgt: product_id (LONG)fields: - created_at (LONG)dirType: BOTHExample: Reactions
src: user_id (LONG)tgt: product_id (LONG)fields: - created_at (LONG) - reaction_type (STRING)dirType: BOTHIndex Definition
Section titled “Index Definition”Indices enable efficient querying. Each index has a name and a list of fields with sort order.
indices: - name: by_created_at fields: [created_at DESC] - name: by_type_and_time fields: [reaction_type ASC, created_at DESC]Indices are pre-computed at write time. See Query.
An alternative name for a label.
| Property | Description |
|---|---|
| name | Format: service.alias |
| desc | Description (v3: comment) |
| target | The label it points to |
| active | Whether active |
Useful for gradual migrations or domain-specific naming.
Naming Conventions
Section titled “Naming Conventions”| Type | Format | Example |
|---|---|---|
| Service | Simple identifier | myservice |
| Label | service.label | myservice.likes |
| Alias | service.alias | myservice.friends |
Schema Versions
Section titled “Schema Versions”v2 and v3 map almost 1:1.
| v2 (Current) | v3 (Future) |
|---|---|
| service | database |
| label | table |
| src | source |
| tgt | target |
| ts | version |
| fields | properties |
| dirType | direction |
| indices | indexes |
| desc | comment |
Next Steps
Section titled “Next Steps”- Mutation: Write data
- Query: Query data
- Metadata API: API reference