Docs > Ontology and knowledge graph
Knowledge graph
# Knowledge graph Dex's **knowledge graph** is the live, permissioned representation of your workspace's people, companies, custom Objects, relationships, and interaction history. Rather than maintaining a disconnected graph database that drifts from structured tables, Dex projects the knowledge graph directly over your workspace's typed Postgres Object tables (`zeta_store`), relationship links, and provenance-backed observations. Every read—whether in [Nexus](/context/nexus/), via `dex zeta`, or through Agent SQL—enforces the same row-level security rules. ## Nodes and edges | Graph element | Where it comes from | Example | | --- | --- | --- | | **Nodes** | Materialized **Object records** defined by your [ontology](/context/ontology/) | `person` ("Maya Chen"), `company` ("Acme Corp"), `commitment` ("Send SOC 2 pack") | | **Typed relationship edges** | Explicit `link` fields (`manyOne`, `oneMany`, `manyMany`) between Object types | `Maya Chen --company--> Acme Corp`; `Renewal Q4 --contacts--> [Maya Chen, Sam Lee]` | | **Co-occurrence / activity edges** | Records that appear together in the same synced or manual **observation** | Two people and a company co-occurring in the same Slack thread, email, or meeting note | When a sync encounters a reference pointing to an entity that has not been synced yet, Dex stores a **pending reference** and automatically links the records once the target identity arrives. ## Identity resolution and explicit merges As synced Datasets feed into Object mappings, Dex resolves records deterministically using the mapping's `cluster.keys`: - **Cross-source merging (`scopedBy: "scope"`)** — Rows from Gmail, Slack, and Attio that normalize to the same cluster key (such as `maya@acme.com`) fold into one `person` record inside that output Data Scope, combining fields by mapping priority. - **Per-connection isolation (`scopedBy: "connection"`)** — Keys that are unique only within a single tool stay partitioned per provider connection. - **Fail-closed on collisions** — If one incoming source row asserts keys that already belong to two distinct records, Dex **refuses to silently auto-merge** them and records a mapping error (`sync_error`) for review. - **Explicit merging with aliases** — When you intentionally merge duplicate records (`dex zeta records merge` or in Nexus), Dex consolidates sources and identities onto the surviving record, trashes the duplicate, and records a **record alias** so existing references and old record UUIDs continue to resolve cleanly. ## Manual edits, history, and trash Synced records are not read-only. Both people and authorized agents can update fields on synced or manual records: - **Manual edits win over syncs.** Editing a cell records a `cell_edit` entry; future sync recomputations skip hand-edited cells so your corrections are never overwritten. Resetting a cell restores automatic synced folding. - **Full audit trail.** Record mutations log to `record_history` with their origin (`user`, `agent`, `sync`, `merge`, or `system`). - **Safe deletion.** Deleting a record snapshots it into trash (`record_trash`, restorable via `dex zeta records restore`) and marks synced source links as suppressed so the next sync pass does not resurrect a record you deleted. ## Querying the knowledge graph Agents and users can query the knowledge graph in three ways: ### 1. Structured record queries (`dex zeta records`) Filter, search, page (up to 1,000 rows per page), aggregate, and inspect full provenance context: ```bash # Inspect an Object's fields and supported filter operators dex zeta objects get --object person # Query with typed filters and aggregations dex zeta records list --object commitment --filter '{"status":{"eq":"Open"}}' --limit 100 dex zeta records aggregate --object deal --group-by stage # Inspect a record's source rows, evidence, and linked timeline events dex zeta records context --object person --id <record-id> ``` When creating or updating records with loose inputs (such as `"yes"`, formatted dates, select choice labels, or a linked record's title), pass `--typecast` so Dex coerces values to each field's schema. ### 2. Read-only Agent SQL (`dex zeta sql`) For joins, counts, cohort comparisons, and multi-object analytics, Dex exposes a sandboxed read-only SQL interface over your workspace's Object views (`o_<object>`) and Dataset views (`d_<dataset>`): ```bash # Discover available views and lowercased column names first dex zeta sql schema # Run a single read-only SELECT (joins use <link_field>_id or <link_field>_ids) dex zeta sql query " SELECT c.name AS company, COUNT(p.id) AS contacts FROM o_person p JOIN o_company c ON p.company_id = c.id GROUP BY c.name ORDER BY contacts DESC " ``` Security and runtime guarantees on Agent SQL: - Parsed with a Postgres AST validator (`libpg-query`): allows only a single `SELECT` over allowlisted workspace `o_*` and `d_*` views and safe SQL functions. - Executes inside a read-only transaction (`SET LOCAL transaction_read_only = on`) under a dedicated `NOLOGIN` workspace SQL role with caller RLS claims applied—every row is filtered to what the calling user is allowed to read. - Protected by a 10-second statement timeout and a 10,000-row / 5 MB response cap (1,000 rows by default; `truncated: true` signals you should aggregate or narrow the query). ### 3. Saved Views (`dex views`) When a recurring question needs a stable definition shared across people and agents, define a saved [View](/context/nexus/#views) (`views/*.md`) and query it with `dex views query <id>`. ## Related pages - [Ontology](/context/ontology/) - Define the Object types, link fields, and mappings behind the graph - [Nexus](/context/nexus/) - Visualize the graph in Force, Constellation, and Spatial modes - [Records, observations, and timeline](/context/records-and-timeline/) - Provenance, manual notes, and timeline windowing - [Sources and data scopes](/context/sources-and-scopes/) - Row-level permissions and Data Scopes - [Knowledge and memory](/agents/knowledge/) - When to use Knowledge files instead of the knowledge graphUnderstand how Dex materializes Object records, typed links, co-occurrence edges, identity resolution, manual edits, and read-only Agent SQL.
Dex’s knowledge graph is the live, permissioned representation of your workspace’s people, companies, custom Objects, relationships, and interaction history.
Rather than maintaining a disconnected graph database that drifts from structured tables, Dex projects the knowledge graph directly over your workspace’s typed Postgres Object tables (zeta_store), relationship links, and provenance-backed observations. Every read—whether in Nexus, via dex zeta, or through Agent SQL—enforces the same row-level security rules.
Nodes and edges
Section titled “Nodes and edges”| Graph element | Where it comes from | Example |
|---|---|---|
| Nodes | Materialized Object records defined by your ontology | person (“Maya Chen”), company (“Acme Corp”), commitment (“Send SOC 2 pack”) |
| Typed relationship edges | Explicit link fields (manyOne, oneMany, manyMany) between Object types | Maya Chen --company--> Acme Corp; Renewal Q4 --contacts--> [Maya Chen, Sam Lee] |
| Co-occurrence / activity edges | Records that appear together in the same synced or manual observation | Two people and a company co-occurring in the same Slack thread, email, or meeting note |
When a sync encounters a reference pointing to an entity that has not been synced yet, Dex stores a pending reference and automatically links the records once the target identity arrives.
Identity resolution and explicit merges
Section titled “Identity resolution and explicit merges”As synced Datasets feed into Object mappings, Dex resolves records deterministically using the mapping’s cluster.keys:
- Cross-source merging (
scopedBy: "scope") — Rows from Gmail, Slack, and Attio that normalize to the same cluster key (such asmaya@acme.com) fold into onepersonrecord inside that output Data Scope, combining fields by mapping priority. - Per-connection isolation (
scopedBy: "connection") — Keys that are unique only within a single tool stay partitioned per provider connection. - Fail-closed on collisions — If one incoming source row asserts keys that already belong to two distinct records, Dex refuses to silently auto-merge them and records a mapping error (
sync_error) for review. - Explicit merging with aliases — When you intentionally merge duplicate records (
dex zeta records mergeor in Nexus), Dex consolidates sources and identities onto the surviving record, trashes the duplicate, and records a record alias so existing references and old record UUIDs continue to resolve cleanly.
Manual edits, history, and trash
Section titled “Manual edits, history, and trash”Synced records are not read-only. Both people and authorized agents can update fields on synced or manual records:
- Manual edits win over syncs. Editing a cell records a
cell_editentry; future sync recomputations skip hand-edited cells so your corrections are never overwritten. Resetting a cell restores automatic synced folding. - Full audit trail. Record mutations log to
record_historywith their origin (user,agent,sync,merge, orsystem). - Safe deletion. Deleting a record snapshots it into trash (
record_trash, restorable viadex zeta records restore) and marks synced source links as suppressed so the next sync pass does not resurrect a record you deleted.
Querying the knowledge graph
Section titled “Querying the knowledge graph”Agents and users can query the knowledge graph in three ways:
1. Structured record queries (dex zeta records)
Section titled “1. Structured record queries (dex zeta records)”Filter, search, page (up to 1,000 rows per page), aggregate, and inspect full provenance context:
# Inspect an Object's fields and supported filter operatorsdex zeta objects get --object person
# Query with typed filters and aggregationsdex zeta records list --object commitment --filter '{"status":{"eq":"Open"}}' --limit 100dex zeta records aggregate --object deal --group-by stage
# Inspect a record's source rows, evidence, and linked timeline eventsdex zeta records context --object person --id <record-id>When creating or updating records with loose inputs (such as "yes", formatted dates, select choice labels, or a linked record’s title), pass --typecast so Dex coerces values to each field’s schema.
2. Read-only Agent SQL (dex zeta sql)
Section titled “2. Read-only Agent SQL (dex zeta sql)”For joins, counts, cohort comparisons, and multi-object analytics, Dex exposes a sandboxed read-only SQL interface over your workspace’s Object views (o_<object>) and Dataset views (d_<dataset>):
# Discover available views and lowercased column names firstdex zeta sql schema
# Run a single read-only SELECT (joins use <link_field>_id or <link_field>_ids)dex zeta sql query " SELECT c.name AS company, COUNT(p.id) AS contacts FROM o_person p JOIN o_company c ON p.company_id = c.id GROUP BY c.name ORDER BY contacts DESC"Security and runtime guarantees on Agent SQL:
- Parsed with a Postgres AST validator (
libpg-query): allows only a singleSELECTover allowlisted workspaceo_*andd_*views and safe SQL functions. - Executes inside a read-only transaction (
SET LOCAL transaction_read_only = on) under a dedicatedNOLOGINworkspace SQL role with caller RLS claims applied—every row is filtered to what the calling user is allowed to read. - Protected by a 10-second statement timeout and a 10,000-row / 5 MB response cap (1,000 rows by default;
truncated: truesignals you should aggregate or narrow the query).
3. Saved Views (dex views)
Section titled “3. Saved Views (dex views)”When a recurring question needs a stable definition shared across people and agents, define a saved View (views/*.md) and query it with dex views query <id>.
Related pages
Section titled “Related pages”- Ontology - Define the Object types, link fields, and mappings behind the graph
- Nexus - Visualize the graph in Force, Constellation, and Spatial modes
- Records, observations, and timeline - Provenance, manual notes, and timeline windowing
- Sources and data scopes - Row-level permissions and Data Scopes
- Knowledge and memory - When to use Knowledge files instead of the knowledge graph