How the X For You Feed Algorithm Works: A Technical Breakdown of the Open Source Ranking System
The X For You feed algorithm operates as a two-stage pipeline that gathers candidate posts from in-network and out-of-network sources, scores them using a multi-action prediction model with configurable per-action weights, filters them through a visibility service that returns ALLOW, INTERSTITIAL, or DROP decisions, and finally blends the surviving posts with ads and recommendations.
The X For You feed algorithm, released as part of the xai-org/x-algorithm open source repository, processes billions of requests through a modular Rust-based architecture designed to balance relevance, safety, and diversity. This system separates ranking logic from policy enforcement, allowing engineers to tune engagement weights independently from content moderation rules. The implementation relies on distinct request-time and labeling-time pathways that jointly determine what appears in a user's timeline.
Two-Stage Architecture Overview
The algorithm is organized around two primary pathways. The request path (Home Mixer) handles real-time candidate retrieval, scoring, and assembly, while the labeling path asynchronously generates content classifications that feed into visibility decisions. This separation enables the ranking layer to focus purely on relevance signals while downstream filters enforce safety and policy constraints based on pre-computed labels.
Stage 1: Candidate Retrieval and the Home Mixer Pipeline
The request-side pipeline begins with the Home Mixer, which orchestrates parallel data fetching and initial filtering before any machine learning scoring occurs.
Parallel Candidate Sources
Posts are collected simultaneously from multiple sources to maximize recall. In-network candidates arrive via the Thunder service, which retrieves tweets from accounts the viewer follows. Out-of-network discovery happens through Phoenix retrieval and SimClusters, identifying relevant content beyond the user's immediate social graph. The orchestration logic resides in home-mixer/candidate_pipeline/.
Query Hydration and Context Assembly
Before scoring begins, the system assembles a comprehensive context object for the viewer. This includes recent engagement history, follow lists, blocks and mutes, muted keywords, previously seen posts, and other behavioral signals. This hydration step ensures that subsequent filters and scorers have access to real-time user state without requiring repeated database lookups.
Pre-Scoring Filters
A battery of heuristics removes unsuitable candidates before expensive model inference. The home-mixer/filters/ directory contains implementations such as:
- DropDuplicatesFilter – Removes identical or near-duplicate posts
- AgeFilter – Excludes posts exceeding configurable age thresholds
- AuthorSocialgraphFilter – Drops self-tweets and out-of-network replies or retweets based on viewer preferences
These filters run in sequence to minimize the candidate pool passed to the scoring stage.
Stage 2: Phoenix Model Scoring and Ranking
Once filtered, candidates enter the scoring phase where the Phoenix model predicts user engagement probabilities and the system computes final ranking scores.
Multi-Action Prediction
Unlike single-score ranking systems, the Phoenix model generates a probability distribution across a dozen possible actions including favorite, reply, dwell, retweet, and negative signals. This multi-action architecture allows the algorithm to weight positive engagements against potential negative behaviors rather than optimizing for a unified relevance metric.
Weighted Score Computation
The core scoring logic lives in home-mixer/scorers/ranking_scorer.rs. The computation follows these steps:
-
Weight loading –
ScoringWeights::from_paramsreads current feature-switch values fromhome-mixer/params/param.rsto assemble a struct of per-action weights (e.g.,weight_favorite,weight_reply). -
Weighted summation –
RankingScorer::compute_weighted_partsmultiplies each predicted probability by its corresponding weight and sums the products into a raw score.
// home-mixer/scorers/ranking_scorer.rs
let weights = ScoringWeights::from_params(&query.params);
let raw_score = RankingScorer::compute_weighted_parts(&weights, &predictions);
Bidirectional Boosts and Author Diversity
The algorithm applies specialized adjustments for social connections and content diversity:
-
Bidirectional boost – When the post author follows the viewer back (mutual follow), the system adds extra
reply_weight_foranddwell_weight_formultipliers to increase visibility of these high-trust interactions. -
Author diversity – After initial scoring,
RankingScorer::author_pool_countstracks how many posts from each author appear in the candidate set. Theauthor_diversity_multipliersmethod applies decay factors to subsequent posts from the same author, ensuring temporal diversity in the final feed.
let counts = RankingScorer::author_pool_counts(candidates, &weighted_scores);
let diversity = RankingScorer::author_diversity_multipliers(query, &counts);
let final_score = weighted_score * diversity[i];
Visibility Filtering and Content Moderation
After ranking, posts undergo mandatory policy and safety checks through a dedicated filtering layer.
The Filtering Decision Engine
The Visibility Filtering service, accessed via visibility-filtering-client/lib.rs, evaluates each post-viewer pair against a rule registry defined in visibility-filtering/rules/registry.rs. Unlike ranking scores, this binary (or trinary) decision returns one of three outcomes:
- ALLOW – Post can be displayed normally
- INTERSTITIAL – Post requires warning labels or click-through confirmations
- DROP – Post is suppressed entirely
This separation ensures that ranking optimizations never override safety policies.
Label Generation Pipeline
The filters rely on labels produced by an asynchronous ML pipeline. Key components include:
- grox/ – Real-time text classifiers for spam, adult content, and violent media
- media-model-proxy/ – Image and video classification for adult content, gore, and hateful symbols
- clip/ – Embedding generation for media similarity and classification tasks
- agatha/ – Batch account labeling based on aggregate blocking and reporting patterns
- bdsm/ – Sequence analysis detecting inauthentic or abusive account behavior
- user-cred-v2/ – PageRank-style authority scores computed over the follow graph
- adult-content/ and pnsfwmedia/ – Calibrated classifiers combining CLIP embeddings with account reputation
These systems emit labels (e.g., "spam", "low-quality", "adult") stored for real-time lookup during the visibility check.
Final Assembly: Blending and Serving
Once ranked and filtered, posts undergo final assembly before delivery.
Content Blending and Interleaving
The BlenderSelector in home-mixer/selectors/blender_selector.rs interleaves organic posts with non-content items including advertisements, "Who to Follow" suggestions, and engagement prompts.
// home-mixer/selectors/blender_selector.rs
let blended = BlenderSelector::interleave(posts, ads, who_to_follow, prompts);
Determinantal Point Process Reranking
Before final delivery, an optional vm-ranker/ service applies Determinantal Point Process (DPP) reranking. This step trades minor score penalties for increased embedding diversity, ensuring that consecutive posts in the feed cover varied topics and media types rather than clustering around similar vectors.
Side Effects and Logging
After the response returns to the client, the system processes asynchronous side effects through home-mixer/side_effects/, including impression logging, cache warming, and ad event recording.
Configuration and Transparency
All numeric parameters in the scoring pipeline are exposed as feature switches with the prefix rust_home_mixer_*. Engineers can launch experiments affecting traffic fractions by modifying weights in home-mixer/params/param.rs without deploying new code. Additionally, the under-the-hood/ directory contains the "Under-the-Hood" transparency tool, allowing users to view which labels affected their posts' visibility.
Key Implementation Files in the X For You Algorithm
home-mixer/scorers/ranking_scorer.rs– Core ranking logic including weight application, bidirectional boosts, and author diversity decayhome-mixer/params/param.rs– Feature-switch definitions and configurable weight parametershome-mixer/filters/– Pre-scoring filters including duplicate removal, age gating, and socialgraph checksvisibility-filtering-client/lib.rs– Client wrapper for the visibility filtering servicevisibility-filtering/rules/registry.rs– Label-based rule registry for ALLOW/INTERSTITIAL/DROP decisionshome-mixer/selectors/blender_selector.rs– Logic for interleaving posts with ads and recommendationsphoenix/– Model training and serving infrastructure for multi-action predictionvm-ranker/– DPP-based diversity reranking serviceunder-the-hood/– Transparency tooling exposing post labels to end users
Summary
- The X For You feed algorithm employs a two-stage pipeline separating candidate retrieval from prediction-based scoring
- Multi-action prediction via the Phoenix model enables nuanced weighting of diverse engagement types rather than single-score optimization
- Configurable weights defined in
param.rsallow real-time experimentation via feature switches without code deployment - Strict separation between ranking and visibility filtering ensures safety policies remain independent from relevance tuning
- Asynchronous label generation through specialized ML models (grox, agatha, bdsm) provides real-time content classification for policy enforcement
- DPP reranking and author diversity multipliers prevent filter bubbles by enforcing temporal and embedding diversity
- Full open source transparency enables external auditing through the Under-the-Hood label viewer and published repository structure
Frequently Asked Questions
What machine learning model powers the X For You feed algorithm scoring?
The Phoenix model generates per-action probabilities for behaviors like favorites, replies, and dwell time. Located in the phoenix/ directory, this model outputs multiple predictions per candidate rather than a single relevance score, allowing the RankingScorer in home-mixer/scorers/ranking_scorer.rs to compute weighted sums based on configurable engagement priorities.
How does the algorithm prevent showing duplicate or low-quality content?
Pre-scoring filters in home-mixer/filters/ remove candidates before scoring occurs. The DropDuplicatesFilter eliminates redundant posts, the AgeFilter removes stale content based on temporal thresholds, and the AuthorSocialgraphFilter blocks self-tweets or unwanted out-of-network replies. Additionally, the author_diversity_multipliers mechanism penalizes multiple consecutive posts from the same author during final ranking.
What is the difference between ranking and visibility filtering in the X For You feed?
Ranking determines the relative order of posts based on predicted engagement probabilities and configured weights, producing a sorted list from highest to lowest relevance. Visibility filtering, implemented in visibility-filtering-client/lib.rs, makes absolute decisions about whether a post may appear at all, returning ALLOW, INTERSTITIAL, or DROP based on safety labels and viewer preferences. This architectural separation allows ranking engineers to optimize for engagement while policy teams enforce content rules independently.
How can developers customize the X For You algorithm behavior?
All scoring parameters are exposed as feature switches with the rust_home_mixer_* prefix defined in home-mixer/params/param.rs. Developers can modify weights for specific actions (such as increasing reply_weight_for for mutual follows), adjust author diversity decay rates, or toggle experimental filters by changing these configuration values. The system supports A/B testing by enabling feature switches for specific traffic fractions without requiring binary redeployment.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →