Recommendation systems

From j4flmao/agent-skills · View interactive version

Recommendation systems is an AI agent skill from the GitHub repository j4flmao/agent-skills. Use when the user asks about a recommender system, collaborative filtering, matrix factorization, ALS with implicit feedback, two-tower retrieval, candidate generation and ranking, cold start or recall@k and NDCG. Produces baselines, two-stage architecture and leakage-free offline evaluation. Not fo

How to use this skill

Skill file

Recommendation Systems

Purpose

Rank items for a user (or context) so that they engage, buy, or return. Production systems are usually two-stage: cheap candidate generation over the full catalog, then a richer ranking model over a few hundred candidates. Success is measured with time-split offline ranking metrics first, then with online experiments, because offline gains often fail to transfer.

Agent Protocol

Trigger

"recommendation system", "recommender", "collaborative filtering", "matrix factorization", "ALS", "implicit feedback", "two-tower", "candidate generation", "re-ranking", "cold start", "recall@k", "ndcg@k", "you may also like".

Input Context

Output Artifact

Architecture + model choice + evaluation protocol (+ code). No file unless requested.

Response Format

Feedback: {explicit|implicit} users={n} items={n} density={%}
Baseline: {popularity / item-item}
Candidate gen: {method} Ranker: {method}
Offline eval: {split} {Recall@K, NDCG@K, coverage}
Online: {A/B metric, guardrails}

Completion Criteria

Model Choice

| Situation | Approach |

|-----------|----------|

| Small data, need fast baseline | Popularity (global/segment), item-item co-occurrence or cosine similarity |

| Implicit feedback, medium/large | ALS / weighted matrix factorization, BPR |

| Explicit ratings | Biased matrix factorization (Funk-SVD style) |

| Rich features, large scale | Two-tower retrieval (user tower, item tower) + ANN index, then gradient-boosted or neural ranker |

| Sequence matters (sessions) | Sequential models (GRU4Rec, SASRec-style transformers) |

| New items with content | Content embeddings (text/image) blended with CF (hybrid) |

Implicit Feedback

Clicks/views are positive-only signals with noise; absence is not a negative. Weight by confidence (e.g. 1 + α·count), sample negatives for training, and debias for position/exposure when using logged data.

Example: ALS on Implicit Data (`implicit` library)

import numpy as np
import scipy.sparse as sp
from implicit.als import AlternatingLeastSquares

# interactions: arrays of user_idx, item_idx, counts (already mapped to 0..n-1)
user_items = sp.csr_matrix((counts.astype(np.float32), (user_idx, item_idx)),
                           shape=(n_users, n_items))
alpha = 20.0
model = AlternatingLeastSquares(factors=64, regularization=0.05, iterations=20)
model.fit(alpha * user_items)                      # rows = users, cols = items

ids, scores = model.recommend(user_id, user_items[user_id], N=10,
                              filter_already_liked_items=True)
similar_ids, sim_scores = model.similar_items(item_id, N=10)

Example: Explicit Ratings (Surprise)

from surprise import SVD, Dataset
from surprise.model_selection import cross_validate

data = Dataset.load_builtin("ml-100k")            # downloads MovieLens 100k on first use
algo = SVD(n_factors=100, reg_all=0.02)            # biased MF trained with SGD, not a true SVD
results = cross_validate(algo, data, measures=["RMSE", "MAE"], cv=5)
print(results["test_rmse"].mean())

RMSE on ratings rarely correlates with ranking quality; use it only when predicting a rating is the product requirement.

Two-Stage Architecture

user/context → candidate generators (two-tower ANN, item-item, popular, recent) → ~500 candidates
            → feature join (user, item, cross, real-time) → ranker (GBDT / DNN) → business rules
            (dedupe, diversity, freshness, filters) → top-K shown → log impressions + outcomes

Log impressions (what was shown), not only clicks, so you can build unbiased training data and compute CTR.

Offline Evaluation

| Metric | Use |

|--------|-----|

| Recall@K / HitRate@K | Candidate generation: did the true item make the list? |

| NDCG@K, MAP@K, MRR | Ranking quality with position discount |

| Coverage, diversity, novelty | Catalog health; avoid popularity collapse |

| Calibration / AUC | Ranker click-probability models |

Protocol: train on interactions before time T, evaluate on after T; rank against the full catalog (or a large, documented negative sample, since sampled metrics can change model rankings).

Cold Start

Anti-Patterns

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.