Skip to content

Anomaly

Find outliers, discords, repeated motifs and change points in numeric series from SQL

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/anomaly/index.md to help me query Anomaly with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Find outliers in a time series

Example output Β· captured
Connector release
v0.6.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT "index"
FROM anomaly.main.zscore_anomalies((SELECT CASE WHEN i = 19 THEN 100.0 ELSE 0.0 END FROM range(20) t(i) ORDER BY i))
Result
index
19

Quick start

Choose where to run Anomaly, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'anomaly' AS anomaly (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-anomaly-worker'
);

3. Run a query

query.sql
SELECT "index"
FROM anomaly.main.zscore_anomalies((SELECT CASE WHEN i = 19 THEN 100.0 ELSE 0.0 END FROM range(20) t(i) ORDER BY i))
More example queries β†’
Technical details
Verified connector release
v0.6.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'anomaly' AS anomaly (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-anomaly-worker'
);

Overview

Time-series anomaly detection: matrix profile, change points, z-score for SQL.

Catalog

Everything anomaly exposes once attached β€” read straight from the worker's released build.

anomaly 1 schema
main 5 functions

Time-series anomaly detection: matrix profile, change points, z-score for SQL

Schema examples (5)
Examples (5)

Full matrix profile of a 10-point series with window 4 (7 nearest-neighbour distances).

SELECT anomaly.main.matrix_profile([1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0]::DOUBLE[], 4);

Start index of the top discord (the most anomalous window-4 subsequence) β€” the spike at 18 gives 16.

SELECT anomaly.main.discord_index([1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0,3.0,2.0,50.0,2.0,3.0,4.0,3.0,2.0,1.0]::DOUBLE[], 4);

Start index of the top motif (the most repeated window-5 subsequence) β€” the two triangles give 0.

SELECT anomaly.main.motif_index([0.0,2.0,4.0,2.0,0.0,0.1,0.116,0.133,0.15,0.166,0.183,0.2,0.0,2.0,4.0,2.0,0.0,0.3,0.4,0.5]::DOUBLE[], 5);

Automatically detect regime changes on a single step β€” the level shift at index 8 gives [8].

SELECT anomaly.main.change_points([1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,9.0,9.0,9.0,9.0,9.0,9.0,9.0,9.0]::DOUBLE[]);
1 more example

Flag z-score point outliers beyond 2 sigma β€” the 40.0 spike is index 5, so the result is [5].

SELECT anomaly.main.zscore_anomalies([10.0,10.0,11.0,9.0,10.0,40.0,10.0,9.0,11.0]::DOUBLE[], 2.0);
Table in-out functions
change_points (data TABLE, n_bkps := BIGINT) +2 overloads 3 examples

Regime-change indices from an ordered numeric table; optional n_bkps selects an exact count.

Positional arguments
data TABLE
One numeric column, ordered by time with ORDER BY in the input query.
Named arguments
n_bkps := BIGINT
Exact breakpoint count; omit for PELT. Β· default null
Overloads
change_points(data TABLE, n_bkps BIGINT)change_points(values DOUBLE[]) β†’ BIGINT[]change_points(values DOUBLE[], n_bkps BIGINT) β†’ BIGINT[]
Returns columns
index BIGINT
Zero-based position in the ordered input; NULL for an invalid series.
Examples (3)

Change point rows

SELECT "index"
FROM anomaly.change_points((SELECT CASE WHEN i < 8 THEN 1.0 ELSE 9.0 END FROM range(16) t(i) ORDER BY i));

Auto-detect change points on a single step at index 8 -> [8].

SELECT anomaly.main.change_points([1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,9.0,9.0,9.0,9.0,9.0,9.0,9.0,9.0]::DOUBLE[]);

Detect exactly one change point on a single step -> [8].

SELECT anomaly.main.change_points([1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,9.0,9.0,9.0,9.0,9.0,9.0,9.0,9.0]::DOUBLE[], 1);
Link
discord_index (data TABLE, window_size := BIGINT) +1 overload 2 examples

Most anomalous window's zero-based start index from an ordered numeric table.

Positional arguments
data TABLE
One numeric column, ordered by time with ORDER BY in the input query.
Named arguments
window_size := BIGINT
Subsequence length; at least 3 and less than the series length.
Overloads
discord_index(data TABLE, window_size BIGINT)discord_index(values DOUBLE[], window BIGINT) β†’ BIGINT
Returns columns
index BIGINT
Zero-based position in the ordered input; NULL for an invalid series.
Examples (2)

Discord index row

SELECT "index"
FROM anomaly.discord_index((SELECT i::DOUBLE FROM range(10) t(i) ORDER BY i), window_size := 4);

Index of the most anomalous window (a spike at 18 -> 16).

SELECT anomaly.main.discord_index([1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0,3.0,2.0,50.0,2.0,3.0,4.0,3.0,2.0,1.0]::DOUBLE[], 4);
Link
matrix_profile (data TABLE, window_size := BIGINT) +1 overload 2 examples

Matrix-profile distances as rows from an ordered numeric table.

