DuckDB Extension
VGI
Expose your APIs, application data, and models to DuckDB SQL. VGI (Vector Gateway Interface) connects DuckDB to a worker: a local program or hosted service that publishes SQL tables and functions backed by your code.
On this page
Connect SQL to code running in a worker
A VGI worker defines tables and functions that DuckDB can call. Its implementation might fetch an API response, query an internal service, or run a model. The extension handles the connection; the worker decides how to obtain the data or compute the result.
Attach a worker someone else has published, or build your own using a supported SDK. Its tables and functions can then participate in queries alongside your local data. The public earthquake worker below is one example of that interface; each worker can expose a different set of capabilities.
VGI runs in DuckDB 2.0, installed from the Query.Farm extension repository, and in Haybarn, which ships it. A few capabilities need engine changes that are in Haybarn but not yet in a DuckDB release: named arguments in a correlated LATERAL call (LATERAL f(t.x, opt := 1)), cancelling a query mid-request over HTTP, DELETE … RETURNING on worker tables, and pushing join filters down to workers. In current builds, SELECT * FROM vgi_engine_features() reports which of these your engine supports.
Example
Try VGI with a public demo worker
This demo worker publishes a live earthquake feed, so you can try VGI without writing or hosting anything. ATTACH connects to the worker; SELECT reads a table it provides. Your own workers use the same pattern to expose different data and functions.
Before you run it: The embedded browser supports this worker. For native SQL, use DuckDB 2.0 or Haybarn 2.0 with the current VGI extension. Network access is required.
Browser examples use Haybarn-Wasm 2.0.0-rc12.
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;
ATTACH 'earthquakes' AS eq (
TYPE vgi, LOCATION 'https://vgi-earthquakes.rusty-bb6.workers.dev'
);
SELECT round(mag, 1) AS magnitude, place
FROM eq.main.recent
ORDER BY time DESC
LIMIT 5;
INSTALL vgi FROM community;
LOAD vgi;
ATTACH 'earthquakes' AS eq (
TYPE vgi, LOCATION 'https://vgi-earthquakes.rusty-bb6.workers.dev'
);
SELECT round(mag, 1) AS magnitude, place
FROM eq.main.recent
ORDER BY time DESC
LIMIT 5;
To use your own API or code, build a worker that exposes it, then attach that worker’s location. The worker defines its own tables and functions; eq.main.recent belongs to this demo. You can also try a worker that calls a weather API. The earthquake feed changes, so your results will vary.
Common tasks
- Expose your own API or code Build a worker that turns an API, a model, or an existing library into SQL tables and functions.
- Join data from two workers Combine the earthquake feed with weather data in one SQL query.
- Sign in to a protected worker Connect with a bearer token or an interactive OAuth flow.
Reference
Extension Contents
Quick reference to all available functions and settings organized by category.
| Name | Type | Description |
|---|---|---|
|
Catalog
|
||
| vgi | Object type: Catalog | ATTACH a VGI worker as a DuckDB catalog and query it in SQL. |
|
Configuration
|
||
| vgi_async_prefetch | Object type: Setting | Enable async I/O prefetch for VGI table-function scans. |
| vgi_cancel_enabled | Object type: Setting |
Notify VGI workers (on both the subprocess and HTTP transports) when a stream is torn down early, so their on_cancel hook can release resources.
|
| vgi_eager_load_threshold | Object type: Setting |
Per-object-kind threshold keyed by VgiCatalogSet::CacheKindName (table, view, index, scalar_function, aggregate_function, table_function, macro).
|
| vgi_http_timeout_seconds | Object type: Setting |
Timeout, in seconds, for VGI HTTP requests (catalog, init, and exchange operations).
|
| vgi_join_keys_max_bytes | Object type: Setting | Maximum estimated byte size for a join-keys batch; pushdown is skipped if exceeded. |
| vgi_join_keys_threshold | Object type: Setting |
When a join has a VGI scan on one side, raise DuckDB's dynamic_or_filter_threshold to this value so the build side's distinct join keys are pushed to the worker as an IN filter.
|
| vgi_multi_branch_scans | Object type: Setting |
Rewrite VGI multi-branch table scans into LogicalSetOperation(UNION_ALL, ...) via the optimizer extension.
|
| vgi_oauth_enabled | Object type: Setting |
Enable interactive OAuth (PKCE or device-code) authentication on HTTP 401.
|
| vgi_oauth_flow | Object type: Setting | OAuth flow type. |
| vgi_oauth_prompt | Object type: Setting |
OAuth prompt behavior sent to the authorization endpoint.
|
| vgi_oauth_timeout_seconds | Object type: Setting | Window, in seconds, for a human to complete interactive OAuth (device-code or browser/PKCE) authentication. |
| vgi_secret_default_ttl_seconds | Object type: Setting | Default cache TTL, in seconds, for credentials fetched from an Orchard remote secret provider. |
| vgi_streaming_window | Object type: Setting |
Route eligible OVER (...) queries against VGI aggregates with streaming_partitioned=true through the custom streaming operator.
|
| vgi_table_buffering | Object type: Setting |
Rewrite calls to TableBufferingFunction subclasses through the Sink+Source PhysicalVgiTableBufferingFunction operator.
|
| vgi_trust_empty_kinds | Object type: Setting |
Trust worker assertions that estimated_object_count[kind] == 0 means the kind is empty (skip the catalog_schema_contents_* RPC).
|
| vgi_worker_pool_idle_limit_seconds | Object type: Setting | Maximum idle time, in seconds, before pooled workers are removed. |
| vgi_worker_pool_max | Object type: Setting |
Default per-path pool limit for VGI workers (0 = disabled).
|
|
Diagnostics
Look under the hood of a VGI table — its per-column statistics and, for multi-branch tables, the branches it declares. |
||
| vgi_table_branches() | Object type: Table function | Inspect how each attached VGI table is composed from its underlying worker functions, one row per branch per table across every attached VGI catalog. |
| vgi_table_statistics() | Object type: Table function | Show the per-column statistics DuckDB holds for a VGI table, identified by catalog, schema, and table name. |
|
Internal
Implementation details that aren't part of the public API. Listed for completeness — you should not call these directly. |
||
| vgi_native_delegation_marker() | Object type: Table function | Internal: a placeholder table function used by VGI's multi-branch scan rewriter to carry filter and projection pushdown before they are handed to the real worker-backed scan. |
|
Maintenance
Clear VGI's caches and pooled workers to force fresh state on the next call. |
||
| vgi_clear_cache() | Object type: Table function | Clear cached catalog metadata (schemas, tables, functions, statistics) for all attached VGI catalogs, returning one row per catalog cleared. |
| vgi_worker_pool_flush() | Object type: Table function | Clear all subprocess-pooled VGI workers, returning one row with the count of workers flushed. |
|
OAuth & identity
Inspect and manage the OAuth identity a catalog authenticates with: who you are, the tokens currently held, and signing out. |
||
| vgi_oauth_identity() | Object type: Table function | Report the OIDC identity for each attached VGI catalog (catalog_name, origin, authenticated, sub, email, name, issuer, and the full decoded id_token claims as JSON). |
| vgi_oauth_logout() | Object type: Table function | Forget cached OAuth tokens. |
| vgi_oauth_tokens() | Object type: Table function | Show the OAuth tokens the extension has cached, one row per origin, with each token's expiry and refresh state. |
|
Secrets
Inspect the secret providers registered for a catalog and flush their cached secrets. |
||
| vgi_secret_provider_flush() | Object type: Table function | Clear the TTL cache of one Orchard remote secret provider, or all providers when 'catalog' is omitted. |
| vgi_secret_providers() | Object type: Table function | List the Orchard remote secret providers auto-registered by attached VGI catalogs, one row per provider with its endpoint, tie-break offset, active flag, cached-secret count, and cache TTL. |
|
Worker access
Reach a VGI worker directly — discover the catalogs it advertises and run its table functions or table scans — without |
||
| vgi_catalogs() | Object type: Table function | List the catalogs advertised by a VGI worker, one row per catalog with its name and description. |
| vgi_table_function() | Object type: Table function | Legacy API. Current VGI releases call worker-defined functions through an attached catalog. |
| vgi_table_scan() | Object type: Table function | Internal: the physical scan operator for tables in an attached VGI catalog. |
|
Workers & pooling
Inspect VGI's subprocess worker pool — which workers are alive and how often pooled workers are reused. |
||
| vgi_worker_pool() | Object type: Table function |
List the VGI worker subprocesses currently pooled for reuse by this DuckDB process, one row per worker with its path, version info, pid, and idle age in seconds.
|
| vgi_worker_pool_stats() | Object type: Table function | Report worker-pool reuse effectiveness, one row per worker_path with how many acquisitions reused a pooled worker (hits) versus spawned a fresh one (misses). |
No extension contents match that search.
API Reference
Function Reference
Database Storage
Storage Extensions
Catalog implementations that attach external storage as a DuckDB database.
vgi
Description
ATTACH a VGI worker as a DuckDB catalog and query it in SQL. The database identifier you pass to ATTACH is the catalog name the worker advertises — a single worker can serve several catalogs — while the worker itself is selected with the LOCATION option. Once attached, the worker's schemas, tables, and table functions are queryable like any local database, joins and aggregates included. LOCATION accepts an HTTP(S) URL for a hosted worker, or an executable path / launch: spec for a worker VGI runs as a local subprocess. Any options VGI doesn't recognize are forwarded to the worker and validated against the attach-option specs that catalog declares, so each worker can accept its own attach-time options.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
location
|
VARCHAR
|
Required |
Where the worker lives: an HTTP(S) URL for a hosted worker (e.g. https://host/vgi/), or an executable path / launch: spec for a worker VGI runs as a local subprocess. May instead be embedded in the database identifier as '<catalog>?location=<worker>'.
|
secrets
|
BOOLEAN
|
Optional |
Default: true
Whether to auto-register the remote secret provider a worker advertises in its attach response, reusing this catalog's identity. Set false to opt out.
|
bearer_token
|
VARCHAR
|
Optional | Bearer token sent to the worker. Avoid inlining it in query text where you can. |
oauth_refresh_token
|
VARCHAR
|
Optional |
OAuth refresh token used to seed silent authentication for this catalog (see vgi_oauth_tokens and vgi_oauth_identity).
|
data_version_spec
|
VARCHAR
|
Optional | Pin the catalog to a specific data-version specifier the worker advertises, instead of the latest. |
pool
|
BOOLEAN
|
Optional |
Whether subprocess workers for this catalog are pooled and reused across attaches. Applies to executable / launch: LOCATIONs.
|
pool_max
|
BIGINT
|
Optional | Maximum number of pooled subprocess workers to keep for this catalog. |
pool_timeout
|
BIGINT
|
Optional | Idle time, in seconds, before a pooled subprocess worker is shut down. |
worker_debug
|
BOOLEAN
|
Optional | Enable verbose worker-side debug logging for this catalog. |
Examples
Attach a hosted worker as a catalog and query it like a local database
ATTACH 'earthquakes' AS earthquakes (
TYPE vgi,
LOCATION 'https://vgi-earthquakes.rusty-bb6.workers.dev'
);
SELECT time, mag, place
FROM earthquakes.main.recent
LIMIT 10;
Run a worker as a local subprocess and pool it across attaches
-- browser-unavailable: This example starts a local worker process. Run it in native DuckDB; the browser supports HTTP workers.
-- LOCATION can point at an executable VGI launches as a subprocess.
ATTACH 'example' AS ex (
TYPE vgi,
LOCATION './my_worker',
pool true
);
SHOW TABLES FROM ex;
Discover the catalogs a worker exposes before attaching one
SELECT catalog, source_url
FROM vgi_catalogs('https://vgi-earthquakes.rusty-bb6.workers.dev');
Configuration
Settings
Configure the vgi extension behavior using these settings.
vgi_async_prefetch
Enable async I/O prefetch for VGI table-function scans. Off by default: DuckDB's POSITIONAL JOIN operator does not handle BLOCKED sources.
false
vgi_cancel_enabled
Notify VGI workers (on both the subprocess and HTTP transports) when a stream is torn down early, so their on_cancel hook can release resources. Set to false to disable: destructors skip the cancel dispatch entirely, on_cancel is never invoked, and workers learn the stream is gone only via normal stream-close / HTTP TTL.
true
vgi_eager_load_threshold
Per-object-kind threshold keyed by VgiCatalogSet::CacheKindName (table, view, index, scalar_function, aggregate_function, table_function, macro). When a schema's estimated_object_count[kind] is ≤ the threshold, the first GetEntry() triggers a single bulk LoadEntries() instead of N per-name RPCs. Read at ATTACH; a mid-session SET requires re-ATTACH to take effect.
table |
1000 |
view |
1000 |
index |
1000 |
scalar_function |
1000 |
aggregate_function |
1000 |
table_function |
1000 |
macro |
1000 |
vgi_http_timeout_seconds
Timeout, in seconds, for VGI HTTP requests (catalog, init, and exchange operations).
300
vgi_join_keys_max_bytes
Maximum estimated byte size for a join-keys batch; pushdown is skipped if exceeded.
67108864
vgi_join_keys_threshold
When a join has a VGI scan on one side, raise DuckDB's dynamic_or_filter_threshold to this value so the build side's distinct join keys are pushed to the worker as an IN filter. This is a threshold, not a cap on how many keys are sent: if the distinct count exceeds it, no keys are pushed (the filter isn't built). Raise-only — it never lowers a user-set threshold. 0 = disabled. See also vgi_join_keys_max_bytes for the byte-size cap.
100000
vgi_multi_branch_scans
Rewrite VGI multi-branch table scans into LogicalSetOperation(UNION_ALL, ...) via the optimizer extension. Set to false to disable the rewrite — multi-branch table scans then throw at execution time (the marker placeholder's loud-fail). Emergency-rollback knob; not generally useful.
true
vgi_oauth_enabled
Enable interactive OAuth (PKCE or device-code) authentication on HTTP 401. Set to false to fail fast instead of prompting.
true
vgi_oauth_flow
OAuth flow type. auto lets VGI choose based on what the provider advertises.
auto
auto
device_code
pkce
vgi_oauth_prompt
OAuth prompt behavior sent to the authorization endpoint.
none
none
login
select_account
consent
vgi_oauth_timeout_seconds
Window, in seconds, for a human to complete interactive OAuth (device-code or browser/PKCE) authentication. Further capped by the provider's token expires_in.
120
vgi_secret_default_ttl_seconds
Default cache TTL, in seconds, for credentials fetched from an Orchard remote secret provider. Capped per-credential by the credential's own expiry. Read at ATTACH and frozen per-provider.
300
vgi_streaming_window
Route eligible OVER (...) queries against VGI aggregates with streaming_partitioned=true through the custom streaming operator. Set to false to fall back to PhysicalWindow / WindowCustomAggregator.
true
vgi_table_buffering
Rewrite calls to TableBufferingFunction subclasses through the Sink+Source PhysicalVgiTableBufferingFunction operator. Set to false to disable the rewrite — table_buffering queries then throw a clear InternalException instead of running.
true
vgi_trust_empty_kinds
Trust worker assertions that estimated_object_count[kind] == 0 means the kind is empty (skip the catalog_schema_contents_* RPC). Set to false to force every RPC to fire even when the worker reports zero — a debug escape hatch for diagnosing worker bugs.
true
vgi_worker_pool_idle_limit_seconds
Maximum idle time, in seconds, before pooled workers are removed.
5
vgi_worker_pool_max
Default per-path pool limit for VGI workers (0 = disabled).
256
Platform Support
Compatibility
Extension availability may vary by platform and DuckDB version. Check below to ensure this extension supports your environment before installation.
Quick Facts
Platforms
Haybarn 1.5.6
- Linux x86_64aarch64
- Linux (musl) Not available
- macOS IntelApple Silicon
- Windows x86_64
- WASM ehmvpthreads
Compiled binary sizes
| Platform | Architecture | Size |
|---|---|---|
| Linux | x86_64 | 29.31 MB |
| Linux | aarch64 | 27.38 MB |
| macOS | Intel | 20.17 MB |
| macOS | Apple Silicon | 18.89 MB |
| Windows | x86_64 | 17.79 MB |
Compressed download sizes for the release shown above.
DuckDB & Haybarn
Release calendar- Haybarn v1.5.6 Built-in community repository Supported
Browser examples use Haybarn-Wasm 2.0.0-rc12.
Checked .