Skip to navigation

Configure Table Metadata

View as Markdown

After you create a graph, review the inferred metadata for every table so Kumo Relational can identify entities, interpret column values, and use the correct event times when building prediction context. Access a table through graph["table_name"]; you do not need to construct table objects directly.

Inspect inferred metadata

Continue with the graph created in Create a graph:

graph.print_metadata()

The output shows each table’s inferred primary key, time columns, and column types. Access the tables that you need to correct:

customers_table = graph["customers"]
orders_table = graph["orders"]
products_table = graph["products"]

Configure keys and timestamps

A primary key uniquely identifies each row in a table. A time column identifies when a row became available to the prediction workflow. Set these fields when inference did not select the intended columns:

customers_table.primary_key = "customer_id"
orders_table.primary_key = "order_id"
orders_table.time_column = "order_time"
products_table.primary_key = "product_id"

Use an end-time column only when a record stops being valid at a known time. The time column should represent when an event became available to the prediction workflow.

Tables can use composite primary keys when one column is not sufficient to identify a row. Configure the complete ordered set of key columns, and ensure every corresponding composite foreign key uses compatible physical and semantic types in the same order.

customers_table.primary_key = ("customer_id", "region")

Every component must be present, non-null, and use a physical type that the SDK can combine into a composite identifier, also called a foldable type. Floating-point columns cannot be components of a composite identity. When you request predictions for entities with a composite key, pass one tuple per entity in the same order:

result = client.relational(graph).predict(
query,
indices=[("AB-10015", "Central"), ("ZZ-00001", "West")],
)

Refer to Time and End-Time Columns for selection guidance, entity-table validity rules, and current sampling behavior for related tables.

Correct semantic types

A semantic type tells Kumo Relational how to interpret a column’s values, regardless of how those values are physically stored. Correct an inferred semantic type when it does not match the column’s role:

from kumo_relational_client import relational
customers_table["customer_id"].stype = relational.Stype.ID
orders_table["order_id"].stype = relational.Stype.ID
orders_table["customer_id"].stype = relational.Stype.ID
orders_table["product_id"].stype = relational.Stype.ID
orders_table["order_time"].stype = relational.Stype.timestamp
products_table["product_id"].stype = relational.Stype.ID

A semantic type assignment must be compatible with the column’s physical data type. Refer to Data Types and Semantic Types for the supported combinations.

Metadata checklist

  • Each table’s primary key values are non-null and unique.
  • Foreign-key columns use values and physical data types that are compatible with those of the referenced keys.
  • The time column represents when an event became available to the prediction workflow.
  • Identifier columns use the ID semantic type.
  • Free-form language uses the text semantic type, and low-cardinality labels use the categorical semantic type.
  • End-time columns are used only when records stop being valid at a known time.

Inspect the result after making corrections:

graph.print_metadata()

Next, review and define relationships.