Skip to navigation

Quickstart for Kumo Relational

View as MarkdownOpen in Claude

This quickstart uses local pandas DataFrames to build a relational schema and run a Kumo Relational prediction through an NVIDIA NIM.

The small tables are for API verification only. They do not contain enough historical examples to assess prediction quality.

Prerequisites

Before you start, make the Kumo Relational NIM available. Then install the SDK with the relational extra:

pip install "structured-data-models-client[relational]"

Quickstart Steps

To make your first prediction, complete the following steps:

  1. Prepare the related tables.
  2. Build a Schema with sdm_client.Schema.from_data() and review the inferred metadata and relationships.
  3. Write the prediction task in PQL.
  4. Materialize a Request with PredictiveQuery(...).materialize(indices=...).
  5. Call predict() with the request and the KumoRelational model.

The result is a PredictionResult, and to_pandas() gives you a DataFrame. The following sections walk through this workflow.

Prepare Relational Data

Create two small related tables as pandas DataFrames:

import pandas as pd
users = pd.DataFrame({
"user_id": [1, 2, 3],
"signup_date": pd.to_datetime(["2024-01-01", "2024-02-15", "2024-03-20"]),
})
orders = pd.DataFrame({
"order_id": [101, 102, 103, 104],
"user_id": [1, 1, 2, 3],
"price": [50.0, 30.0, 100.0, 75.0],
"timestamp": pd.to_datetime([
"2025-01-10", "2025-02-15", "2025-01-20", "2025-03-05"
]),
})

Build a Schema

Build a Schema from the two DataFrames:

from sdm_client import Schema
schema = Schema.from_data({
"users": users,
"orders": orders,
})

Schema.from_data() infers table metadata and relationships from the DataFrames you give it. Treat this inference as a starting point. The following pages explain how to inspect and correct it. For tables too large to load into memory, Schema.from_source samples a warehouse or database directly.

Run a Prediction

Write the question in PQL, materialize it against the entities you want scored, and predict:

This standalone example uses a context manager to create and close the client. For an application or notebook that makes multiple requests, follow the reusable client pattern.

from sdm_client import PredictiveQuery, SDMClient, KumoRelational
query = PredictiveQuery(
"PREDICT COUNT(orders.*, 0, 30, days) > 0 FOR EACH users.user_id",
schema,
)
request = query.materialize(indices=[1])
with SDMClient(url="http://localhost:8000") as client:
result = client.predict(request, model=KumoRelational())
print(result.to_pandas())

The returned DataFrame includes row_index and, for this scalar task, prediction and probability_<class> columns. The prediction value depends on the deployed model and the supplied context.

Pass api_key to SDMClient if your deployment has an authenticating gateway.

Next Steps

Now that you have made a first prediction, explore the following resources: