Two-Stage Embedding Retrieval for a Rental Marketplace
Machine LearningModel answerLast updated
Design a two-tower embedding retrieval plus ranking system for vacation rentals, covering representations, labels, bias correction, and evaluation.
A vacation-rental marketplace wants search results — a ranked list of roughly 20–50 bookable homes — that maximize completed bookings without degrading long-term guest satisfaction. Inventory is large (order 10M active listings), traffic is heavy (hundreds of millions of searches per day), and latency must stay interactive (p99 well under 200 ms).
Design the retrieval-and-ranking system whose core is learned vector representations of users and listings. Your answer should cover:
- The end-to-end architecture, from query to final ranked page, including where hard constraints (dates, guests, area, price filters) are enforced.
- How you construct user representations, including both in-session intent and durable preferences, and how you handle users with little or no history.
- How you construct listing representations for both well-engaged and brand-new listings.
- Training objectives and the label hierarchy for retrieval and ranking, plus leakage hazards.
- How relevance, revenue/business goals, and fairness constraints are blended into the final ordering.
- How interaction-log biases — especially position bias — are corrected.
- Evaluation, A/B testing philosophy, and production monitoring.
State your assumptions about scale, then justify each design choice and name the trade-offs.
Hints
Hint 1
Separate the retrieval probe (query + user + trip context) from the listing index, and think hard filters first: geography, availability, and capacity cut the candidate pool more than any model can.
Hint 2
One embedding per user is too crude — split into a recency-weighted session vector and a slow-moving preference vector learned from bookings, with a bucketed 'user type' fallback for cold start.
Hint 3
Treat position bias explicitly: either restrict training to bookings (rarer but less position-dependent), or add position as a feature at serving time and drop it at inference (PAL-style), or apply inverse-propensity weighting.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Assumptions and constraints
Let's fix the numbers: ~10M live listings, ~100M monthly searchers, ~200M searches/day (≈2.5k QPS average, ~10k peak). Latency budget: p99 ≤ 200 ms total — ~30 ms for candidate generation, ~80 ms for ranking, rest for logging/network.
At 128-dim float32, 10M listings × 512 B ≈ 5 GB, so the behavioral index fits in RAM, shardable by market/region. The key facts that shape design:
- Bookings are extremely rare (<1% of searches), so click-based labels dominate volume and the signal we actually care about is sparse.
- Intent is dominated by place and dates, not free text. Most sessions are a few searches for one trip.
- Users are heavily cold-start — a few bookings ever, a handful of sessions per year.
- Inventory is perishable and two-sided: a listing can be booked once per date range, and hosts can decline.
2. Architecture
Query understanding → hard filter → ANN retrieval → ranking → business re-ranking → logging.
- Query parsing: resolve "near Paris" to an S2/geohash polygon and a market ID; parse dates, guests, price bounds, amenities; encode residual free text.
- Hard filtering first: geo cells + availability calendar + capacity + filters shrink 10M to ~1k–50k in-market candidates. ANN search then runs within the filtered partition — hybrid filtering matters because pure ANN over the global index returns unavailable homes.
- Candidate generation (~1–2k): ANN over listing embeddings (HNSW/ScaNN) using the composed query vector, plus complementary sources — popularity in market, "similar to recently viewed," and fresh listings — so recall and diversity don't collapse to whatever the embedding favors.
- Ranking (~500 scored): a DNN/GBDT over rich features — user–listing similarity, price relative to the user's typical spend, distance, quality, host acceptance rate, real-time features. Two-tower scores are too coarse to know that a $180 room for 2 beats a $140 room for 4.
- Re-ranking: multi-objective blending, diversity rules (neighborhood, price band, property type), new-listing boosts, policy guardrails.
- Logging: every impression with position, model version, and eventual conversions — this is the training corpus.
3. User representation
Ship two vectors plus a fallback:
- Session intent (strongest signal): encode the sequence of clicked/wishlisted/long-dwelled listings in the last few days with a recency-weighted mean or small attention/GRU. A Tokyo trip must not be polluted by last summer's lake house.
- Long-term taste: user tower of a two-tower model trained on booking history — captures price tier, property type, party size, amenities.
- Cold start: bucket users by device, locale, signup market, first-search context → learn user-type embeddings in the same space (the classic Airbnb approach). Clustering users into types also densifies labels since bookings per user are sparse.
Final probe = f(session, long-term, trip context [destination, guests, lead time, length of stay]).
4. Listing representation
Two sources, unified in one space:
- Behavioral/skip-gram: treat click sessions as sentences, listings as tokens, add the booked listing as global context on booking sessions. Use same-market negatives — otherwise the model only learns geography (cheap: everything in Paris looks like Paris).
- Content: vision encoder for photos, text encoder for title/description, plus amenity/type/capacity/price/location features — essential for zero-interaction listings.
For new listings, initialize as the mean of nearby/attribute-similar listings and blend toward the behavioral vector as interactions accrue. Refresh daily; incrementally insert into the index.
5. Objectives and labels
Label hierarchy: booking > contact-host request > wishlist > long dwell > click > no-click impression.
- Retrieval: InfoNCE / sampled softmax with in-batch + hard negatives (same-search, same-market impressions that were skipped). Apply logQ correction for popularity skew.
- Ranking: listwise LambdaRank with booking as top grade on searches with ≥1 booking, or a multi-task DNN predicting P(click), P(book|click), P(host accepts), P(no cancellation / good review).
- Long-term satisfaction: reviews, cancellations, complaints, rebooking within a year — delayed labels, train on matured data or a short-horizon proxy.
- Leakage: enforce point-in-time correctness — never use review counts or host stats computed after the label event.
6. Business objectives and bias
Combine as score = P(book)·P(accept)·E[satisfaction]·w_value + λ·diversity + boosts, with w_value reflecting GMV/take rate but capped, so you don't just rank expensive homes. Set explicit guardrails (cancellation rate ≤ X, new-host exposure ≥ Y) and tune weights online or via constrained optimization.
Position bias is the subtle trap: clicks depend on rank, bookings much less so. Three practical fixes: (a) train mostly on bookings/requests; (b) PAL-style — feed position as a feature at training, remove it at inference; (c) inverse-propensity weighting from a randomized exploration slice. Always keep a small randomization bucket to keep propensities estimable.
7. Evaluation and monitoring
Offline: NDCG@k on bookings, recall@1k for retrieval (rank vs. 1–2k candidates), counterfactual/IPS estimates, calibration checks. Online: interleaving early, then A/B with primary metric = bookings/booking conversion, guardrails = cancellations, host diversity, latency, long-run rebooking. Monitor embedding drift, index staleness, cold-start segment performance, and fairness across hosts. Common mistakes: skipping hard filters before ANN, one vector for all intent, ignoring position bias, optimising clicks instead of bookings, and letting revenue weighting silently override satisfaction.