Omnigraph
Schema

Schema

A .pg file defines your graph's structure. The node types, edge types, interfaces, and constraints that the query engine enforces.

Every Omnigraph graph starts with a schema. The schema is a single .pg file that declares what kinds of entities and relationships exist in your graph, what properties they carry, and what rules apply to the data.

What a .pg file looks like

// Line comments use //, and /* block comments */ are also accepted.

node Person {
    name: String @key
    age:  I32?
}

node Company {
    name: String @key
}

edge Knows: Person -> Person {
    since: Date?
}

edge WorksAt: Person -> Company

Type names must begin with an uppercase ASCII letter (Person, WorksAt). Property names, parameter names, and other identifiers must begin with a lowercase ASCII letter or _. Property declarations must be on separate lines inside the body. Comma-separated single-line bodies are a parse error.

The three declaration kinds

KeywordPurpose
nodeA vertex type with typed properties
edgeA directed relationship between two node types
interfaceA named set of properties that node types can implement

Every node and edge gets its own storage table. Interfaces are compile-time only.

What the schema drives

When Omnigraph opens a graph, it compiles the stored schema source into a catalog:

  1. Typecheck queries. Property references, traversal paths, and filter expressions are validated against the declared types.
  2. Create and validate storage. One data table is created per node type and per edge type.
  3. Enforce constraints, @range, @check, and edge cardinality annotations are checked at load and mutation time.
  4. Build indices, @index and @key annotations cause BTree (scalar), inverted (full-text), or ivf_flat (vector) indexes to be created.

On this page