项目简介
X 公司开源的推荐引擎,用于“为你推荐”时间线的帖子选取与排序。它融合站内关注与站外发现内容,通过可见性规则过滤,并基于 Transformer 模型打分。仓库包含检索、训练、排序及透明度工具等相关组件。
README 预览
# X For You Feed Algorithm\n\nThis repository contains the core code that determines which posts a viewer sees in the **For You** feed on X. It combines in-network content (from accounts the viewer follows) with out-of-network content (discovered through ML-based retrieval and other mechanisms), filters content based on a variety of inputs, and ranks posts using a transformer model.\n\n## Table of Contents\n\n- [Notable Updates](#notable-updates)\n - [August 14th, 2026](#august-14th-2026)\n - [August 13th, 2026](#august-13th-2026)\n- [Overview](#overview)\n- [System Architecture](#system-architecture)\n - [Request Path](#request-path)\n - [Labeling Path](#labeling-path)\n- [Components](#components)\n- [How It Works](#how-it-works)\n - [Scoring and Ranking](#scoring-and-ranking)\n - [Filtering](#filtering)\n- [Experiments and Configuration](#experiments-and-configuration)\n- [What's not in this repo?](#whats-not-in-this-repo)\n- [Under the Hood Label Transparency Tool](#under-the-hood-label-transparency-tool)\n- [Key Design Decisions](#key-design-decisions)\n- [License](#license)\n\n---\n\n\n\n## Notable Updates\n\n### August 14th, 2026\n\nNotable updates:\n\n- **How weights work.** There's a common misconception about how weights related to actions (e.g. Like, Share, Block, Report, etc) work in ranking. The weights scale the predicted probabilities of such actions (or predicted continuous values, e.g. dwell time) — they do *not* scale the raw engagement counts, so e.g. it'd be incorrect to see that a report has 468 times higher weight than a like and conclude that e.g. "1 report cancels out 468 likes". The weights are a multiple on your own predicted probability of Liking, Reporting, etc, which is substantially driven by your own behavior. We've [added comments](home-mixer/params/param.rs) [to the code](home-mixer/scorers/ranking_scorer.rs) so that LLMs or people reading it are more likely to understand it correctly.\n- **Brazil 2026 Elections.** As [announced
常见问题 (2)
故障排除为什么我已验证的 X 账户在个人资料页面上显示“Not verified yet”?
这通常是临时性的验证状态/UI 同步问题,而不是验证资格的实际丢失。在报告的案例中,“About this account”部分正确显示了“Verified since June 2026”和“Identity verified with an official ID”,而个人资料卡片却错误地显示“Not verified yet”。该问题在账号未做任何更改的情况下自行解决。故障排查步骤:1)查看“About this account”以确认您的验证状态。2)关闭并重新打开 X iOS 应用。3)更新至最新版本的应用。4)退出登录后重新登录。5)等待服务器/UI 状态刷新。除非“About this account”部分也显示验证未完成,否则请勿重复进行身份验证。如果该显示不一致的问题持续存在,请联系 X Support。
故障排除如何修复在使用 Tokio 和 DashMap 时,并发点赞事件导致重复帖子和 in-network 分数虚高的问题?
竞态条件的产生是因为共享的 Semaphore::new(1) 从未被获取,而 DashMap 只在每次操作时锁定单个分片。因此,读取-删除检查、帖子插入以及 VecDeque 更新都不是原子操作。即时修复方案:在调用 insert_posts() 之前获取信号量,并在整个操作期间持有它:
let permit = Arc::clone(&semaphore)
.acquire_owned()
.await
.expect("semaphore closed");
post_store_clone.insert_posts(batch).await?;
drop(permit);
这会将所有插入操作串行化,并防止出现重复的 TinyPost 条目,但可能会降低吞吐量。如需更细粒度的修复,可以为每个帖子/作者添加一个外部锁,并在该锁的保护下执行完整的读取-修改-写入操作:
let lock = self.locks
.entry(author_id)
.or_insert_with(|| Arc::new(tokio::sync::Mutex::new(())))
.clone();
let _guard = lock.lock().await;
if self.deleted_posts.contains_key(&post_id) {
return Ok(());
}
if self.posts.contains_key(&post_id) {
return Ok(()); // duplicate event
}
self.posts.insert(post_id, Arc::new(compact_post));
self.original_posts_by_user
.entry(author_id)
.or_default()
.push_back(tiny_post);
对 mark_as_deleted() 应用相同的锁,并且在访问另一个分片时不要持有 DashMap 的分片守卫。通过并发发送两个相同的点赞事件来验证修复效果,并断言作者的 VecDeque 中只包含一次该帖子 ID。