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 repository 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
node Person {
name: String @key
age: I32?
}
node Company {
name: String @key
}
edge Knows: Person -> Person {
since: Date?
}
edge WorksAt: Person -> CompanyThe three declaration kinds
| Keyword | Purpose |
|---|---|
node | A vertex type with typed properties |
edge | A directed relationship between two node types |
interface | A 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 repository, it compiles _schema.pg into a catalog:
- Typecheck queries — property references, traversal paths, and filter expressions are validated against the declared types.
- Create and validate storage — one data table is created per node type and per edge type.
- Enforce constraints —
@range,@check, and edge cardinality annotations are checked at load and mutation time. - Build indices —
@indexand@keyannotations cause BTree, inverted (full-text), or IVF-HNSW (vector) indices to be created.