Positional arguments
data TABLE
One numeric column, ordered by time with ORDER BY in the input query.
Named arguments
window_size := BIGINT
Subsequence length; at least 3 and less than the series length.
Overloads
matrix_profile(data TABLE, window_size BIGINT)matrix_profile(values DOUBLE[], window BIGINT) β†’ DOUBLE[]
Returns columns
index BIGINT
Zero-based position in the ordered input; NULL for an invalid series.
distance DOUBLE
Z-normalized distance to the nearest non-trivial neighbour.
Examples (2)

Matrix profile rows

SELECT "index", distance
FROM anomaly.matrix_profile((SELECT i::DOUBLE FROM range(10) t(i) ORDER BY i), window_size := 4);

Matrix profile of a 10-point series with window 4 (7 distances).

SELECT anomaly.main.matrix_profile([1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0]::DOUBLE[], 4);
Link
motif_index (data TABLE, window_size := BIGINT) +1 overload 2 examples

Most repeated window's zero-based start index from an ordered numeric table.

Positional arguments
data TABLE
One numeric column, ordered by time with ORDER BY in the input query.
Named arguments
window_size := BIGINT
Subsequence length; at least 3 and less than the series length.
Overloads
motif_index(data TABLE, window_size BIGINT)motif_index(values DOUBLE[], window BIGINT) β†’ BIGINT
Returns columns
index BIGINT
Zero-based position in the ordered input; NULL for an invalid series.
Examples (2)

Motif index row

SELECT "index"
FROM anomaly.motif_index((SELECT i::DOUBLE FROM range(10) t(i) ORDER BY i), window_size := 4);

Index of the most repeated window (two triangles -> 0).

SELECT anomaly.main.motif_index([0.0,2.0,4.0,2.0,0.0,0.1,0.116,0.133,0.15,0.166,0.183,0.2,0.0,2.0,4.0,2.0,0.0,0.3,0.4,0.5]::DOUBLE[], 5);
Link
zscore_anomalies (data TABLE, threshold := DOUBLE) +2 overloads 5 examples

Point-outlier indices from an ordered numeric table; threshold defaults to 3 sigma.

Positional arguments
data TABLE
One numeric column, ordered by time with ORDER BY in the input query.
Named arguments
threshold := DOUBLE
Positive finite population z-score cutoff. Β· default 3.0
Overloads
zscore_anomalies(data TABLE, threshold DOUBLE)zscore_anomalies(values DOUBLE[], threshold DOUBLE) β†’ BIGINT[]zscore_anomalies(values DOUBLE[]) β†’ BIGINT[]
Returns columns
index BIGINT
Zero-based position in the ordered input; NULL for an invalid series.
Examples (5)

Z-score outlier rows

SELECT "index"
FROM anomaly.zscore_anomalies((SELECT CASE WHEN i = 19 THEN 100.0 ELSE 0.0 END FROM range(20) t(i) ORDER BY i));

Flag point outliers at the default 3-sigma cutoff β€” the lone 100.0 among zeros is index 19.

SELECT anomaly.main.zscore_anomalies([0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,100.0]::DOUBLE[]);

Flag samples beyond 2 sigma (an outlier at index 5).

SELECT anomaly.main.zscore_anomalies([10.0,10.0,11.0,9.0,10.0,40.0,10.0,9.0,11.0]::DOUBLE[], 2.0);
2 more examples
SELECT anomaly.main.change_points([1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,9.0,9.0,9.0,9.0,9.0,9.0,9.0,9.0]::DOUBLE[]);
SELECT anomaly.main.change_points([1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,9.0,9.0,9.0,9.0,9.0,9.0,9.0,9.0]::DOUBLE[], 1);
Link

Try these queries

Full matrix profile of a 10-point series with window 4 (7 nearest-neighbour distances).

SELECT anomaly.main.matrix_profile([1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0]::DOUBLE[], 4)

Uses matrix_profile

Start index of the top discord (the most anomalous window-4 subsequence) β€” the spike at 18 gives 16.

SELECT anomaly.main.discord_index([1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0,3.0,2.0,50.0,2.0,3.0,4.0,3.0,2.0,1.0]::DOUBLE[], 4)

Uses discord_index

Start index of the top motif (the most repeated window-5 subsequence) β€” the two triangles give 0.

SELECT anomaly.main.motif_index([0.0,2.0,4.0,2.0,0.0,0.1,0.116,0.133,0.15,0.166,0.183,0.2,0.0,2.0,4.0,2.0,0.0,0.3,0.4,0.5]::DOUBLE[], 5)

Uses motif_index

Automatically detect regime changes on a single step β€” the level shift at index 8 gives [8].

SELECT anomaly.main.change_points([1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,9.0,9.0,9.0,9.0,9.0,9.0,9.0,9.0]::DOUBLE[])

Uses change_points

Flag z-score point outliers beyond 2 sigma β€” the 40.0 spike is index 5, so the result is [5].

SELECT anomaly.main.zscore_anomalies([10.0,10.0,11.0,9.0,10.0,40.0,10.0,9.0,11.0]::DOUBLE[], 2.0)

Uses zscore_anomalies

Motif index row

SELECT "index"
FROM anomaly.motif_index((SELECT i::DOUBLE FROM range(10) t(i) ORDER BY i), window_size := 4)

Uses motif_index

6 more examples in the Catalog, each listed under the table or function it uses.

Anomaly is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.