Build a Graph
Connect the tables from Define Tables so Kumo can learn from relationships between entities and events. These calls are the same in local Python and in Snowflake or Databricks notebooks.
Prerequisites
Before you start, complete the following prerequisites:
- Tables: Define the tables to connect. The first example continues from the AdventureWorks tables created in Define Tables.
- Column roles and types: Set column types on your tables before constructing the graph. Refer to Define Tables.
- Local working storage: Configure sufficient local working storage for your environment before constructing your graph, as described under Create a Snapshot.
Create a Graph
To create a graph, connect each foreign key to the corresponding primary key.
Use the same connector, customer, product, and sales_order_header objects from Define Tables.
Define the order-detail table, using ModifiedDate as its line-item timestamp, then pass the tables as a sequence and describe each relationship with an Edge:
src_table names the table containing the foreign key, and fkey names that column.
dst_table names the table whose primary key it references.
For a sequence, use each object’s table_name in edges and predictive queries.
Each name must be distinct. To give one source multiple roles, use a mapping as shown in Use One Source in Multiple Roles.
Self-relations, where src_table and dst_table identify the same graph table, are not supported.
Kumo emits a warning and omits these relationships from the snapshot.
validate() checks the schema, key references, and compatible key types before ingestion.
A successful return produces no result object. If validation fails, correct the named table, column, or type before requesting a snapshot.
It does not establish that every source row has a matching relationship.
Treat a graph as immutable after construction. Do not mutate its exposed tables or edges lists. To change tables or relationships, construct a new Graph with the revised sequence or mapping.
Visualize Table Relationships
Kumo Engine includes an interactive graph viewer for inspecting tables and their relationships.
Display the graph from Create a Graph with graph.visualize():
No snapshot or trained model is needed, and the default call reads no source rows. Arrows point from foreign keys to primary keys. Column badges mark primary keys (PK), foreign keys (FK), time columns (TS), and end-time columns (TE).
Try the same Kumo Engine viewer below with synthetic customers, orders, and products. This example includes sample values and requires no setup.
Hover over a table or column to highlight it, and drag the diagram to pan. Expand the graph to inspect column details and sample values in hover boxes. To zoom, use + and −. To fit the graph, use Fit graph. For a larger view, use Expand graph.
Show Columns and Sample Values
Continue with the AdventureWorks graph from Create a Graph.
Every table must already have a resolved definition. If a table’s definition is None, resolve its metadata and construct the graph again with the returned table.
To declare a primary key, use Table.from_source_table(..., primary_key=...) as shown in Define Tables.
Resolving metadata can read the source. The rendering helper below only reads the existing definition.
Include other columns alongside the key and time columns with show_cols=True:
The viewer shows up to 10 columns per table, or 5 for graphs with more than 10 tables, plus any remaining key and time columns. In a notebook, the layout selector switches between Standard and Compact arrangements.
Add show_samples=True to include source values in column hover boxes:
Unlike the preloaded example above, this call reads your source data and can incur warehouse charges. Sample values are included in saved notebook output.
Export the Graph and Schema
Save a diagram as SVG or PDF, or export the schema as Markdown:
PDF and Markdown include a complete column and connection index, even for columns omitted from the diagram.
Markdown also includes a Mermaid relationship diagram.
Exports omit sample values. SVG and PDF use a light palette and the initial layout.
Set layout to "auto" (the default), "standard", or "compact" to choose that layout.
Kumo Engine saves the files where it runs.
Use your local output directory or your notebook’s file browser to retrieve them.
Resolve Visualization Errors
Visualization supports up to 30 tables and does not support self-relations. For larger graphs, visualize a smaller graph containing the tables and relationships you want to inspect. If a table definition is missing, refresh its metadata and rebuild the graph with the returned table.
Use One Source in Multiple Roles
Use graph aliases when the same source has different roles, such as buyers and sellers in a transaction.
Pass a mapping from each graph name to its Table. The mapping keys are the names used in edges and predictive queries. The underlying source name and location stay unchanged.
Aliases give each role its own graph table. They do not filter the source rows into different groups.
This standalone local-file example requires an installed Kumo Engine environment and a new, writable directory for two small CSV files.
It creates three customers with a numeric label to predict and two orders with separate buyer_id and seller_id references:
Successful validation returns None. The example prints the following output:
Both aliases refer to the same customer_roles object and read customers.csv from source_dir.
Use buyers or sellers in this graph’s edges and PQL, not customers.
For the seller role, the corresponding query is PREDICT sellers.label FOR EACH sellers.id.
If validation fails, check that edge table names match the mapping keys and that each foreign-key column exists and matches the destination primary-key type.
These calls validate definitions. They do not generate training rows, train a model, or return predictions.
To materialize this example, configure local working storage as described under Create a Snapshot, then call role_graph.snapshot().
Continue to Predictive Queries.
Import a Prepared RelBench Database
Convert an in-memory RelBench Database into a local graph by exporting its tables to Parquet and carrying their declared keys and timestamps into Kumo.
This recipe starts with prepared data. Dataset downloads, benchmark splits, and evaluation tasks are separate steps.
Use an installed Kumo Engine environment with RelBench, pandas, and PyArrow available. Configure local scratch as described under Create a Snapshot before continuing. Choose a new, writable source directory outside scratch. Neither directory can contain the other. Refer to the local-file connector guide.
The following small database illustrates the required metadata: three customers and two timestamped orders, with each order referencing a customer.
If you already have a prepared relbench.base.Database, use it as db and skip this block.
For your own database, this recipe assumes each table has a declared primary-key column and every referenced table is included in db.table_dict.
Keys must be ordinary DataFrame columns, not only index values. Preserve the key values and compatible types across related tables.
Use time_col=None for a table without a time role. Otherwise, the named column must contain timestamps with a compatible type.
Self-relations are unsupported and omitted from snapshots, as explained under Create a Graph. Do not use this recipe to preserve them.
Export each DataFrame without its pandas index, then map the RelBench metadata to Kumo tables and edges.
The database’s table names become both Parquet filenames and graph names, so use simple names such as customers and orders.
Change relbench-example-data to a new source directory for your data:
pkey_col sets the primary-key role, time_col sets the time role, and each entry in fkey_col_to_pkey_table creates an edge to the destination table’s primary key.
For the example, the relationship is orders.customer_id to customers.id, and only orders has a time column.
Before constructing the graph, inspect the resolved column types on each table in relbench_tables.
Inferred types for other columns might need adjustment. For example, a small numeric feature can be inferred as categorical.
Apply any with_column() overrides by assigning the returned table back to relbench_tables[name].
Validate the resulting schema, then materialize the local index:
Successful validation returns None. Snapshot creation returns an object identifying the materialized index and its local directory.
If validation fails, check the declared key and time columns, each foreign-key column, and the referenced table names and key types.
Schema validation does not check every row’s relationship or establish that arbitrary RelBench datasets need no further preparation.
Keep the index files while using the snapshot, as described below, and continue to Predictive Queries.
Inspect a Graph Definition
Use an already constructed graph to review its table names and declared relationships before creating a snapshot:
For a sequence of tables, the names come from each table’s table_name.
For a mapping, its keys are the graph aliases, which can differ from the source table names.
The DataFrame has one row per declared edge, showing the source table, foreign-key column, and destination table.
A graph without edges produces an empty DataFrame with the same three columns.
This example inspects the supplied definition. It does not validate relationships or show which source rows match.
To inspect each table’s column types and key or time roles, use the metadata DataFrame example.
To view the same relationships as a diagram, refer to Visualize Table Relationships.
Create a Snapshot
A graph definition describes what to read. A snapshot materializes the source data into the local index used by training and prediction:
This call runs synchronously and can take time for large datasets. Configure sufficient local working storage before constructing your graph. Follow the working storage steps for your environment: local machine, Snowflake notebook, or Databricks notebook.
The following table describes the snapshot attributes:
Keep the complete index directory while the snapshot is in use. The snapshot object does not copy its files into the Python process, and deleting scratch makes those files unavailable. In a Snowflake notebook, the graph index remains in the notebook compute environment. Creating a snapshot does not store that index in the source schema. In a Databricks notebook, the index also remains in local scratch. A model bundle copied to a Unity Catalog volume does not include the index. Rebuild a compatible snapshot after a cluster restart unless you have separately retained and validated its files.
Refresh Data and Reuse Snapshots
Kumo does not watch your sources.
After the data changes, call graph.snapshot() again to materialize the version the connector now reports.
If that version already has a valid index, Kumo reuses it. A new version gets a separate snapshot, and earlier snapshots stay as they were.
Source preparation might still access the connector before Kumo determines that the index can be reused.
For a local table stored in one file, version detection uses that file’s modification time, to the whole second.
After updating it, make sure its modification time changes to a different second before calling graph.snapshot() again.
For a directory, version detection includes every source file’s path, size, and modification time at nanosecond precision, so adding or removing a file also changes the version.
The graph definition, snapshot, training table, and model bundle are separate artifacts, and each call creates only its own. Pass the selected snapshot explicitly to query generation, training, and prediction. A training table keeps its rows and labels apart from graph features, so you can train or predict with a compatible updated snapshot without regenerating it.
Each call writes only its own artifact and overwrites nothing. Kumo builds a regenerated training table from the new snapshot and does not append it to the original, so the regenerated table need not contain every original row.
Snapshot ids such as g@A stand for the graph id and the data version its connectors reported.
A new snapshot is not a new model: to predict with one, the model’s target, entity types, and features must still be compatible. Changing the graph’s tables, keys, relationships, connectors, or table locations gives it a new id. Kumo Engine 1.0.0 and 1.0.1 do not check that a prediction snapshot belongs to the graph the model was trained on, so pass a snapshot of that graph.
Next Steps
The following topics build on your graph and snapshot:
- Continue to Predictive Queries.
- For feature encoding, refer to Encoder Selection.
- Apply optional encoder overrides through the Model Plan Guide before training.