@elonmusk: The latest π algorithm has been published to GitHub
Summary
Elon Musk announced that the latest π algorithm, including the For You feed recommendation system powered by a Grok-based transformer, has been published on GitHub. The release includes an end-to-end inference pipeline, pre-trained model artifacts, and new components for content understanding and ads.
View Cached Full Text
Cached at: 05/15/26, 03:02 PM
The latest π algorithm has been published to GitHub https://t.co/ZCOm51uxmh
xai-org/x-algorithm
Source: https://github.com/xai-org/x-algorithm
X For You Feed Algorithm
This repository contains the core recommendation system powering the βFor Youβ feed on X. It combines in-network content (from accounts you follow) with out-of-network content (discovered through ML-based retrieval) and ranks everything using a Grok-based transformer model.
Note: The transformer implementation is ported from the Grok-1 open source release by xAI, adapted for recommendation system use cases.
Table of Contents
- Updates β May 15th, 2026
- Overview
- System Architecture
- Components
- How It Works
- Key Design Decisions
- License
Updates β May 15th, 2026
This release updates the For You algorithm code, including a runnable end-to-end inference pipeline alongside new components for content understanding, ads, and candidate sourcing.
-
End-to-end inference pipeline: A new
phoenix/run_pipeline.pyreplaces the separaterun_ranker.pyandrun_retrieval.pyscripts with a single entry point that runs retrieval β ranking from exported checkpoints, mirroring how the two stages are composed in production. -
Pre-trained model artifacts: A pre-trained mini Phoenix model (256-dim embeddings, 4 attention heads, 2 transformer layers) is now packaged as a ~3 GB archive distributed via Git LFS, enabling out-of-the-box inference without training your own model first.
-
Grox content-understanding pipeline: A new
grox/service is included, providing classifiers, embedders, and a task-execution engine for content understanding workloads such as spam detection, post-category classification, and PTOS policy enforcement. -
Ads blending system: Includes a new
home-mixer/ads/module that handles ad injection and positioning within the feed, including brand-safety tracking that respects sensitive content boundaries. -
Query hydrators: Home mixer now hydrates user context including followed topics, starter packs, impression bloom filters, IP, mutual follow graphs, and served history.
-
Candidate hydrators: Additional hydrators for engagement counts, brand safety signals, language codes, media detection, quote post expansion, mutual follow scores, and more.
-
Candidate sources: Adds sources for ads, who to follow, Phoenix MoE, Phoenix topics, prompts, and updates Thunder/Phoenix ones.
Overview
The For You feed algorithm retrieves, ranks, and filters posts from two sources:
- In-Network (Thunder): Posts from accounts you follow
- Out-of-Network (Phoenix Retrieval): Posts discovered from a global corpus
Both sources are combined and ranked together using Phoenix, a Grok-based transformer model that predicts engagement probabilities for each post. The final score is a weighted combination of these predicted engagements.
We have eliminated every single hand-engineered feature and most heuristics from the system. The Grok-based transformer does all the heavy lifting by understanding your engagement history (what you liked, replied to, shared, etc.) and using that to determine what content is relevant to you.
System Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FOR YOU FEED REQUEST β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β HOME MIXER β
β (Orchestration Layer) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β QUERY HYDRATION β β
β β ββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββββββββββ β β
β β β User Action Sequence β β User Features β β β
β β β (engagement history) β β (following list, preferences, etc.) β β β
β β ββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β CANDIDATE SOURCES β β
β β βββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββ β β
β β β THUNDER β β PHOENIX RETRIEVAL β β β
β β β (In-Network Posts) β β (Out-of-Network Posts) β β β
β β β β β β β β
β β β Posts from accounts β β ML-based similarity search β β β
β β β you follow β β across global corpus β β β
β β βββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β HYDRATION β β
β β Fetch additional data: core post metadata, author info, media entities, etc. β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β FILTERING β β
β β Remove: duplicates, old posts, self-posts, blocked authors, muted keywords, etc. β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β SCORING β β
β β ββββββββββββββββββββββββββββ β β
β β β Phoenix Scorer β Grok-based Transformer predicts: β β
β β β (ML Predictions) β P(like), P(reply), P(repost), P(click)... β β
β β ββββββββββββββββββββββββββββ β β
β β β β β
β β βΌ β β
β β ββββββββββββββββββββββββββββ β β
β β β Weighted Scorer β Weighted Score = Ξ£ (weight Γ P(action)) β β
β β β (Combine predictions) β β β
β β ββββββββββββββββββββββββββββ β β
β β β β β
β β βΌ β β
β β ββββββββββββββββββββββββββββ β β
β β β Author Diversity β Attenuate repeated author scores β β
β β β Scorer β to ensure feed diversity β β
β β ββββββββββββββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β SELECTION β β
β β Sort by final score, select top K candidates β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β FILTERING (Post-Selection) β β
β β Visibility filtering (deleted/spam/violence/gore etc) β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β RANKED FEED RESPONSE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Components
Home Mixer
Location: home-mixer/
The orchestration layer that assembles the For You feed. It leverages the CandidatePipeline framework with the following stages:
| Stage | Description |
|---|---|
| Query Hydrators | Fetch user context (engagement history, following list) |
| Sources | Retrieve candidates from Thunder and Phoenix |
| Hydrators | Enrich candidates with additional data |
| Filters | Remove ineligible candidates |
| Scorers | Predict engagement and compute final scores |
| Selector | Sort by score and select top K |
| Post-Selection Filters | Final visibility and dedup checks |
| Side Effects | Cache request info for future use |
The server exposes a gRPC endpoint (ScoredPostsService) that returns ranked posts for a given user.
Thunder
Location: thunder/
An in-memory post store and realtime ingestion pipeline that tracks recent posts from all users. It:
- Consumes post create/delete events from Kafka
- Maintains per-user stores for original posts, replies/reposts, and video posts
- Serves βin-networkβ post candidates from accounts the requesting user follows
- Automatically trims posts older than the retention period
Thunder enables sub-millisecond lookups for in-network content without hitting an external database.
Phoenix
Location: phoenix/
The ML component with two main functions:
1. Retrieval (Two-Tower Model)
Finds relevant out-of-network posts:
- User Tower: Encodes user features and engagement history into an embedding
- Candidate Tower: Encodes all posts into embeddings
- Similarity Search: Retrieves top-K posts via dot product similarity
2. Ranking (Transformer with Candidate Isolation)
Predicts engagement probabilities for each candidate:
- Takes user context (engagement history) and candidate posts as input
- Uses special attention masking so candidates cannot attend to each other
- Outputs probabilities for each action type (like, reply, repost, click, etc.)
See phoenix/README.md for detailed architecture documentation.
Candidate Pipeline
Location: candidate-pipeline/
A reusable framework for building recommendation pipelines. Defines traits for:
| Trait | Purpose |
|---|---|
Source | Fetch candidates from a data source |
Hydrator | Enrich candidates with additional features |
Filter | Remove candidates that shouldnβt be shown |
Scorer | Compute scores for ranking |
Selector | Sort and select top candidates |
SideEffect | Run async side effects (caching, logging) |
The framework runs sources and hydrators in parallel where possible, with configurable error handling and logging.
How It Works
Pipeline Stages
-
Query Hydration: Fetch the userβs recent engagements history and metadata (eg. following list)
-
Candidate Sourcing: Retrieve candidates from:
- Thunder: Recent posts from followed accounts (in-network)
- Phoenix Retrieval: ML-discovered posts from the global corpus (out-of-network)
-
Candidate Hydration: Enrich candidates with:
- Core post data (text, media, etc.)
- Author information (username, verification status)
- Video duration (for video posts)
- Subscription status
-
Pre-Scoring Filters: Remove posts that are:
- Duplicates
- Too old
- From the viewer themselves
- From blocked/muted accounts
- Containing muted keywords
- Previously seen or recently served
- Ineligible subscription content
-
Scoring: Apply multiple scorers sequentially:
- Phoenix Scorer: Get ML predictions from the Phoenix transformer model
- Weighted Scorer: Combine predictions into a final relevance score
- Author Diversity Scorer: Attenuate repeated author scores for diversity
- OON Scorer: Adjust scores for out-of-network content
-
Selection: Sort by score and select the top K candidates
-
Post-Selection Processing: Final validation of post candidates to be served
Scoring and Ranking
The Phoenix Grok-based transformer model predicts probabilities for multiple engagement types:
Predictions:
βββ P(favorite)
βββ P(reply)
βββ P(repost)
βββ P(quote)
βββ P(click)
βββ P(profile_click)
βββ P(video_view)
βββ P(photo_expand)
βββ P(share)
βββ P(dwell)
βββ P(follow_author)
βββ P(not_interested)
βββ P(block_author)
βββ P(mute_author)
βββ P(report)
The Weighted Scorer combines these into a final score:
Final Score = Ξ£ (weight_i Γ P(action_i))
Positive actions (like, repost, share) have positive weights. Negative actions (block, mute, report) have negative weights, pushing down content the user would likely dislike.
Filtering
Filters run at two stages:
Pre-Scoring Filters:
| Filter | Purpose |
|---|---|
DropDuplicatesFilter | Remove duplicate post IDs |
CoreDataHydrationFilter | Remove posts that failed to hydrate core metadata |
AgeFilter | Remove posts older than threshold |
SelfpostFilter | Remove userβs own posts |
RepostDeduplicationFilter | Dedupe reposts of same content |
IneligibleSubscriptionFilter | Remove paywalled content user canβt access |
PreviouslySeenPostsFilter | Remove posts user has already seen |
PreviouslyServedPostsFilter | Remove posts already served in session |
MutedKeywordFilter | Remove posts with userβs muted keywords |
AuthorSocialgraphFilter | Remove posts from blocked/muted authors |
Post-Selection Filters:
| Filter | Purpose |
|---|---|
VFFilter | Remove posts that are deleted/spam/violence/gore etc. |
DedupConversationFilter | Deduplicate multiple branches of the same conversation thread |
Key Design Decisions
1. No Hand-Engineered Features
The system relies entirely on the Grok-based transformer to learn relevance from user engagement sequences. No manual feature engineering for content relevance. This significantly reduces the complexity in our data pipelines and serving infrastructure.
2. Candidate Isolation in Ranking
During transformer inference, candidates cannot attend to each otherβonly to the user context. This ensures the score for a post doesnβt depend on which other posts are in the batch, making scores consistent and cacheable.
3. Hash-Based Embeddings
Both retrieval and ranking use multiple hash functions for embedding lookup
4. Multi-Action Prediction
Rather than predicting a single βrelevanceβ score, the model predicts probabilities for many actions.
5. Composable Pipeline Architecture
The candidate-pipeline crate provides a flexible framework for building recommendation pipelines with:
- Separation of pipeline execution and monitoring from business logic
- Parallel execution of independent stages and graceful error handling
- Easy addition of new sources, hydrations, filters, and scorers
License
This project is licensed under the Apache License 2.0. See LICENSE for details.
Similar Articles
@elonmusk: Critique of the π algorithm is welcome. There will be monthly updates of the latest algorithm to GitHub with release nβ¦
Elon Musk announces monthly open-source updates of the X (formerly Twitter) algorithm on GitHub with release notes, inviting critique and reminding users they can opt out of the algorithm via the Following tab.
X Algorithm Open Source: This Is What the Leaked Grok Code Tells You About Going Viral in 2026
Elon Musk's xAI open-sourced the X 'For You' recommendation algorithm on GitHub, revealing the code that determines virality on the platform. The article analyzes the code and outlines six rules for going viral.
@elonmusk: Grok now has skills
Elon Musk announces that the Grok AI model has been updated to include new 'skills'.
@elonmusk: To give people confidence that we are not secretly manipulating the π recommendations, it is critical that we open souβ¦
Elon Musk states that X will open-source its recommendation algorithms to demonstrate transparency and build user trust.
@elonmusk: Try this early Grok Build (anything) beta and let us know what to improve. Much appreciated!
Elon Musk invites users to try an early beta build of Grok, the AI model from xAI, and provide feedback for improvements.