For You ranking
The for_you block of a ranking config turns on ranking features built for the foryou feed group: ready-made ranking presets, ranking variables that learn from each user's behavior, an exploration slot for new content, and long-dwell tracking. Everything in it is opt-in. A group without for_you ranks exactly as before.
For the basics of a "for you" style feed (selectors, interest tags and reasons), start with the For You feed guide.
Turning it on
Set ranking.for_you.enabled on the foryou feed group. The example below uses the for_you_v2 preset instead of writing a score, and also turns on the exploration slot and long dwells. Updating a feed group replaces its configuration, so the example sends the activity selectors too, each with the same 2 day cutoff window the group's default selectors use.
$feedsClient->updateFeedGroup('foryou', new GeneratedModels\UpdateFeedGroupRequest(
activitySelectors: [
new GeneratedModels\ActivitySelectorConfig(type: 'following', cutoffWindow: '2d'),
new GeneratedModels\ActivitySelectorConfig(type: 'popular', cutoffWindow: '2d'),
new GeneratedModels\ActivitySelectorConfig(type: 'interest', cutoffWindow: '2d'),
],
ranking: new GeneratedModels\RankingConfig(
type: 'expression',
forYou: new GeneratedModels\ForYouConfig(
enabled: true,
preset: 'for_you_v2',
exploration: new GeneratedModels\ForYouExplorationConfig(enabled: true, slot: 15),
dwell: new GeneratedModels\ForYouDwellConfig(enabled: true, thresholdMs: 5000),
),
),
));Rules for the for_you block:
- On a feed group it is accepted only on the
foryougroup, and only when that group is not aggregated. - A feed view can carry a
for_youblock too. It applies only when the view is read on theforyougroup, and is ignored elsewhere. enabled: falseturns everyfor_youfeature off, whatever else the block contains.
| Field | Description | Default |
|---|---|---|
enabled |
Turns For You ranking on. Required by every other field. | false |
preset |
A ready-made ranking formula used when score is empty: for_you_v2 or hot. See Presets. |
- |
exploration |
The exploration slot. See Exploration. | off |
dwell |
Long-dwell tracking. See Long dwells. | off |
trending |
Trending topics and the topic_trend variable. See Trending topics. |
false |
analytics |
Engagement analytics per feed view. See Experiments and analytics. | false |
experiment |
A/B test between feed views. See Experiments and analytics. | - |
Presets
A preset is a ranking formula Stream maintains, so you don't have to write and tune a score yourself. Set preset and leave score empty.
| Preset | What it ranks for |
|---|---|
for_you_v2 |
Engagement (reactions, comments, shares and bookmarks, each on a log scale), the user's show more/less feedback, freshness (half the weight after a day), a lift for posts from people the user follows or whose friends engaged, a penalty for posts many users hid or asked to see less of, and a boost for authors the user often engages with. |
hot |
What is popular right now: reactions, comments and shares on a log scale, with a 12 hour half-life. |
The for_you_v2 formula:
(ln(1 + reaction_count) + 3 * ln(1 + comment_count) + 4 * ln(1 + share_count) + 2 * ln(1 + bookmark_count) + 4 * preference_score)
* decay_exp(time) // scale 1d, offset 2h, decay 0.5
* (selector_source == "following" || selector_source == "friends_engaged" ? 1.0 : 0.75)
* (neg_feedback >= 3 ? 1.0 - min(0.5, 0.1 * neg_feedback) : 1.0)
* (1 + 0.5 * author_affinity)The hot formula:
ln(1 + reaction_count + 2 * comment_count + 3 * share_count) * decay_exp(time) // scale 12h, offset 1h, decay 0.5- A
scoreyou set takes precedence over the preset. Copy a preset's formula intoscoreto tune it. - With a preset and no
score,functionsanddefaultsare rejected, because the preset brings its own. - An unknown preset name is rejected.
- Set
include_ranking_config: trueon a server-side feed read to see the expanded formula the feed was ranked with.
For You ranking variables
These variables can be used in score only when the same ranking has for_you.enabled. A config that uses one without it is rejected.
| Variable | Value |
|---|---|
neg_feedback |
How many users currently hide the activity or chose to see less of it, through activity feedback. |
impressions_bucket |
How many times the activity was shown in For You feeds, as floor(log2(impressions)): 0 for 1 impression, 3 for 8 to 15, 10 for 1024 to 2047. Counts impressions sent with a request_id within a 48 hour window, and never goes down. Updated about once a minute. See Feed reads and impressions. |
author_affinity |
0 to 1: how much the user engages with the activity's author, from the user's comments (weighted 3), reactions (2), bookmarks (1) and long dwells (1) in the last 30 days, with recent engagement counting more. Any author counts, followed or not. |
is_mutual |
1 when the user and the activity's author follow each other, else 0. |
friends_engagement |
How many of the user's close friends reacted to the activity. Read from the friends_engaged selector; 0 without it. |
topic_trend |
0 to 1: how much the activity's topics are trending. Needs for_you.trending. See Trending topics. |
neg_feedbackandimpressions_bucketare internal: they shape the ranking but are not returned inscore_varsor anywhere else in the API.author_affinity,is_mutualandfriends_engagementare per user. A ranking that uses them is computed per user, likeinterest_score.- A variable that cannot be loaded for a read (for example during an outage) reads 0 for that read. The feed still serves.
For example, to lift posts from authors the user engages with and from mutual follows:
popularity * decay_exp(time) * (1 + author_affinity) * (1 + 0.5 * is_mutual)A boost on author_affinity can let one favourite author fill a page. Pair it with ranking.arrange in diversify mode to cap how many posts per author a page shows.
Exploration
The exploration slot puts one recent, under-exposed activity at a fixed position in each user's ranked feed, so new posts and new creators get a chance to be seen.
{
"for_you": { "enabled": true, "exploration": { "enabled": true, "slot": 15 } }
}slotis the 1-based position, 1 to 100. It defaults to 15.- Candidates are recent activities from the last 24 hours, across the app. Activities that were already shown about 1000 times are skipped.
- The pick balances how many times an activity was shown (
impressions_bucket) against its engagement, so a new post with few impressions gets a chance, and one that keeps getting shown without engagement stops being picked. - The pick is per user and stays the same for about 10 minutes, then a new one is picked. It never repeats an activity the user's feed already contains, the user's own activities, or activities the user hid.
- The picked activity has
selector_source: "exploration"and theexplorationreason. - There is no exploration slot on reads with a request
filterorfilter_tags, or when a selector uses a filter or a feed group scope.
Exploration requires a paid Feeds plan and an authenticated user.
Exploration learns from impressions, so send impressions with the feed's request_id, as described below.
Long dwells
A long dwell is a dwell event at or above the threshold, meaning the user stopped on the activity. Long dwells count toward author_affinity, so a user who reads an author's posts without reacting to them still gets more of that author.
{
"for_you": {
"enabled": true,
"dwell": { "enabled": true, "threshold_ms": 5000 }
}
}threshold_ms is 1000 to 60000 and defaults to 5000. Each user's last 20 long dwells of the past 48 hours are kept, and are deleted with the user's data. Send dwell events as described in Activity metrics.
Long dwells require a paid Feeds plan.
Feed reads and impressions
When exploration, analytics or a ranking using impressions_bucket is on, a feed read by an authenticated user on a paid plan returns:
request_id: a signed token for that read, valid for 48 hours.positionon each activity, only when exploration orimpressions_bucketis on: its 1-based position in the ranked feed, continuing across pages.
Send the request_id, and the activity's position, with the impressions, clicks and dwell events you track for activities from that read. See Activity metrics. When exploration or impressions_bucket is on, impressions sent this way feed them instead of the activity's metrics.impressions.
Friends and authors
- The
friends_engagedselector adds posts the user's close friends reacted to, whoever wrote them. Activities from it get theliked_by_friends:<N>reason. - With
author_affinityinscore, activities by authors the user engages with a lot (author_affinityof at least 0.5) get theyou_often_engagereason.
See Why am I seeing this for every reason code.
Caching
Ranked feeds keep their order for a short time after a config change, the same as after any score edit. A change shows on every page once the cached rankings expire.