# Vision

> Label images with a MobileNet model, returning the top ImageNet class or the top predictions with confidence scores

This page includes setup, release pins, credentials, hosting and verification evidence. [JSON alternative](https://query.farm/products/orchard/api/v1/connectors/vision.json) contains the same setup facts for structured readers; choose one format.

## Runtime and release

Use DuckDB or Haybarn **2.0.1** with **VGI protocol 3.4**.
Catalog alias: `vision`. Release: [v0.5.0](https://github.com/Query-farm/vgi-vision/releases/tag/v0.5.0). Metadata generated: 2026-12-01T18:22:16+00:00.

## Choose where it runs

- On your machine: use an installation method below. No Query Farm account is required for local execution.
- Self-host: follow [the connector deployment instructions](https://github.com/Query-farm/vgi-vision) and [connection guide](https://query.farm/vgi/connect-to-a-worker/). Use your real endpoint and its authentication settings.
- Query Farm hosted: [create a deployment](https://auth.queryfarm.cloud/console/new?worker=vision). Hosting has a $10 monthly minimum per organization; usage and license fees may apply. Copy the deployment-specific ATTACH from the console.

## Service credentials and prerequisites

No service credentials are declared by this connector. Individual datasets, input files or deployments may have their own prerequisites.

Secret parameter required flags describe the upstream declaration; they do not override the service-level mode above. Keep secrets in environment variables or the deployment secret store. SQL values in angle brackets are placeholders, not automatic environment lookups. Native DuckDB and Haybarn 2.0.1 do not provide a SQL getenv() function, even when worker-supplied snippets mention it. Read environment variables in your application and pass credential values through client parameter bindings (for example, Python con.execute("CREATE SECRET stripe (TYPE stripe, api_key ?)", [os.environ["STRIPE_API_KEY"]]) after attaching the connector. Omit unused optional parameters and keep real values out of saved SQL and logs.

## Install the extension

In stock DuckDB:

```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;
```

In Haybarn:

```sql
INSTALL vgi FROM community;
LOAD vgi;
```

## Attach the connector

The local recipes below pin the catalog release for repeatability. A public demo endpoint follows its deployed release.

### uvx

Attach with uvx

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

```sql
ATTACH 'vision' AS vision (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/vgi-vision@v0.5.0 vgi-vision-worker'
);
```

### Docker

Attach the signed image

Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.

```sql
ATTACH 'vision' AS vision (
  TYPE vgi,
  LOCATION 'oci://ghcr.io/query-farm/vgi-vision:0.5.0'
);
```

## Top-5 (label, confidence) predictions for an image BLOB, confidence-descending.

Service credentials required for this example: not declared by this example; check the connector requirements above.

```sql
SELECT label, round(confidence, 4) AS confidence FROM vision.main.classify('\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0D\x49\x48\x44\x52\x00\x00\x00\x40\x00\x00\x00\x40\x08\x02\x00\x00\x00\x25\x0B\xE6\x89\x00\x00\x00\xE1\x49\x44\x41\x54\x78\xDA\xED\xDA\xB1\x0D\x83\x30\x10\x85\x61\xB0\x18\x21\x43\x30\x4C\x26\xA0\x66\x04\xC6\xC8\x08\x29\x52\x65\x82\x0C\xC3\x10\x19\x22\x05\x4D\xA4\x20\x41\x7C\xCF\x1C\x27\xFF\x57\x02\xB2\xDE\x87\x8D\x31\x16\x6D\x3F\x3C\x9A\xC8\x95\x9A\xE0\x05\x00\x00\x00\x00\x00\x00\x00\xF0\xAC\x6E\xCF\x45\xAF\xE1\xEE\x95\xEF\xFA\x1C\x19\x42\x00\x00\x00\x00\xE0\xFD\x1E\xC8\xA8\x79\x7A\xFF\x1E\xEC\x6F\x97\x00\x80\xD5\xE8\xDF\xA7\xB4\x8C\xEE\x98\xE8\xE5\x18\xE9\xE0\xF4\xD9\xD7\x97\x05\xE4\xA5\x91\x18\x92\x57\x7A\x95\xA1\xFA\xF7\x80\xFD\x16\x1A\x5B\xA8\xBB\x07\x54\x33\x89\xA5\x1D\xD6\x42\x00\x00\x00\x08\x0C\x50\xAD\x28\x2D\xED\x54\x3F\x84\xEC\x9D\x60\x6C\x81\x87\xD8\x76\x0B\xED\x1D\x98\x1C\x9F\x42\xC9\x1C\x20\x1B\x42\xFF\xA6\x51\xCD\x60\xCA\x8F\xFA\x25\xD3\xE6\xD2\xF2\xBC\xBB\x12\x9B\x8C\x18\xFB\x42\xE5\xB2\x32\x8D\x02\x00\x00\x00\x80\xBE\x5A\x7E\xFA\x03\x00\x00\x00\x00\x00\x00\x00\xE4\xD7\x07\x2B\x8B\x39\x99\xCE\x48\xA8\x86\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82'::BLOB) ORDER BY confidence DESC;
```

- [vision.main.classify — table_function](https://query.farm/products/orchard/connectors/vision/objects/table_function.bWFpbg.Y2xhc3NpZnk.md): exact declaration for this example.

Execution evidence: **captured_result**.

```json
{
  "status": "captured_result",
  "capturedAt": "2026-12-01T06:24:17+00:00",
  "engineVersion": "2.0.1",
  "protocolVersion": "3.4.0",
  "releaseTag": "v0.5.0",
  "sample": {
    "columns": [
      "label",
      "confidence"
    ],
    "types": [
      "VARCHAR",
      "DOUBLE"
    ],
    "rows": [
      [
        "envelope",
        0.1352
      ],
      [
        "ping-pong ball",
        0.0981
      ],
      [
        "Band Aid",
        0.0729
      ],
      [
        "tennis ball",
        0.0529
      ],
      [
        "binder",
        0.0524
      ]
    ],
    "more": false
  }
}
```

## Connector reference

### Vision: Image Classification (ImageNet) in SQL

![ONNX Runtime](https://raw.githubusercontent.com/microsoft/onnxruntime/main/docs/images/ONNX_Runtime_logo_dark.png)

**Run deep-learning image classification directly in DuckDB SQL** — point a query at a column of image blobs (or image file paths) and get back ImageNet-1k labels, no Python notebook, model server, or ML pipeline required. The `vision` catalog turns computer-vision inference into ordinary SQL functions you can `SELECT`, filter, `JOIN`, and aggregate.

This extension is for data engineers, analysts, and application developers who want to tag, filter, search, or group images by what they depict without leaving the database. Classic use cases include auto-labeling a column of photo blobs, finding every row whose image looks like a cat or a car, ranking an image's most probable subjects, and enriching a media table with predicted categories — all expressed as the SQL you already write. Because the model runs out-of-process behind VGI, untrusted inputs are safe: a malformed, empty, or oversized image yields SQL `NULL` (scalar) or no rows (table function), never a worker crash.

Under the hood, inference is powered by [ONNX Runtime](https://onnxruntime.ai), Microsoft's high-performance, cross-platform inference engine for ONNX models ([source on GitHub](https://github.com/microsoft/onnxruntime), [documentation](https://onnxruntime.ai/docs/)). The classifier is a permissively-licensed MobileNetV2 model trained on the [ImageNet](https://www.image-net.org) 1000-class dataset (Apache-2.0 weights served via ONNX Runtime's MIT license) — deliberately chosen to be safe for a commercial marketplace, unlike copyleft alternatives. The model and its 1000 labels are downloaded once on first use and cached locally, so subsequent queries pay only inference cost.

## How it works

There are two ways to ask the model about an image: a per-row scalar that returns the single most probable ImageNet label, ideal as an enrichment column, and a table function that returns the top-k `(label, confidence)` predictions in descending confidence. The model's full 1000-class label set is also published as a browsable table, so predicted labels can be validated or joined against the vocabulary the model actually knows.

## Notes

Every image argument is accepted either as a `BLOB` column or via a filesystem-path overload. Untrusted or malformed images yield SQL `NULL` (scalar) or no rows (table), never a crash, making the functions safe to apply across an entire column of user-supplied data.

## Find the exact SQL object

[Browse 3 object declarations](https://query.farm/products/orchard/api/v1/connectors/vision/objects.json) or [search within this connector](https://query.farm/products/orchard/api/v1/search.json?kind=object&connector=vision&q=vision).

Follow one format of each needed object for complete argument types, defaults, named flags, return columns and examples. Existing links above can replace another search. For questions about hosting, credentials or supported operations, stop once the documentation answers the question; SQL and unrelated object lookups are unnecessary.

## Verification and interpretation

- Missing, null, or undeclared metadata means unknown; do not invent defaults, credential scope, platform support or endpoint URLs.
- Search is keyword retrieval, not proof of a capability. Read the exact object declaration before generating SQL.
- A table and a table function can have the same name. Preserve parentheses and use the matching overload and schema.
- Service credentials, external data availability and deployment authentication are separate requirements.
- Catalog verification records the harvest environment. It is not proof that every query or current live API call succeeds. Only an example with captured_result has a saved result for that exact SQL.

```json
{
  "generatedAt": "2026-12-01T18:22:16+00:00",
  "repository": "https://github.com/Query-farm/vgi-vision",
  "harvest": {
    "status": "ok",
    "method": "subprocess",
    "error": null,
    "vgi_version": "9773130dde"
  },
  "catalogVerification": {
    "verified": true,
    "status": "passed",
    "total": 12,
    "passed": 12,
    "failed": 0,
    "needs_credentials": 0,
    "location": "uvx --from git+https://github.com/Query-farm/vgi-vision@v0.5.0 vgi-vision-worker",
    "transport": "subprocess",
    "environment": {
      "vgi_extension_version": "9773130dde",
      "haybarn_version": "2.0.1rc3",
      "engine_version": "v2.0.1",
      "python": "3.12.4",
      "platform": "darwin_arm64",
      "protocol_version": "3.4.0"
    },
    "checked_at": "2026-12-01T06:22:13+00:00"
  },
  "interpretation": "Catalog verification records the harvest environment. It is not proof that every query or current live API call succeeds. Only an example with captured_result has a saved result for that exact SQL."
}
```
