AI Wiki中文/EN

Recommender systems: ranking cannot recover a missing candidate

推荐系统概览

Follow a time-safe recommendation pipeline and compare popularity, candidate recall and personalized rules.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

The useful item never reached the ranker

Imagine a reading app with seven articles. Ada has read a space article. The two most popular eligible articles concern music; two less popular space articles would match her interests. A clever ranker receiving only those two music candidates cannot recommend a space article. The omission happened before ranking.

A recommender system selects useful items for a user under a particular context and set of constraints. Collaborative methods use patterns across users’ interactions; content-based methods use item attributes and a user profile. These are sources of evidence, not complete product architectures. Koren and colleagues contrast neighborhood and latent-factor approaches; Pazzani and Billsus explain content profiles and their dependence on the available attributes. Factorization overview, PDF 2–3 Content-based systems, PDF 2–3

This article follows the decision pipeline. The neighboring articles develop collaborative filtering and content-based recommendation as actual scoring methods. Our pipeline uses an authored rule so that each failure remains visible.

Candidate inclusion limits what ranking can recover; future events inflate historical counts.
Candidate inclusion limits what ranking can recover; future events inflate historical counts.

Keep the decision’s time boundary intact

Let an interaction be a user, item and timestamp triple. At decision time t, training history must contain only information already available:

D≤t={(u,i,τ):τ≤t}.D_{\le t}=\{(u,i,\tau):\tau\le t\}.

The timestamp must represent when information became available to the system. A retrospectively backfilled event with an earlier occurrence date can still leak information. In the example, all events are assumed available at their recorded integer time.

Let E contain items that are released, currently available and not already consumed by the user. The last condition is our reading-app policy; repeat music listening would require another policy. Candidate generation returns C, and ranking returns a list L of at most k distinct items:

Lk(u,t)⊆C(u,t)⊆E(u,t).L_k(u,t)\subseteq C(u,t)\subseteq E(u,t).

For a nonempty independently specified relevant set R inside E, this immediately gives a recall ceiling:

Recall@⁡k=∣Lk∩R∣∣R∣≤∣C∩R∣∣R∣=CandidateRecall⁡.\operatorname{Recall@}k=\frac{|L_k\cap R|}{|R|}\le\frac{|C\cap R|}{|R|}=\operatorname{CandidateRecall}.

Changing the scoring function cannot break a set-inclusion constraint. If R is empty, recall is undefined here; the program returns None, not a made-up perfect score. For real evaluation, define relevance, label collection, eligibility and candidate budget together. An offline metric measures agreement with those labels; it does not itself measure satisfaction caused by displaying the list.

Our non-AI baseline sorts eligible items by historical interaction count. The personalized rule adds a category bonus based on Ada’s distinct consumed items:

s(u,i)=10 hu(category⁡(i))+count⁡D≤t(i). s(u,i)=10\,h_u(\operatorname{category}(i))+\operatorname{count}_{D_{\le t}}(i).

The coefficient 10 is an authored teaching choice, not a fitted parameter or a published optimum. Counts include repeated interactions, whereas h counts distinct consumed items by category. Ties use the numeric item ID, making the experiment deterministic. The Recommenders project separates data preparation, models, offline evaluation, model selection and operation; that separation is useful when deciding which stage a test actually covers. Pinned README, lines 33–43

Three lists from the same seven items

Run the following complete program with Python 3.12; it uses only the standard library. Items are numbered 0–6. Item 4 is unavailable, item 6 is released at time 12, and Ada has consumed item 0. The decision time is 10. Relevance labels {1,5} are authored for this example, not inferred from a real reader study.

"""Original recommendation pipeline: time boundary, eligibility, candidates, ranking."""
import json
from collections import Counter

ITEMS = [dict(id=i, category=c, released=12 if i==6 else 0, available=i!=4)
         for i,c in enumerate(['space','space','music','music','garden','space','space'])]


def before(events, cutoff):
    if any(len(e)!=3 or not isinstance(e[2],int) for e in events):
        raise ValueError('events must be (user, item, integer time)')
    return [e for e in events if e[2]<=cutoff]


def eligible(items, history, cutoff):
    if len({i['id'] for i in items})!=len(items):raise ValueError('unique item IDs required')
    return [i for i in items if i['available'] and i['released']<=cutoff and i['id'] not in history]


def recommend(events, user, cutoff, pool=4, size=2, items=ITEMS, personalize=True):
    if not isinstance(pool,int) or pool<0 or not isinstance(size,int) or size<0:raise ValueError('nonnegative budgets required')
    train=before(events,cutoff);pop=Counter(i for u,i,t in train);catalog={i['id']:i for i in items}
    if any(i not in catalog for u,i,t in train):raise ValueError('unknown catalog item')
    history={i for u,i,t in train if u==user};liked=Counter(catalog[i]['category'] for i in history)
    allowed=eligible(items,history,cutoff)
    candidates=sorted(allowed,key=lambda i:(-pop[i['id']],i['id']))[:pool]
    def score(item):return (10*liked[item['category']] if personalize else 0)+pop[item['id']]
    ranked=sorted(candidates,key=lambda i:(-score(i),i['id']))[:size]
    return dict(eligible=[i['id'] for i in allowed],candidates=[i['id'] for i in candidates],
                recommendations=[i['id'] for i in ranked],training_events=len(train),
                popularity={str(i['id']):pop[i['id']] for i in items})


def recall(result, relevant):
    return len(set(result)&set(relevant))/len(set(relevant)) if relevant else None


def fixture():
    events=[('Ada',0,1)]
    for item,count in [(1,2),(2,5),(3,4),(4,7),(5,1)]:
        events.extend((f'reader-{j}',item,2+j) for j in range(count))
    events.extend(('Ada',1,11+j) for j in range(12))
    return events


def demo():
    events=fixture();relevant={1,5};rows=[]
    for label,pool,personalize in [('popular',4,False),('narrow',2,True),('wider',4,True)]:
        r=recommend(events,'Ada',10,pool=pool,personalize=personalize)
        r.update(name=label,candidate_recall=recall(r['candidates'],relevant),recall_at_2=recall(r['recommendations'],relevant));rows.append(r)
    return dict(rows=rows,relevant=sorted(relevant),past_events=len(before(events,10)),future_events=len(events)-len(before(events,10)),
                future_leaky_count=Counter(i for u,i,t in events)[1],honest_count=Counter(i for u,i,t in before(events,10))[1])


if __name__=='__main__':print(json.dumps(demo(),allow_nan=False))

There are 20 past events and 12 future events. Eligibility leaves [1,2,3,5]. Popularity returns [2,3], giving recall@2 of 0. Applying the personalized rule to a two-item candidate pool still returns [2,3]. Expanding the pool to four items lets that same rule return [1,5], giving recall 1. This demonstrates a mechanism, not a measured business improvement.

Item 1 has 2 interactions by the cutoff. Counting future events would raise that number to 14. The added events make an answer look more informed by giving it information unavailable at decision time. Tests append even more future events and verify that the legitimate output stays unchanged.

For M events, N items, candidate budget B and output size k, this simple implementation scans events and sorts all eligible items: O(M + N log N + B log B) time, with O(M + N) working storage. It materializes the filtered events and does not use an index. A large service needs indexed eligibility and candidate generation; increase B only with a measured latency and memory budget. Outputting more candidates also leaves more work for the ranker.

An accurate list can still be a poor intervention

The program treats every past interaction as evidence of interest. Accidental clicks, repeated exposure and interface position can distort that evidence. An unpersonalized fallback is useful for a new user, but popularity can repeatedly favor already visible items. Attribute profiles can score new items when metadata exists, yet cannot recover preferences absent from the profile. Content profiles and limitations, PDF 5–7 and 16

For a deployment exercise, freeze a training cutoff, tune on a later validation interval, and assess once on a separate later test interval. Log availability as it was at each decision, not only as it is today. Report ranking quality alongside empty-result frequency, coverage, repeat rate and latency, with the population and measurement window stated. A controlled online comparison can test user outcomes; this small offline calculation cannot establish them. Retain the popularity fallback if personalization fails to produce eligible results.

Find the stage that failed

  1. A ranker is perfect within C, but C contains none of R. What is recall? Answer: Zero. Every possible output is disjoint from R; the candidate generator must change.
  2. C contains one of two relevant items. What is its recall ceiling? Answer: One half, even if that item is ranked first. A small output budget may lower achieved recall further.
  3. Why does item 1 have counts 2 and 14 in the demonstration? Answer: The first excludes 12 future events; the second includes them. Only 2 is available at the time-10 decision.
  4. Should a music app always exclude consumed items as this program does? Answer: No. Repeated listening may be the desired action. Specify the product’s eligibility policy before treating repeats as an error.

From model families to a measured system

The two surveys support the distinction between interaction-based and attribute-based evidence. The pinned GitHub README supplies a workflow map, not proof of performance. Here, candidate inclusion, time leakage and complexity are derived from the disclosed original program. No upstream code, user data or benchmark scores were copied. Extend the example by changing one eligibility rule or candidate budget, then explain which outputs can change before running it.

Make a prediction, then check

Can a ranker recover an item absent from its candidate pool?

Choose one answer

Learning objectives

  • Separate eligibility, candidate generation, ranking and outcome measurement.
  • Run the original example, check its numerical result and explain one failure condition.

Prerequisites & connections

Explore related knowledge →

References

  1. Matrix Factorization Techniques for Recommender Systems
    Yehuda Koren; Robert Bell; Chris Volinsky · 2009
  2. Content-based Recommendation Systems
    Michael J. Pazzani; Daniel Billsus · 2007
  3. Recommenders README — pinned pre-cutoff workflow
    Recommenders contributors · 2026

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-23 · Single AI author. Scoped reading: Physical PDF 1 identity, 2–4 methods text; viewed page 4 equations. Observed ratings, biases, SGD/ALS. No benchmark reproduction. Physical PDF 1 identity and 2–3, 5–7, 10–12, 16 text: item features, profiles, linear regression, Rocchio and limits. Figures not visually reviewed. README lines 33–43 read: data, modeling, offline evaluation, selection and operation. Repository not executed; not an independent performance audit. 4 paired equations and four explained exercises. Checked temporal availability, eligibility, candidate ceiling, counts 2 versus leaky14, cold-user fallback and three rule-based lists. Authored labels, no trained ranker or online gain.

  • Checked temporal availability, eligibility, candidate ceiling, counts 2 versus leaky14, cold-user fallback and three rule-based lists. Authored labels, no trained ranker or online gain.
  • Four computed SVG variants per topic;11 numeric/geometry tests and36 responsive cases passed. Twelve selected captures visually checked;11 current images match previously viewed bytes and the revised matrix-factorization image was viewed again. Full article acceptance recorded separately.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.