---
topic: ai-ml
author: Engineering Team
published: Nov 17, 2026 · read: 6 min
---

Inside LinkedIn Feed Architecture: Dual-Encoder LLM Retrieval and Ranking

Discover how LinkedIn replaced heterogeneous candidate sources with dual-encoder LLM embeddings, percentile tokenization, and sequential transformers.

– –

How do you evaluate millions of candidate posts and serve hyper-personalized feeds to over 1.3 billion professionals in under 50 milliseconds?

For years, LinkedIn’s feed retrieval pipeline operated as a heterogeneous federation of specialized indexing systems: a chronological network index, trending posts by geographic clusters, collaborative filtering algorithms, industry-specific heuristics, and early graph embedding models. Each pipeline maintained separate infrastructure, custom indexing schemas, and isolated tuning parameters.

While this federation ensured content variety, optimizing one source frequently degraded another. Candidate selection lacked a shared semantic coordinate system, forcing the downstream ranking model to arbitrate between candidates with wildly divergent scoring biases.

To solve this, LinkedIn redesigned its retrieval and ranking architecture around foundational Large Language Models (LLMs). This article explores the engineering innovations that made this possible: replacing heterogeneous pipelines with a unified dual-encoder embedding space, converting numeric signals into percentile tokens, sequential transformer ranking, and shared context batching.


From Five Librarians to a Unified Dual-Encoder Space

In a distributed recommendation system, the candidate generation (retrieval) stage must compress a universe of hundreds of millions of posts into a few thousand high-quality candidates before deep ranking begins.

┌─────────────────────────────────────────────────────────────────────────┐
│                      Dual-Encoder Embedding Generation                  │
│                                                                         │
│   Member Profile & History                     Candidate Post Text      │
│   ["Electrical Engineer, Grid..."]            ["Modular Nuclear SMR..."]│
│                 │                                           │           │
│                 ▼                                           ▼           │
│   ┌───────────────────────────┐               ┌──────────────────────┐  │
│   │   Member Transformer      │               │   Post Transformer   │  │
│   │   Encoder (LLM Weights)   │               │   Encoder (Weights)  │  │
│   └─────────────┬─────────────┘               └──────────┬───────────┘  │
│                 │                                        │              │
│                 ▼                                        ▼              │
│          Member Vector $u$                        Post Vector $v$       │
│          (768 dimensions)                         (768 dimensions)      │
│                 │                                        │              │
│                 └───────────────────┬────────────────────┘              │
│                                     ▼                                   │
│                        Dot Product: $ ext{score} = u \cdot v$          │
└─────────────────────────────────────┬───────────────────────────────────┘
                                      │
                                      ▼ Sub-50ms HNSW Search
                         Top 1,000 Relevant Candidates

The Dual-Encoder Paradigm

A dual-encoder architecture uses two distinct encoding branches that project both members and content items into a shared, dense mathematical vector space ($d = 768$):

  1. Member Encoder: Generates a vector $u \in R^d$ from a structured prompt representing the member’s profile, industry, skills, and engagement history.
  2. Post Encoder: Generates a vector $v \in R^d$ from the post text, media metadata, author attributes, and engagement distributions.

Relevance is computed as the inner dot product:

Relevance Score = u * v = sum(u_i * v_i)

Because post vectors are computed asynchronously at ingestion time and indexed in a distributed vector database (using HNSW or IVF-PQ graphs), serving a user request requires only:

  1. One forward pass through the Member Encoder.
  2. An approximate nearest neighbor (ANN) search against the post index, returning the top candidate IDs in less than 15 milliseconds.

Pretrained World Knowledge Eliminates Keyword Mismatch

Traditional retrieval systems fail on vocabulary mismatch. If an engineer’s profile states “Electrical Engineering” and a post discusses “Small Modular Reactors for Grid Balancing”, keyword matching scores zero. Because LLM encoders carry deep world knowledge acquired during pretraining, the embedding space inherently places nuclear power grid systems adjacent to electrical engineering concepts.


Tokenizing Quantities: The Percentile Bucketing Breakthrough

LLMs are designed to process natural language tokens. When numeric engagement signals are fed into LLMs as raw text strings, standard tokenizers split digits into disjoint arbitrary sub-word tokens.

When LinkedIn initially tested passing raw view counts directly into prompts (e.g., views: 12345), the model tokenized 12345 as arbitrary characters. When measuring the mathematical correlation between raw item popularity and embedding cosine similarity, the correlation was essentially zero ($-0.004$). The model was completely blind to content popularity, one of the most critical relevance features in recommendation systems.

Raw Input: "Views: 12345"
  └── Tokenizer: ["Views", ":", "12", "34", "5"]
  └── Embedding: Model treats digits like text; correlation = -0.004

Percentile Input: "<view_pct>71</view_pct>"
  └── Tokenizer: Single learned vocabulary token representing 71st percentile
  └── Embedding: Direct linear relationship; correlation jumps 30x

The Percentile Token Solution

Instead of raw integers, LinkedIn computes the historical cumulative distribution function (CDF) for every continuous numeric feature and maps it into integer percentile buckets (1 to 100). These values are wrapped in dedicated domain tags:

<author_affinity_pct>88</author_affinity_pct>
<view_pct>71</view_pct>
<like_rate_pct>94</like_rate_pct>

Instead of raw integers, LinkedIn computes the historical cumulative distribution function (CDF) for every continuous numeric feature and maps it into integer percentile buckets (1 to 100). These values are wrapped in dedicated domain tags:

Results:

  • Popularity-to-embedding correlation increased by $30 imes$.
  • Retrieval Recall@10 improved by $15%$.

Signal Clarity: Why Pruning Scrolled-Past Posts Sped Up Training 2.6x

In recommendation machine learning, conventional wisdom suggests that feeding more training data produces superior models. LinkedIn initially included every post rendered in a member’s viewport during a session: posts they clicked on, posts they liked, and posts they scrolled past without interacting.

However, training on full viewing sessions degraded model accuracy and inflated computational costs. Self-attention complexity scales quadratically with sequence length:

O(N^2 * d)

A scrolled-past impression contains ambiguous intent. Did the user ignore the post because it was irrelevant, or because they were in a rush, or because the image loaded slowly?

LinkedIn restructured training data to include only positively engaged posts in the member context sequence:

  • Memory footprint per training sequence dropped by 37%.
  • Batch processing capacity increased by 40%.
  • Training iterations executed 2.6x faster.

Dual Negative Sampling Strategy

To teach the dual-encoder fine-grained boundaries, training batches combine two distinct negative sampling strategies:

  1. Easy Negatives: Randomly sampled posts from the global corpus that the member was never shown. This establishes broad semantic domain boundaries.
  2. Hard Negatives: Posts shown in the feed that the user scrolled past without engaging. Adding just two hard negatives per member sample forced the encoder to learn subtle quality distinctions, improving candidate recall by $3.6%$.

Sequential Ranking with Generative Recommenders

Once the dual-encoder retrieves the top 1,000 candidate posts, the Feed passes them to the second-stage ranking model: the Generative Recommender (GR).

Traditional ranking architectures evaluate each member-post candidate pair independently (pointwise ranking). This misses temporal narrative context. If a professional reads three articles on distributed database replication on Monday and Tuesday, an article on Raft consensus on Wednesday is part of an active learning trajectory, not an isolated preference.

Member Historical Sequence (1,000+ Engagements)
┌─────────────────────────────────────────────────────────────┐
│ [Post 1: Go Concurrency] ──► [Post 2: Kafka Partitioning] ──► ...
└──────────────────────────────┬──────────────────────────────┘
                               │
                               ▼
        ┌──────────────────────────────────────────────┐
        │   Causal Transformer Sequence Model          │
        │   (Autoregressive History Representation)    │
        └──────────────────────┬───────────────────────┘
                               │
                               ▼
┌─────────────────────────────────────────────────────────────┐
│                 Late Fusion Concatenation                   │
│   Transformer History State + Non-Sequence Context Signals  │
│   (Network Affinity Scores, Recency, Device Telemetry)      │
└──────────────────────────────┬──────────────────────────────┘
                               │
                               ▼
        ┌──────────────────────────────────────────────┐
        │   Multi-Gate Mixture-of-Experts (MMoE)       │
        │   Prediction Heads                           │
        └───────┬──────────────┬──────────────┬────────┘
                │              │              │
                ▼              ▼              ▼
           P(Like)         P(Comment)     P(Share)

1. Late Fusion for Computational Efficiency

Running every member feature through deep self-attention is computationally prohibitive. LinkedIn uses late fusion: raw statistical features (connection degrees, real-time counters, network affinity) bypass the transformer layers and are concatenated directly with the transformer’s sequence embedding before the final prediction heads.

2. Shared Context Batching

Scoring 1,000 candidates by evaluating the user’s 1,000-post interaction history 1,000 separate times would overload GPU clusters. With shared context batching, the member’s historical sequence is encoded once. The resulting user state is broadcast across all candidate vectors in parallel using masked cross-attention.

3. Multi-Gate Mixture-of-Experts (MMoE)

Different user engagements have different business values. A comment represents higher engagement than a passive impression, and a share represents high endorsement. The ranking head employs an MMoE layer where specialized expert networks share the underlying sequential representation while separate gating networks output calibrated probabilities for P(Like), P(Comment), P(Share), and P(Long Dwell).


Architectural Lessons for AI-Native Systems

LinkedIn’s feed transformation offers critical blueprints for modern AI-native engineering:

  1. Unify Fragmented Retrieval: Replacing disparate heuristic candidate sources with a shared dual-encoder embedding space creates a coherent, globally tunable candidate distribution. Instead of raw integers, LinkedIn computes the historical cumulative distribution function (CDF) for every continuous numeric feature and maps it into integer percentile buckets (1 to 100). These values are wrapped in dedicated domain tags:
  2. Filter for High-Signal Training: High-volume ambiguous data degrades training performance. Pruning noisy negative signals reduces context length and unlocks faster experimentation cycles.
  3. Decouple Sequence from Features: Use transformers where sequential history matters, and combine static features via late fusion to maintain strict sub-50ms latency SLAs at global scale.
Advertisement

/* Comments */