Skip to content

Recommender

Recommend items and find similar items from user interaction data

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/recommender/index.md to help me query Recommender 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.

Recommend the top three items for each user

Example output · captured
Connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
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
Result
user item rank
u3 C 1
u4 C 1

Quick start

Choose where to run Recommender, 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 'recommender' AS recommender (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-recommender'
);

3. Run a query

query.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
More example queries →
Technical details
Verified connector release
v0.5.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 'recommender' AS recommender (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-recommender'
);

Overview

Collaborative-filtering recommendation worker (implicit-feedback ALS) for DuckDB via VGI.

Catalog

Everything recommender exposes once attached — read straight from the worker's released build.

recommender 1 schema
main 1 view · 3 functions

Recommendation table functions: recommend_all, similar_items, recommend_for.

Schema examples (6)
Examples (6)

Top-3 recommended items per user (recommend_all), ranked best-first.

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;
Result
user item rank
u3 C 1
u4 C 1

Top-2 nearest-neighbour items per item (similar_items) by ALS cosine.

SELECT item, similar_item, rank
FROM recommender.main.similar_items((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 := 2)
ORDER BY item, rank;

Top-2 recommendations for one target user (recommend_for), ranked best-first.

SELECT item, rank
FROM recommender.main.recommend_for((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', target_user := 'u3', n := 2)
ORDER BY rank;

Explain each viewer's top recommendation (recommend_all) with the title they already watched that is most similar to it (similar_items), e.g. cal gets Matrix because of Dune.

WITH plays AS (SELECT * FROM (VALUES ('ana','Alien',3.0),('ana','Dune',2.0),('ana','Matrix',4.0),('ben','Alien',1.0),('ben','Dune',5.0),('ben','Matrix',2.0),('ben','Blade Runner',3.0),('cal','Dune',2.0),('cal','Blade Runner',4.0),('dee','Notebook',5.0),('dee','Titanic',2.0),('dee','Amelie',3.0),('eve','Notebook',2.0),('eve','Titanic',4.0),('fay','Titanic',3.0),('fay','Amelie',2.0),('fay','Alien',1.0)) AS t(viewer, title, n_plays)), recs AS (SELECT user AS viewer, item AS title FROM recommender.main.recommend_all((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', n := 1)), sims AS (SELECT item, similar_item, similarity FROM recommender.main.similar_items((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', n := 10)) SELECT r.viewer, r.title AS recommended, arg_max(s.similar_item, s.similarity) AS because_you_watched, round(max(s.similarity), 3) AS similarity
FROM recs r
JOIN plays p ON p.viewer = r.viewer
JOIN sims s ON s.item = r.title AND s.similar_item = p.title
GROUP BY r.viewer, r.title
ORDER BY r.viewer;
2 more examples

Score viewer eve's top-3 ALS recommendations (recommend_for) by their summed item-item similarity to the titles eve watched (similar_items) -- a second, item-based signal to compare or blend with the ALS ranking.

WITH plays AS (SELECT * FROM (VALUES ('ana','Alien',3.0),('ana','Dune',2.0),('ana','Matrix',4.0),('ben','Alien',1.0),('ben','Dune',5.0),('ben','Matrix',2.0),('ben','Blade Runner',3.0),('cal','Dune',2.0),('cal','Blade Runner',4.0),('dee','Notebook',5.0),('dee','Titanic',2.0),('dee','Amelie',3.0),('eve','Notebook',2.0),('eve','Titanic',4.0),('fay','Titanic',3.0),('fay','Amelie',2.0),('fay','Alien',1.0)) AS t(viewer, title, n_plays)), recs AS (SELECT item AS title, score, rank FROM recommender.main.recommend_for((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', target_user := 'eve', n := 3)), sims AS (SELECT item, similar_item, similarity FROM recommender.main.similar_items((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', n := 10)) SELECT r.rank, r.title, round(r.score, 3) AS als_score, round(sum(s.similarity), 3) AS item_similarity_support
FROM recs r
JOIN plays p ON p.viewer = 'eve'
JOIN sims s ON s.item = r.title AND s.similar_item = p.title
GROUP BY r.rank, r.title, r.score
ORDER BY r.rank;

Top recommendation per user from the built-in sample dataset (recommend_all over sample_interactions), joined back to the dataset to count how many users already interacted with the recommended item: u3 and u4 both get C, which 2 users already have.

WITH recs AS (SELECT "user", item FROM recommender.main.recommend_all((SELECT * FROM recommender.main.sample_interactions), n := 1)) SELECT r."user", r.item, count(DISTINCT s."user") AS users_already_interacted
FROM recs r
JOIN recommender.main.sample_interactions s ON s.item = r.item
GROUP BY r."user", r.item
ORDER BY r."user";
Views
sample_interactions 4 examples3 cols

Built-in sample (user, item, value) interaction dataset to browse and feed to the functions.

Columns
user VARCHAR
Interacting user id (original, as supplied).
item VARCHAR
Interacted item id (original, as supplied).
value DECIMAL(2,1)
Interaction strength / confidence (all 1.0 in this sample).
Examples (4)

Count how many interactions each user has in the sample dataset.

SELECT "user", count(*) AS interactions
FROM recommender.main.sample_interactions
GROUP BY 1
ORDER BY 1;

Feed the sample dataset straight into recommend_all (default role args).

SELECT "user", item, rank
FROM recommender.main.recommend_all((SELECT * FROM recommender.main.sample_interactions), n := 3)
ORDER BY 1, rank;

Top recommendation per user from the built-in sample dataset (recommend_all over sample_interactions), joined back to the dataset to count how many users already interacted with the recommended item: u3 and u4 both get C, which 2 users already have.

WITH recs AS (SELECT "user", item FROM recommender.main.recommend_all((SELECT * FROM recommender.main.sample_interactions), n := 1)) SELECT r."user", r.item, count(DISTINCT s."user") AS users_already_interacted
FROM recs r
JOIN recommender.main.sample_interactions s ON s.item = r.item
GROUP BY r."user", r.item
ORDER BY r."user";
1 more example

Recommend the novel item C to users u3 and u4 from the sample dataset.

SELECT "user", item
FROM recommender.main.recommend_all((SELECT * FROM recommender.main.sample_interactions), n := 1)
WHERE "user" IN ('u3', 'u4')
ORDER BY 1;
Link
Table in-out functions
recommend_all (data TABLE, factors := BIGINT, item := VARCHAR, n := BIGINT, user := VARCHAR, value := VARCHAR) 3 examples

Collaborative-filtering: fit implicit-feedback ALS, emit top-N recommended items per user (excluding already-seen items) as (user, item, score, rank). value is the interaction strength (confidence); defaults to 1.0 if absent.

Positional arguments
data TABLE
Relation of (user, item, value) interactions.
Named arguments
factors := BIGINT
ALS latent-factor count. · default 50
item := VARCHAR
Item-id column. · default "item"
n := BIGINT
Recommendations per user. · default 10
user := VARCHAR
User-id column. · default "user"
value := VARCHAR
Interaction-strength column (defaults to 1.0 if absent). · default "value"
Returns columns
user VARCHAR
User id (original, as supplied).
item VARCHAR
Recommended item id (not previously interacted with).
score DOUBLE
ALS recommendation score (higher = stronger).
rank INTEGER
Rank within this user's recommendations (1 = best).
Examples (3)

Top-3 recommendations per user over an inline interaction relation.

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;
Result
user item rank
u3 C 1
u4 C 1

Recommend novel item C to users u3 and u4 (planted CF signal).

SELECT user, item
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 := 1)
WHERE user IN ('u3', 'u4')
ORDER BY user;

Explain each viewer's top recommendation (recommend_all) with the title they already watched that is most similar to it (similar_items), e.g. cal gets Matrix because of Dune.

WITH plays AS (SELECT * FROM (VALUES ('ana','Alien',3.0),('ana','Dune',2.0),('ana','Matrix',4.0),('ben','Alien',1.0),('ben','Dune',5.0),('ben','Matrix',2.0),('ben','Blade Runner',3.0),('cal','Dune',2.0),('cal','Blade Runner',4.0),('dee','Notebook',5.0),('dee','Titanic',2.0),('dee','Amelie',3.0),('eve','Notebook',2.0),('eve','Titanic',4.0),('fay','Titanic',3.0),('fay','Amelie',2.0),('fay','Alien',1.0)) AS t(viewer, title, n_plays)), recs AS (SELECT user AS viewer, item AS title FROM recommender.main.recommend_all((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', n := 1)), sims AS (SELECT item, similar_item, similarity FROM recommender.main.similar_items((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', n := 10)) SELECT r.viewer, r.title AS recommended, arg_max(s.similar_item, s.similarity) AS because_you_watched, round(max(s.similarity), 3) AS similarity
FROM recs r
JOIN plays p ON p.viewer = r.viewer
JOIN sims s ON s.item = r.title AND s.similar_item = p.title
GROUP BY r.viewer, r.title
ORDER BY r.viewer;
Link
recommend_for (data TABLE, factors := BIGINT, item := VARCHAR, n := BIGINT, target_user := VARCHAR, user := VARCHAR, value := VARCHAR) 2 examples

Top-N recommended items for a single specified user, excluding items that user has already interacted with, as (item, score, rank). Returns no rows when the requested user is absent from the interaction relation.

Positional arguments
data TABLE
Relation of (user, item, value) interactions.
Named arguments
factors := BIGINT
ALS latent-factor count. · default 50
item := VARCHAR
Item-id column. · default "item"
n := BIGINT
Number of recommendations. · default 10
target_user := VARCHAR
Id of the single user to recommend for.
user := VARCHAR
User-id column. · default "user"
value := VARCHAR
Interaction-strength column (defaults to 1.0 if absent). · default "value"
Returns columns
item VARCHAR
Recommended item id (not previously interacted with).
score DOUBLE
ALS recommendation score (higher = stronger).
rank INTEGER
Rank within the recommendations (1 = best).
Examples (2)

Top-2 recommendations for a single target user (u3).

SELECT item, rank
FROM recommender.main.recommend_for((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', target_user := 'u3', n := 2)
ORDER BY rank;

Score viewer eve's top-3 ALS recommendations (recommend_for) by their summed item-item similarity to the titles eve watched (similar_items) -- a second, item-based signal to compare or blend with the ALS ranking.

WITH plays AS (SELECT * FROM (VALUES ('ana','Alien',3.0),('ana','Dune',2.0),('ana','Matrix',4.0),('ben','Alien',1.0),('ben','Dune',5.0),('ben','Matrix',2.0),('ben','Blade Runner',3.0),('cal','Dune',2.0),('cal','Blade Runner',4.0),('dee','Notebook',5.0),('dee','Titanic',2.0),('dee','Amelie',3.0),('eve','Notebook',2.0),('eve','Titanic',4.0),('fay','Titanic',3.0),('fay','Amelie',2.0),('fay','Alien',1.0)) AS t(viewer, title, n_plays)), recs AS (SELECT item AS title, score, rank FROM recommender.main.recommend_for((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', target_user := 'eve', n := 3)), sims AS (SELECT item, similar_item, similarity FROM recommender.main.similar_items((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', n := 10)) SELECT r.rank, r.title, round(r.score, 3) AS als_score, round(sum(s.similarity), 3) AS item_similarity_support
FROM recs r
JOIN plays p ON p.viewer = 'eve'
JOIN sims s ON s.item = r.title AND s.similar_item = p.title
GROUP BY r.rank, r.title, r.score
ORDER BY r.rank;
Link
similar_items (data TABLE, factors := BIGINT, item := VARCHAR, n := BIGINT, user := VARCHAR, value := VARCHAR) 3 examples

Item-item collaborative filtering: top-N most similar items per item by cosine of the ALS item factors, as (item, similar_item, similarity, rank).

Positional arguments
data TABLE
Relation of (user, item, value) interactions.
Named arguments
factors := BIGINT
ALS latent-factor count. · default 50
item := VARCHAR
Item-id column. · default "item"
n := BIGINT
Similar items per item. · default 10
user := VARCHAR
User-id column. · default "user"
value := VARCHAR
Interaction-strength column (defaults to 1.0 if absent). · default "value"
Returns columns
item VARCHAR
Item id (original, as supplied).
similar_item VARCHAR
A similar item id.
similarity DOUBLE
Cosine similarity of ALS item factors (1 = identical).
rank INTEGER
Rank within this item's neighbours (1 = most similar).
Examples (3)

Top-2 most similar items for every item in an inline relation.

SELECT item, similar_item, rank
FROM recommender.main.similar_items((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 := 2)
ORDER BY item, rank;

Explain each viewer's top recommendation (recommend_all) with the title they already watched that is most similar to it (similar_items), e.g. cal gets Matrix because of Dune.

WITH plays AS (SELECT * FROM (VALUES ('ana','Alien',3.0),('ana','Dune',2.0),('ana','Matrix',4.0),('ben','Alien',1.0),('ben','Dune',5.0),('ben','Matrix',2.0),('ben','Blade Runner',3.0),('cal','Dune',2.0),('cal','Blade Runner',4.0),('dee','Notebook',5.0),('dee','Titanic',2.0),('dee','Amelie',3.0),('eve','Notebook',2.0),('eve','Titanic',4.0),('fay','Titanic',3.0),('fay','Amelie',2.0),('fay','Alien',1.0)) AS t(viewer, title, n_plays)), recs AS (SELECT user AS viewer, item AS title FROM recommender.main.recommend_all((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', n := 1)), sims AS (SELECT item, similar_item, similarity FROM recommender.main.similar_items((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', n := 10)) SELECT r.viewer, r.title AS recommended, arg_max(s.similar_item, s.similarity) AS because_you_watched, round(max(s.similarity), 3) AS similarity
FROM recs r
JOIN plays p ON p.viewer = r.viewer
JOIN sims s ON s.item = r.title AND s.similar_item = p.title
GROUP BY r.viewer, r.title
ORDER BY r.viewer;

Score viewer eve's top-3 ALS recommendations (recommend_for) by their summed item-item similarity to the titles eve watched (similar_items) -- a second, item-based signal to compare or blend with the ALS ranking.

WITH plays AS (SELECT * FROM (VALUES ('ana','Alien',3.0),('ana','Dune',2.0),('ana','Matrix',4.0),('ben','Alien',1.0),('ben','Dune',5.0),('ben','Matrix',2.0),('ben','Blade Runner',3.0),('cal','Dune',2.0),('cal','Blade Runner',4.0),('dee','Notebook',5.0),('dee','Titanic',2.0),('dee','Amelie',3.0),('eve','Notebook',2.0),('eve','Titanic',4.0),('fay','Titanic',3.0),('fay','Amelie',2.0),('fay','Alien',1.0)) AS t(viewer, title, n_plays)), recs AS (SELECT item AS title, score, rank FROM recommender.main.recommend_for((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', target_user := 'eve', n := 3)), sims AS (SELECT item, similar_item, similarity FROM recommender.main.similar_items((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', n := 10)) SELECT r.rank, r.title, round(r.score, 3) AS als_score, round(sum(s.similarity), 3) AS item_similarity_support
FROM recs r
JOIN plays p ON p.viewer = 'eve'
JOIN sims s ON s.item = r.title AND s.similar_item = p.title
GROUP BY r.rank, r.title, r.score
ORDER BY r.rank;
Link

Try these queries

Top-2 nearest-neighbour items per item (similar_items) by ALS cosine.

SELECT item, similar_item, rank
FROM recommender.main.similar_items((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 := 2)
ORDER BY item, rank

Uses similar_items

Top-2 recommendations for one target user (recommend_for), ranked best-first.

SELECT item, rank
FROM recommender.main.recommend_for((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', target_user := 'u3', n := 2)
ORDER BY rank

Uses recommend_for

Explain each viewer's top recommendation (recommend_all) with the title they already watched that is most similar to it (similar_items), e.g. cal gets Matrix because of Dune.

WITH plays AS (SELECT * FROM (VALUES ('ana','Alien',3.0),('ana','Dune',2.0),('ana','Matrix',4.0),('ben','Alien',1.0),('ben','Dune',5.0),('ben','Matrix',2.0),('ben','Blade Runner',3.0),('cal','Dune',2.0),('cal','Blade Runner',4.0),('dee','Notebook',5.0),('dee','Titanic',2.0),('dee','Amelie',3.0),('eve','Notebook',2.0),('eve','Titanic',4.0),('fay','Titanic',3.0),('fay','Amelie',2.0),('fay','Alien',1.0)) AS t(viewer, title, n_plays)), recs AS (SELECT user AS viewer, item AS title FROM recommender.main.recommend_all((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', n := 1)), sims AS (SELECT item, similar_item, similarity FROM recommender.main.similar_items((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', n := 10)) SELECT r.viewer, r.title AS recommended, arg_max(s.similar_item, s.similarity) AS because_you_watched, round(max(s.similarity), 3) AS similarity
FROM recs r
JOIN plays p ON p.viewer = r.viewer
JOIN sims s ON s.item = r.title AND s.similar_item = p.title
GROUP BY r.viewer, r.title
ORDER BY r.viewer

Uses recommend_allsimilar_items

Score viewer eve's top-3 ALS recommendations (recommend_for) by their summed item-item similarity to the titles eve watched (similar_items) -- a second, item-based signal to compare or blend with the ALS ranking.

WITH plays AS (SELECT * FROM (VALUES ('ana','Alien',3.0),('ana','Dune',2.0),('ana','Matrix',4.0),('ben','Alien',1.0),('ben','Dune',5.0),('ben','Matrix',2.0),('ben','Blade Runner',3.0),('cal','Dune',2.0),('cal','Blade Runner',4.0),('dee','Notebook',5.0),('dee','Titanic',2.0),('dee','Amelie',3.0),('eve','Notebook',2.0),('eve','Titanic',4.0),('fay','Titanic',3.0),('fay','Amelie',2.0),('fay','Alien',1.0)) AS t(viewer, title, n_plays)), recs AS (SELECT item AS title, score, rank FROM recommender.main.recommend_for((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', target_user := 'eve', n := 3)), sims AS (SELECT item, similar_item, similarity FROM recommender.main.similar_items((SELECT viewer, title, n_plays FROM plays), user := 'viewer', item := 'title', value := 'n_plays', n := 10)) SELECT r.rank, r.title, round(r.score, 3) AS als_score, round(sum(s.similarity), 3) AS item_similarity_support
FROM recs r
JOIN plays p ON p.viewer = 'eve'
JOIN sims s ON s.item = r.title AND s.similar_item = p.title
GROUP BY r.rank, r.title, r.score
ORDER BY r.rank

Uses recommend_forsimilar_items

Top recommendation per user from the built-in sample dataset (recommend_all over sample_interactions), joined back to the dataset to count how many users already interacted with the recommended item: u3 and u4 both get C, which 2 users already have.

WITH recs AS (SELECT "user", item FROM recommender.main.recommend_all((SELECT * FROM recommender.main.sample_interactions), n := 1)) SELECT r."user", r.item, count(DISTINCT s."user") AS users_already_interacted
FROM recs r
JOIN recommender.main.sample_interactions s ON s.item = r.item
GROUP BY r."user", r.item
ORDER BY r."user"

Uses recommend_allsample_interactions

Count how many interactions each user has in the sample dataset.

SELECT "user", count(*) AS interactions
FROM recommender.main.sample_interactions
GROUP BY 1
ORDER BY 1

Uses sample_interactions

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

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