Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 11 min read How-to mediumAdept

ClickHouse forecasting and anomaly detection with time series foundation models

TimesFM 3.0, a pretrained time-series foundation model, can be called from ClickHouse SQL via executable Python UDFs that forward arrays to an HTTP model server, giving zero-shot forecasts and anomaly scores without per-series training. SQL handles aggregation, ordering and time bucketing. aiForecast returns median, q10–q90 bounds and nine native quantiles per step, and aiDetectAnomalies scores rolling held-out windows by normalized forecast error. On Walmart M5 store sales, adding a known-future Christmas event flag as a covariate dropped Christmas anomaly scores below the threshold in nine of ten stores (e.g. TX_2 from 8.65 to 2.71). The weights carry non-commercial restrictions and the demo is for local evaluation only.

Assumes: ClickHouse SQL and array functionstime series forecasting basicsprediction intervals and quantiles

Related posts

  • Forecasting Using ClickHouse Machine Learning Functions

    ClickHouse mediumAdept

    ClickHouse's built-in stochasticLinearRegression and evalMLMethod functions can fit and apply time-series forecasting models entirely in SQL, with no Python or R. Using monthly flight passenger data, a log-transformed target is regressed on a linear trend plus 12 month dummy variables, with no intercept to avoid the dummy variable trap. One model per airline-airport pair is trained in a single GROUP BY query, giving 35 models. Test-set MAE and RMSE are computed in SQL, and a future-dates view extends the forecasts three years out. Wrapping training in a materialized view would let the models retrain continuously as new data arrives.

  • TimesFM-3: A zero-shot foundation model for multivariate forecasting

    Google Research hardMaster

    TimesFM-3 is a 330M-parameter decoder-only transformer pre-trained on over 1 trillion real and synthetic time points that does zero-shot multivariate forecasting, supporting multiple targets, past-only covariates and known-future covariates. Series are split into 32-step patches with per-series normalization. Future-known covariates use lookahead tokens that concatenate the current patch with future patches. Layers alternate causal temporal attention within each series with full cross-variate attention at each time step. Contiguous Patch Masking replaces autoregressive patch-by-patch decoding, producing the whole horizon and 9 quantiles in one forward pass. It ranks first among pre-trained foundation models on Gift-Eval, FEV-Bench and Time against Chronos-2, Toto 2.0 and TimesFM-2.5, even in univariate mode, and is available on GitHub, Hugging Face and BigQuery's AI.FORECAST.

  • Introducing TabFM: A zero-shot foundation model for tabular data

    Google Research easyNovice

    TabFM is a foundation model that treats tabular classification and regression as in-context learning, so it predicts on an unseen table in a single forward pass with no training, hyperparameter tuning or feature engineering. Its hybrid architecture combines TabPFN-style alternating row and column attention, compression of each row into a dense vector, and a TabICL-style Transformer over the compressed rows to keep compute low on larger tables. It is pretrained entirely on hundreds of millions of synthetic datasets generated from structural causal models. On TabArena (38 classification and 13 regression datasets, 700 to 150K rows), it is reported to beat tuned tree-based baselines in Elo, and an ensemble variant adds cross and SVD features, NNLS weighting and Platt scaling. It is available on Hugging Face and GitHub and through BigQuery's AI.PREDICT.

  • What's new in ClickStack - April 2026

    ClickHouse mediumAdept

    ClickStack's April 2026 release adds alerts driven by arbitrary ClickHouse SQL, so rolling baselines and standard-deviation anomaly checks can be written with window functions and fire when the query returns 1. The default otel_logs schema was redesigned around ClickHouse full-text indexes on attribute map keys/values and lower(Body), with a five-minute bucketed ordering key, improving sample query performance by over 70% at comparable insert cost; versions before 26.2 fall back to bloom_filter indexes. An opt-in companion column flattens attribute maps into key=value arrays so map lookups are rewritten to indexed has() predicates, running 1.4–10x faster. Autocomplete now reads from 15-minute materialized-view rollups instead of scanning live tables, and heatmaps become a general chart type.

  • Executable UDFs are now in public beta on ClickHouse Cloud

    ClickHouse mediumAdept

    Executable UDFs are in public beta on ClickHouse Cloud: you upload a zipped Python function with its model files, and ClickHouse runs it in a pool of long-lived sandboxed processes that can be called from SQL, including inside materialized views. The demo trains a ~270K-parameter PyTorch autoencoder on trade ticks and scores each insert inline through a materialized view, producing a 32-dim embedding and a reconstruction error. A backfill of ~6B rows ran at ~35K rows/sec on a 3-replica cluster. A raw global anomaly threshold proved misleading for high-priced symbols, so anomalies are defined against per-symbol p95 baselines kept in an hourly refreshable materialized view, which cut leaderboard query time from ~1.7s to ~0.27s. Network-access UDFs that can make outbound HTTPS calls are in private beta.

The quest for software engineering knowledge.

Look:
Layout: