0019. Recommended+: a mixed feed of four kinds of picks, fed by a slow YouTube gatherer¶
Status: Accepted (now the only Recommended tab: 0026)
Context¶
People who open YouTube "to find something to watch" want a feed that knows them: new uploads from the creators they follow, more of what they have been watching, now and then a channel they have never seen, and sometimes something they used to like. Horde already ranked the library ("For you", services/ai/recommend.py) and could add followed channels' indexed uploads, but it never looked past the library and the catalogs, and it never learnt from videos watched as streams (no history was kept for them).
Two limits shape any answer. YouTube has no public recommendation API, and every request Horde makes counts against the same bot checks as downloads; a feed that called YouTube per page view would get the server blocked. And recommendations must stay sensible with or without an embedding model, on any embed model (their cosine scales differ a lot), and for households of a few people (no collaborative filtering at scale).
Decision¶
- Three home tabs. Library (the archive), Recommended (the existing shelf, now over the library plus every indexed catalog, not only followed channels), and Recommended+ (
services/discovery/,GET /api/discover/feed), which adds videos found on YouTube. - Gather slowly, rank locally. A background worker (
discovery/gather.py) asks YouTube for candidates only for people who opened Recommended+ in the last 3 days, at most every 6 hours each (a refresh at most every 20 minutes): up to 4 searches built from their interests and 3 "up next" lists of videos they liked. Every request goes through the global extract gate at background priority; at most 30 calls an hour for everyone, 20 seconds apart; a bot check or rate limit pauses all gathering for 30 minutes, doubling up to 12 hours; a search or seed is not repeated for 4 (7) days. Found videos are stored (discovery_videos,discovery_hits), embedded with the library's embed model, and forgotten after 21 days. Page views never reach YouTube. - Searches from interests. The history splits into recent (30 days, widened to 60 in a quiet month) and older (60 days to 3 years) watches, each grouped by spherical k-means over embeddings (by channel without AI). An older group close to a recent one is not "dormant". The chat model writes two searches per group aimed at other creators; without one, the group's distinctive title words (TF-IDF against the rest of the history) and its top tags make the search. One search in four is for a dormant interest. The first search of a recent group is limited to this year's uploads.
- "Up next" through yt-dlp's own parsers. yt-dlp does not extract related videos, so
ytdlp_extract.youtube_up_nextcalls YouTube'snextendpoint through yt-dlp's client and reads the cards with yt-dlp'sYoutubeTabIErenderer parsers, which follow YouTube's layout changes with each yt-dlp release; a failure only skips that source. - Four buckets, mixed by share. Every unwatched candidate lands in one bucket: subscriptions (recent uploads of followed or currently watched channels), similar (known channels), new (channels never watched; a video already downloaded is never one, since 1.4.1) and throwback (dormant interests or channels watched long ago and not lately). Shares 30/30/25/15 by smooth weighted round robin; when a bucket runs dry its share goes mostly to the familiar ones (new and throwback stay at most 35% and 18%). The same channel appears at most once in 5 slots; a new channel at most twice and a throwback channel three times before the end of the feed. Within a bucket a smaller interest is pulled forward when it has had less than its share of the history.
- Relevance on a calibrated scale. A candidate's fit is 60% its closest recent watch and 40% its closest interest centre, scaled so 1 means "as close as the user's own recent watches are to each other" and 0 the bottom tenth of all candidates. That keeps floors (similar 0.45, new 0.6, throwback 0.55) meaningful across embed models and when the pool is mostly relevant.
- Feedback and wear. "Not interested", "don't recommend this channel" and dismissed channel suggestions (
rec_feedback) apply to both recommendation tabs and the gatherer. Each visit a video is shown on without being watched lowers it (rec_impressions); after six it drops to the end. A small seeded jitter, larger for new channels, varies the order; Refresh changes the seed. Stream watches are recorded per user (user_stream_state) and count as taste and as watched. - Household, lightly. Library videos that people here with similar channel taste liked get a small lift (switchable,
discovery_household). Nothing says who watched what.
Consequences¶
- Recommended+ costs at most 7 YouTube calls (a search can be two or three HTTP requests) per active person every 6 hours, spread behind interactive work, and stops on its own when YouTube pushes back. The search words are sent to YouTube;
discovery_enabled(andyoutube_video_search) turn the gathering off, leaving a feed from the library and catalogs. - The first visit has no found videos until the first run (a minute or two); the page polls the gatherer's status and fills in.
- The "up next" source relies on yt-dlp internals (
_extract_response,_extract_lockup_view_model); a yt-dlp change that renames them makes that source fail quietly until fixed, and the unit test that feeds a recorded card shape to the real parser catches it on the yt-dlp bump. - AI spend: the chat model writes a person's searches only when they have the
use_aipermission (otherwise their searches come from keywords). Embedding found videos is server-side work like embedding catalogs, booked to the cost ledger asdiscovery. GET /api/discover/feed(and the For you shelf) record what they showed (rec_impressions) and mark the person active for the gatherer. Nothing is deleted or downloaded by a GET.- Tuning constants live at the top of
discovery/scoring.py(what each kind of pick is scored on, and the floors),mix.py,interests.pyandgather.py; changing them changes every user's feed.