Skip to content
Vector Gateway Interface logo

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.

292,273
extension loads · last 90 days
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;

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

Reference

Extension Contents

Quick reference to all available functions and settings organized by category.

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
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
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
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
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
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
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
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).

API Reference

Function Reference

Database Storage

Storage Extensions

Catalog implementations that attach external storage as a DuckDB database.

vgi

Catalog Catalog
Description
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
1
ATTACH 'earthquakes' AS earthquakes (
  TYPE vgi,
  LOCATION 'https://vgi-earthquakes.rusty-bb6.workers.dev'
);

SELECT time, mag, place
FROM earthquakes.main.recent
LIMIT 10;
2
-- 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;
3
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

Default Value: false

vgi_cancel_enabled

Default Value: true

vgi_eager_load_threshold

MAP(VARCHAR, BIGINT) Configuration
Default value
table 1000
view 1000
index 1000
scalar_function 1000
aggregate_function 1000
table_function 1000
macro 1000

vgi_http_timeout_seconds

Default Value: 300

vgi_join_keys_max_bytes

Default Value: 67108864

vgi_join_keys_threshold

Default Value: 100000

vgi_multi_branch_scans

Default Value: true

vgi_oauth_enabled

Default Value: true

vgi_oauth_flow

Default Value: auto
Valid Values:
auto device_code pkce

vgi_oauth_prompt

Default Value: none
Valid Values:
none login select_account consent

vgi_oauth_timeout_seconds

Default Value: 120

vgi_secret_default_ttl_seconds

Default Value: 300

vgi_streaming_window

Default Value: true

vgi_table_buffering

Default Value: true

vgi_trust_empty_kinds

Default Value: true

vgi_worker_pool_idle_limit_seconds

Default Value: 5

vgi_worker_pool_max

Default Value: 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

Release status Stable
Pricing Free
Source Available Yes
View on GitHub
Usage
292,273
loads · last 90 days

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 .