Blog

AI functions belong inside SQL

Forecasting and anomaly detection usually live in a pipeline next to the database. On a GPU-native engine they are table functions in the query — which changes who gets to use them.

Most analytics teams already do machine learning on their time series. They export the series, run a model somewhere else, and write the result back — or, more often, into a dashboard nobody trusts because it is a day stale. The model is fine. The pipeline is where freshness, ownership and correctness go to die.

The pipeline is the problem

A forecast is a function of a series. An anomaly score is a function of a series. If the series is a SELECT, the natural place for the function is in the same statement. What has stopped that from happening is not conceptual; it is that CPU databases have no spare compute for inference, and models want the kind of parallelism a GPU provides.

A GPU-native engine has that compute sitting next to the data. So in RayoDB, forecasting and anomaly detection are table functions:

-- the next 24 hours, with 10/50/90 quantile bands
SELECT * FROM AI_FORECAST(hourly_plays, hour, plays, 24, '0.1,0.5,0.9');

-- what is misbehaving right now
SELECT ts, value, expected, score
FROM AI_DETECT_ANOMALIES(hourly_errors, hour, errors, 3.5)
WHERE is_anomaly
ORDER BY score DESC;

No export, no scheduler, no write-back. The result is a table like any other, joinable, filterable, fresh as the data underneath it.

Baselines first, models when you want them

AI_FORECAST works with zero setup: a built-in baseline backtests several statistical methods on your series and picks the winner honestly, with quantile bands. When you want more, you register a model:

CREATE AI MODEL chronos_bolt TASK FORECAST BACKEND ONNX PATH '/models/chronos-bolt-small';
SELECT * FROM AI_FORECAST(hourly_plays, hour, plays, 24, '0.1,0.5,0.9', 'chronos_bolt');

The catalog is SQL. Models are ONNX artifacts with a manifest, validated at registration, persisted across restarts, and served on the GPU where the data lives. The same mechanism gives you AI_EMBED and AI_SIMILARITY for text — semantic matching in a WHERE clause, with a built-in embedder that needs nothing installed and neural models when you register them.

Who gets to use it

The interesting consequence is organizational. When a forecast is a clause, the analyst writing the query gets to use it — not the team that owns the pipeline. Forecasting stops being a project and becomes a verb. That is what we mean when we say the GPU unlocks questions that were too expensive to ask.

Read more about the functions in the product overview, or request early access and run them on your own series.

See it on your data.

Early access is open to a small group of design partners.