Skip to navigation

Predictive Queries for Kumo Relational

View as MarkdownOpen in Claude

PQL describes a predictive task over a relational schema. Every runnable Kumo Relational query identifies a target and the entity or entities to score.

Target, Entity, and Horizon

A query identifies the following parts, where the horizon applies to a temporal target:

  • Target: The value or event to predict, such as a column or future aggregation.
  • Entity: The table key for which Kumo Relational returns predictions.
  • Horizon: The future interval used by a temporal target.

The following example shows the structure of a query:

PREDICT <target_expression>
FOR <entity_table>.<primary_key> <entity_selection>
[WHERE <context_filter>]
[ASSUMING <condition>]

Complete Examples

The following examples show complete queries for regression, classification, and a static target:

-- Regression: spend during the next 30 days
PREDICT SUM(orders.amount, 0, 30, days)
FOR customers.customer_id=42
-- Classification: any order during the next 30 days
PREDICT COUNT(orders.*, 0, 30, days) > 0
FOR customers.customer_id IN (42, 57, 81)
-- Static target on the entity table
PREDICT customers.segment
FOR customers.customer_id=42

Current Kumo Relational Constraints

The following constraints describe the current sdm-pql validator, not every construct in the broader PQL grammar:

AreaCurrent Kumo Relational behavior
Entity selectionA query must include FOR or FOR EACH; applications pass keys through indices, up to 100,000 per materialize() call, gathered as at most 100 NIM calls of 10,000 entities each (200 for temporal link prediction).
Static filtersColumn-value filters are limited to the same table; joined static filters are not supported.
Static targetsA non-aggregated target must be on the entity table.
RankingRANK TOP K requires naming the candidate set with materialize(..., candidates=...); no candidate is assumed. One call is made per candidate.
ForecastingFORECAST N TIMEFRAMES is limited to a single entity; one call is made per timeframe.

Refer to Write Predictive Queries for clause and aggregation details, and to Prediction Types for ranking and forecasting.

From Query to Prediction

The following example materializes a query and runs the prediction:

from sdm_client import PredictiveQuery, SDMClient, KumoRelational
query = PredictiveQuery(query_text, schema)
request = query.materialize(indices=[42])
with SDMClient(url="http://localhost:8000") as client:
result = client.predict(request, model=KumoRelational())

Continue with the query-writing tutorial or choose a prediction type.