Embedding-based retrieval (EBR) is a candidate generation technique in recommender systems that represents users, queries and items as dense vectors in a shared embedding space and retrieves the items whose vectors are closest to the user or query vector, typically with approximate nearest neighbor search. It is also described as vector retrieval for recommendation.
EBR forms the first stage of a multi-stage ranking pipeline: it narrows a catalog of millions or billions of items to a few hundred or thousand candidates within milliseconds, after which heavier ranking models score them precisely. Large platforms use it for feeds, video, product search, advertising and social connections.
How embedding-based retrieval works
Embedding-based retrieval works in two separate phases: an offline phase that encodes every item into a vector and builds an index, and an online phase that encodes the current user or request and searches that index. The separation is what makes EBR fast, because item vectors are computed once rather than for every request.
The encoders are usually trained as a two-tower model. One tower turns user features, such as interaction history, context and demographics, into a user embedding; the other tower turns item features into an item embedding. Training pushes vectors of user-item pairs with positive feedback closer together and pairs without interaction further apart, usually measured by dot product or cosine similarity.
Embedding size is a deliberate trade-off. Production systems commonly use 64 to 256 dimensions: larger vectors capture finer preferences but increase index memory and search latency, while smaller vectors are cheaper but blur distinctions between similar items. Because the towers never see each other’s features before the final similarity step, the architecture is called late interaction, and this constraint is exactly what allows item vectors to be precomputed and indexed.
The table below lists the steps of a typical EBR pipeline.
| Stage | Runs | What happens |
|---|---|---|
| Training | Offline, daily or continuously | Two-tower model learns from logged interactions |
| Item encoding | Offline or near-real-time | Every catalog item receives a vector |
| Index building | Offline | Vectors are organized for approximate search |
| Query encoding | Online, per request | User and context become one vector |
| Nearest neighbor search | Online, a few milliseconds | Top-K closest items are returned |
| Hand-off to ranking | Online | Candidates go to the ranking and re-ranking stages |
Training objectives and negative sampling
The quality of embedding-based retrieval depends mainly on how negatives are chosen during training. Logged data contains positive examples, such as clicks, purchases or long watches, but the model must also learn what a user would not want, which requires negative sampling.
Common objectives include sampled softmax, which treats retrieval as classification over the whole catalog, and contrastive losses with in-batch negatives, where the other items in a training batch serve as negatives. In-batch sampling is efficient but over-represents popular items, so practitioners apply a logQ correction that subtracts the log of each item’s sampling probability.
| Strategy | Advantage | Drawback |
|---|---|---|
| Random negatives | Simple, covers the whole catalog | Too easy, weak learning signal |
| In-batch negatives | No extra computation | Popularity bias without correction |
| Hard negatives | Teaches fine distinctions | Risk of false negatives, unstable training |
| Mixed negatives | Balances easy and hard examples | More tuning of ratios |
Hard negatives, for example items that were shown but skipped or items ranked just below positives, sharpen the embedding space. However, too many hard negatives can hurt recall, because some of them are actually relevant items the user simply did not see.
Approximate nearest neighbor search
Exact search over billions of vectors is too slow for online serving, so EBR relies on approximate nearest neighbor (ANN) search, which trades a small loss of recall for a large gain in speed. The quality of ANN is usually reported as recall at K against exact search, with production systems commonly targeting above 90 to 95 percent.
| Index family | Principle | Typical use |
|---|---|---|
| HNSW | Navigable multi-layer proximity graph | High recall, low latency, memory-heavy |
| IVF | Clustering into inverted lists, probe a few | Large catalogs, tunable speed |
| Product quantization | Compressed vector codes | Billion-scale indexes in limited memory |
| ScaNN-style quantization | Anisotropic quantization for inner product | Fast maximum inner product search |
Open-source libraries such as FAISS and dedicated vector databases implement these indexes. Recommender teams also add attribute filtering for availability, region or age restrictions, which is harder in ANN than in classic inverted indexes and can reduce recall when filters are strict.
Embedding-based retrieval compared with other candidate sources
Embedding-based retrieval complements rather than replaces other candidate generators. Production recommenders usually merge several retrieval sources and let the ranking stage decide.
| Method | Strength | Weakness |
|---|---|---|
| Embedding-based retrieval | Semantic matching, personalization | Weak on exact constraints, cold items |
| Item-based collaborative filtering | Simple, explainable co-occurrence | Sparse for new or niche items |
| Term-based retrieval | Exact keyword and attribute matching | No semantic generalization |
| Graph-based retrieval | Exploits social and multi-hop relations | Costly graph updates |
| Generative retrieval | Decodes item IDs such as semantic IDs | Newer, harder to serve at scale |
Limitations and common mistakes
The main limitation of EBR is that a single dot product cannot express complex interactions between user and item features, which is why its output always needs a more expressive ranking stage. Teams also encounter several recurring problems.
- Stale embeddings: user or item vectors that are not refreshed miss new interests and new items.
- Cold start: new items without interactions need content features in the item tower.
- Popularity bias: uncorrected sampling concentrates retrieval on head items.
- Offline-online mismatch: offline recall gains do not always translate into engagement gains.
- Version skew: query and item vectors from different model versions are not comparable.
The idea in brief
A big online store has millions of products. It cannot check every product for every visitor. That would take too long.
Embedding-based retrieval solves this. Each product gets a position on a giant map. Each visitor gets a position on the same map, based on what they liked before. The system then picks the products closest to the visitor. This takes only a moment.
The result is a short list of likely matches. Another, more careful system then decides the final order.
A practical scenario
An online fashion retailer with about two million products sees that its recommendations are dominated by bestsellers. Its existing candidate generator relies on co-purchase statistics, which rarely surfaces newer or niche items.
The team trains a two-tower model on six months of clicks and purchases, adds product images and descriptions to the item tower and builds an HNSW index of 128-dimensional vectors. Online retrieval returns 500 candidates in under 10 milliseconds, and these are merged with the old candidates before ranking.
In an A/B test, the new retrieval source raises click-through on recommendations by several percent and increases the share of long-tail products in recommendations. The team then schedules daily re-encoding of the catalog to keep new items discoverable.