# Recommender

> Recommend items and find similar items from user interaction data

This page includes setup, release pins, credentials, hosting and verification evidence. [JSON alternative](https://query.farm/products/orchard/api/v1/connectors/recommender.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: `recommender`. Release: [v0.5.0](https://github.com/Query-farm/vgi-recommender/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-recommender) 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=recommender). 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 'recommender' AS recommender (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/vgi-recommender@v0.5.0 vgi-recommender'
);
```

### 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 'recommender' AS recommender (
  TYPE vgi,
  LOCATION 'oci://ghcr.io/query-farm/vgi-recommender:0.5.0'
);
```

## Recommend the top three items for each user

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

```sql
SELECT user, item, rank FROM recommender.main.recommend_all((SELECT * FROM (VALUES ('u1','A',1.0),('u1','B',1.0),('u1','C',1.0),('u2','A',1.0),('u2','B',1.0),('u2','C',1.0),('u3','A',1.0),('u3','B',1.0),('u4','A',1.0),('u4','B',1.0)) AS events(u, i, v)), user := 'u', item := 'i', value := 'v', n := 3) ORDER BY user, rank
```

- [recommender.main.recommend_all — table_in_out_function](https://query.farm/products/orchard/connectors/recommender/objects/table_in_out_function.bWFpbg.cmVjb21tZW5kX2FsbA.md): exact declaration for this example.

Execution evidence: **captured_result**.

```json
{
  "status": "captured_result",
  "capturedAt": "2026-12-01T06:21:29+00:00",
  "engineVersion": "2.0.1",
  "protocolVersion": "3.4.0",
  "releaseTag": "v0.5.0",
  "sample": {
    "columns": [
      "user",
      "item",
      "rank"
    ],
    "types": [
      "VARCHAR",
      "VARCHAR",
      "INTEGER"
    ],
    "rows": [
      [
        "u3",
        "C",
        1
      ],
      [
        "u4",
        "C",
        1
      ]
    ],
    "more": false
  }
}
```

## Connector reference

### Recommender: Collaborative-Filtering Recommendations in SQL

Generate personalized product and content recommendations directly in DuckDB SQL with implicit-feedback **Alternating Least Squares (ALS)** collaborative filtering -- no separate ML pipeline, notebook, or model server required.

This VGI worker turns a single relation of `(user, item, value)` interactions -- clicks, purchases, plays, ratings, or any engagement signal -- into top-N recommendations, item-to-item similarity, and per-user suggestions. It is built for data engineers, analysts, and application developers who want a fast, reproducible recommender system they can call from a query instead of standing up a dedicated service. Because it runs as a DuckDB attachment, you can join recommendations straight back to your catalog tables, filter them, and ship them to downstream tables or dashboards in a single statement.

Under the hood the worker fits an implicit-feedback ALS matrix-factorization model with the [`implicit`](https://github.com/benfred/implicit) library by Ben Frederickson -- a fast, Cython/BLAS-accelerated implementation of the classic ALS algorithm for implicit datasets. Each call buffers the whole interaction relation, learns latent user and item factors, and scores candidates by the dot product (recommendations) or the cosine of the item factors (similarity). Results are deterministic (pinned `random_state`, single-threaded BLAS), and `value` is treated as the interaction confidence, defaulting to `1.0` when the value column is omitted. See the [implicit documentation](https://benfred.github.io/implicit/) and the [collaborative filtering overview](https://en.wikipedia.org/wiki/Collaborative_filtering) for background on the method.

## Function surface

The worker covers the three everyday collaborative-filtering workloads: personalized top-N recommendations for the whole user base at once, on-demand recommendations for a single target user, and item-to-item nearest-neighbour lookups (the classic *"people who liked X also liked Y"* / related-items surface).

Every recommendation function takes the interaction relation as a positional `(user, item, value)` subquery (`Arg(0)`) and accepts the column roles and hyperparameters as named arguments (`user := ...`, `item := ...`, `value := ...`, `n := ...`, `factors := ...`). The relation's columns are the data; the named arguments just declare which column plays the user, item, and confidence role, so the same query works over any interaction table by pointing the roles at its columns.


## Find the exact SQL object

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

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-recommender",
  "harvest": {
    "status": "ok",
    "method": "subprocess",
    "error": null,
    "vgi_version": "9773130dde"
  },
  "catalogVerification": {
    "verified": true,
    "status": "passed",
    "total": 3,
    "passed": 3,
    "failed": 0,
    "needs_credentials": 0,
    "location": "uvx --from git+https://github.com/Query-farm/vgi-recommender@v0.5.0 vgi-recommender",
    "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:17:43+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."
}
```
