The front page · Rust
xai-org/x-algorithmX publishes its For You feed algorithm as open source
xai-org/x-algorithm exposes how posts are retrieved, ranked by a transformer model, and filtered for visibility.
What this repository is
xai-org/x-algorithm is the source code behind the For You feed on X — the timeline most users see by default. It answers one question per request: which posts should a given viewer be shown, and in what order? The answer comes from two decisions kept deliberately apart:
- Ranking decides the order of posts.
- Visibility filtering decides whether each post can be shown at all.
The repository is published under Apache-2.0 as a transparency effort. X's stated aim is that people can audit, critique, or help improve how posts are distributed. It is large — about 19 MB across roughly 40 top-level components and thousands of files — and mixes Rust (the dominant language by byte count) with Python, Scala, Java, C++ and CUDA.
How a feed is built
The For You feed is assembled per request inside home-mixer/, which runs on the candidate-pipeline framework. That crate defines the stage types — source, hydrator, filter, scorer, selector, side effect — and executes them in parallel where it can.
Posts come from two places:
- In-network —
thunder/keeps recent posts from accounts a viewer follows in memory. - Out-of-network —
phoenix/retrieval embeds the viewer and each post as vectors and returns nearest neighbours;simclusters/clusters accounts by who engages with what. A shared list of popular recent posts is added viapopular_posts_source.rs.
Both sets are ranked together by the same model.
The request path runs through seven stages: query hydration (the viewer's recent engagements, following list, blocks and mutes), parallel candidate sources, candidate hydration (post text, author labels, engagement counts), pre-scoring filters, scoring, top-K selection, then post-selection filters. A separate blending pipeline wraps the ranked posts with what the model does not rank: ads, Who to Follow recommendations, and prompts.
Scoring
Ranking is done by Phoenix, a transformer model whose training code lives in phoenix/ (JAX for training, Rust for serving). Rather than predicting one "relevance" score, Phoenix predicts a probability for many actions the viewer might take:
Engagement favorite · reply · repost · quote · share · share via DM
Clicks post · profile · link · photo expand · video open
Attention dwell · dwell time · click dwell time · video continuation seconds
Author follow author
Negative not interested · mute author · block author · report
RankingScorer, in xai-value-model/scoring.rs, combines them into one score:
Final Score = Σ (weight_i × P(action_i))
The README is careful to correct a common misconception here: the weights scale predicted *probabilities*, not raw engagement counts. A report having 468 times the weight of a like does not mean "one report cancels out 486 likes" — it means your own predicted probability of reporting is multiplied by that factor.
Three adjustments follow scoring:
- Author diversity — each post after an author's first decays toward a floor.
- Out-of-network discount — posts from accounts the viewer doesn't follow are scaled below 1, as are replies and reposts from followed accounts.
- New-author boost — authors with few impressions get lifted toward a target position.
VMRanker then calls vm-ranker/, a separate service that reorders the result using a determinantal point process over post embeddings, trading a little score for less similarity between neighbours.
Filtering
Filtering happens in two places. Pre-scoring filters run before ranking and remove duplicates across sources, posts older than 48 hours, the viewer's own posts, blocked or muted accounts, muted keywords, already-seen posts, subscriber-only posts the viewer can't access, and more — about eighteen named filters in home-mixer/filters/.
Post-selection filters run after the order is fixed. The most consequential is VFFilter, which asks visibility-filtering/ for each post and viewer one of four answers:
- ALLOW — show normally
- NOTICE — show with a notice attached
- INTERSTITIAL — show behind an interstitial the viewer can tap through (adult or graphic media)
- DROP — do not show
AncillaryVFFilter then removes any post whose parent, quoted post, or reposted post was itself dropped. DedupConversationFilter collapses extra branches of one conversation.
The labeling path
The labels visibility filtering reads come from a separate pipeline that runs continuously rather than on the request path:
- Content understanding —
grox/classifies text and media;media-model-proxy/serves image/video models (adult content, violence, hateful symbols);clip/trains the embedding model those classifiers take as input. On the account side,agatha/labels accounts from how others respond to their posts,bdsm/reads action sequences for inauthentic behavior, anduser-cred-v2/runs PageRank over follow and engagement edges. - Labeling rules —
scarecrow/reacts to events as they happen, embeddingbotmaker/as its rule engine and loading rules frombotmaker-rules/scarecrow/. A rule reads: *on this event, if these conditions hold, apply this label*. Separately, theabuse-enforcement-service/acts on model scores — labeling accounts or posts, challenging them, or suspending them — and consultsabuse-ledger-service/so an action overturned on appeal is not re-applied for a fixed period. - Storage — labels are written to storage and read back on the request path.
Some rules apply only when a post is a recommendation from an account the viewer does not follow, and those can only drop — spam caught at high recall, for instance. The same post may be allowed to a follower.
What's runnable
The repository is primarily for inspection, but some parts are designed to run end-to-end. phoenix/ ships a Cargo workspace, a pyproject.toml, a quickstart at phoenix/QUICKSTART.md, and synthetic data generation so a small model can be trained and served as a proof of concept. Elsewhere, code may not include build or deployment files — the README notes infrastructure imports like xai_service_runner or xai_kafka that aren't self-explanatory.
A few things are deliberately absent: some Grox LLM prompts (the .j2 files) and some botmaker rules, withheld to reduce the risk of gaming. To compensate, X is piloting an Under the Hood transparency tool — available at https://x.com/i/jf/under_the_hood, with its jobs and serving code in under-the-hood/ — that shows people aggregate statistics about the visibility-impacting labels on their account and posts.
Key design decisions
The README documents five deliberate choices worth noting:
- Multi-action prediction rather than a single relevance score; combining them is an explicit, separate step.
- Candidate isolation in ranking — during transformer inference candidates cannot attend to each other, only to the viewer context, so scores are consistent and cacheable regardless of batch composition.
- Hash-based embeddings for both retrieval and ranking, so there's no vocabulary to maintain and new posts are representable immediately.
- Ranking and visibility are separate services with different inputs and rules.
- A composable pipeline architecture in
candidate-pipelinethat separates execution and monitoring from business logic.
Configuration
Many tunable values — including the scoring weights — are read from a configuration system rather than hard-coded, so experiments can run on small percentages of timeline traffic. Cron scripts set this repository's defaults to be the primary production values, for example in home-mixer/params/param.rs. The README points readers at docs/BIDIRECTIONAL_BOOST_CHANGE.md as an example of how a parameter value changes over time.
The repository is updated frequently, with notable updates logged in the README through late October 2026 — most recently removing Brazil2026ElectionFilter, which had dropped posts from accounts reported to Brazil's Electoral Court during that country's election unless the viewer followed them. Earlier releases added visibility filtering and its label-producing systems, Phoenix training code, SimClusters retrieval, and a better dwell-time prediction in ranking.
For anyone who wants to understand — or critique — how one of the largest social platforms decides what you see, this is the reference implementation, published under Apache-2.0 with the weights and rules visible in plain Rust.
xai-org/x-algorithm: 19 MB in 2,395 files, indexed Nov 16, 2026 after 17 hours of indexing. License: Apache-2.0. Source: https://github.com/xai-org/x-algorithm.
Ask your agent to name it in its tool calls (the repo argument of query_graph, recall_project and read_project_source).
Written by AI models on the operator's own hardware, checked by a second model, from the repository's README and its code. Back to the shelf