The limits of LastN history windows
Meta's ads ranking models have grown from sequence learning to LLM-scale foundation models such as GEM, but model capacity is bounded by how much history it can consume. Long-term signals — seasonal shopping habits, shifting interests — fall outside short history windows.
The default approach, LastN, keeps only the last N events or days. It is simple and filters noise, but it discards relevant history and applies the same cutoff to every person. Extending past LastN raises three coupled problems:
- Relevance: most of a full history does not help model quality or advertiser performance, so the useful subset must be isolated without dilution.
- Cost: storing, serving, and processing full histories scales linearly to quadratically with length, which real-time ranking cannot absorb.
- Catastrophic forgetting: training on rolling windows of recent data gradually overwrites older patterns.
History scaling as retrieval
Meta Long Memory Search Modeling treats the problem as retrieval rather than as a larger input. It adapts retrieval-augmented generation (RAG) from LLMs: a person's engagement history becomes a document corpus, each ad request becomes a query, and a small, relevant, diverse subset of past signals is retrieved — letting the system use long-history context within tight constraints.

Mapping the RAG pipeline
The four stages of a RAG pipeline — query, index, retrieval, augmentation — carry over directly:
- Query: each ad request encodes signals such as recency, user cohort, ad category, and interest topics, and can weight topical relevance ("history related to this ad category") against recency ("the most recent engagement pattern").
- Index: eligible history is organized into retrievable units across time and topic, like document chunks. Each unit summarizes engagement from one data source over a defined time period.
- Retrieval: a retrieval model scores index entries against the query and converts sparse, noisy event data into a compact set of relevant, non-redundant signals.
- Augmentation: retrieved entries become extra ranking context, as embeddings, training examples, or events for user sequence models and GEM.
Diversity via maximal marginal relevance

Finding the strongest matches is not enough. Recent behavior repeats, so top matches are often near-copies of the same recent interest — highly relevant but low in new information, and able to crowd out the older signals that justified a longer history.
The system therefore uses Maximal Marginal Relevance (MMR). Candidates are scored on fit to the current decision, measured against both the person's current interests and the ad being ranked, and on how different they are from what has already been selected. A near-duplicate is penalized even when it is relevant on its own. The result is coverage of a recent interest, a recurring one, and a longer consideration cycle rather than one interest repeated many times — broader coverage of intent for advertisers.
Fitting inside the latency budget
Every request ranks a large candidate set under a tight latency budget, and all preprocessing — including Long Memory search and summarization — must fit inside it while being reusable across ranking models. Four design choices make this work:
- Time-based chunking: consecutive days are grouped into coarser weekly units, cutting what must be stored and searched.
- Compact representations: learned representations are quantized into compact numeric formats, reducing memory and bandwidth for storage and transport.
- Vector index search: history lives in a vector database, so nearest-neighbor retrieval finds strong matches without scanning full history per request.
- Asynchronous preparation: indexing and other preparation run before a request arrives, off the latency-critical path.
These levers act separately — on index cost, on storage and transport, on latency — and together keep retrieval overhead minimal.
Two applications, one pipeline
Long Memory Search targets different stages of ads ranking from a shared pipeline. At inference, ranking models consume retrieved historical embeddings as added features. At training, older training examples are retrieved and replayed in a second pass to counter forgetting.

For embeddings, a recurring interest can inform a ranking decision months later while that decision stays grounded in the current request, aligning ad opportunities with consideration cycles that a recent window cannot capture. For training data, models learn when longer-horizon signals should matter and reuse older patterns without reprocessing the entire user history.
The two reinforce each other: training data teaches models when long-horizon signals are useful, and online retrieval makes them available inside the ranking request. Shared infrastructure means an improvement for one can benefit the other.
Production results
Meta Long Memory Search Modeling has been in production for major ads ranking models since 2025. Selective long-horizon learning delivered a 1% click-through rate lift for ads on Facebook Feed and Reels and a 1.2% conversion rate lift, while being 5-10x more efficient on compute than linear history scaling. Against linear history scaling it achieves better NE in CTR and CVR models, and combined with system improvements delivers 5-10x better modeling ROI with minimal end-to-end serving overhead.

For the RecSys community the takeaway is that larger models and longer raw sequences are not the only axis for scaling recommendation quality — data scaling can be selective about long-history context.
Next steps include bringing long history directly into user sequence models by condensing long histories into fixed-length sequences at both the raw-event and learned latent-representation levels, so those models capture fine-grained detail and broad patterns together. Meta also plans tighter model-infrastructure co-design, scaling to longer histories, and capturing seasonal patterns that recur year over year.



