Skip to main content

Overview

The X Recommendation Algorithm uses Apache Thrift for service definitions and data serialization. This page documents the key Thrift types used across multiple services.

Common Types

ClientContext

Client context containing caller identification and device information. Used across all services.
int64
User ID for authenticated users (personalDataType=‘UserId’)
int64
Guest ID for logged-out users (personalDataType=‘GuestId’)
int64
Application identifier (personalDataType=‘AppId’)
string
Client IP address (personalDataType=‘IpAddress’)
string
Client user agent string (personalDataType=‘UserAgent’)
string
Inferred country code (personalDataType=‘InferredCountry’)
string
Inferred language code (personalDataType=‘InferredLanguage’)
string
Device identifier (personalDataType=‘DeviceId’)

CR Mixer Types

Product

Enum identifying which product surface is making the request.

TweetRecommendation

A single tweet recommendation with score and metadata.
int64
required
Tweet identifier (personalDataType=‘TweetId’)
double
required
Recommendation score - higher values indicate stronger recommendations
list<MetricTag>
Tags for metrics tracking and attribution
int64
Tweet author’s user ID (personalDataType=‘UserId’)
CandidateGenerationKey
Information about which algorithm generated this candidate
int64
Latest timestamp of engagement signals used (null if not from engagement signals)

RelatedTweet

A tweet related to a query tweet or author.

UtegTweet

Tweet recommendation from User Tweet Entity Graph with social proof.
int64
required
Tweet identifier
double
required
Sum of weights of seed users who engaged with the tweet. If a user engaged multiple times (e.g., liked and retweeted), their weight is counted for each engagement type.
map<SocialProofType, list<int64>>
required
Map from engagement type to list of user IDs who engaged in that way. Key is engagement type (like, retweet, reply), value is list of user IDs.

TopicTweet

Tweet recommendation for a specific topic.
SimilarityEngineType
required
Algorithm used to generate this recommendation (SimClustersANN, TwHINANN, UTEG, etc.)

Follow Recommendations Types

DisplayLocation

Enum specifying where recommendations will be displayed.
Key display locations:
  • HOME_TIMELINE (39) - WTF module in Home timeline
  • NUX_PYMK (67) - New user “People You May Know”
  • HOME_TIMELINE_TWEET_RECS (83) - FutureGraph tweet author recommendations
  • MagicRecs (59) - Account recommendations in notifications

UserRecommendation

A recommended user account.
int64
required
Recommended user’s ID (personalDataType=‘UserId’)
Reason
Reason for the recommendation (social context, e.g., “Followed by X”)
AdImpression
Present if this is a promoted account; used for ad impression tracking
string
Opaque tracking token for attribution
ScoringDetails
Information about the candidate’s score and ranking
string
Identifier for which recommendation flow generated this candidate

Source Signals

SourceType

Enum identifying the type of user signal used for candidate generation.

SimilarityEngineType

Enum identifying which similarity/recommendation algorithm was used.
Key algorithms:
  • SimClustersANN - Community-based clustering and similarity
  • TweetBasedTwHINANN - Heterogeneous graph neural network
  • UTEG - User Tweet Entity Graph engagement-based
  • TwhinCollabFilter - Collaborative filtering with TwHIN embeddings
  • Earlybird* - Real-time search index-based

Error Types

ValidationExceptionList

List of validation errors with details reported to clients.

ServerError

Generic server error. Details are not reported to clients for security.

Data Annotations

Thrift definitions include personal data annotations for privacy compliance:
  • personalDataType='UserId' - Twitter user identifier
  • personalDataType='TweetId' - Tweet identifier
  • personalDataType='IpAddress' - IP address
  • personalDataType='DeviceId' - Device identifier
  • hasPersonalData='true' - Struct contains personal data
  • persisted='true' - Data may be persisted to storage

Source Files

Thrift definitions can be found in the source repository:
  • cr-mixer/thrift/src/main/thrift/ - CR Mixer definitions
  • follow-recommendations-service/thrift/src/main/thrift/ - FRS definitions
  • src/thrift/com/twitter/ - Shared common definitions