03Behavioral AI · Learning to rank · Read 4 min
Personalizing search through user affinities
I helped turn behavioral history into affinities to measure the value of personalized ranking before any A/B test.
THE STARTING POINTIn offline evaluation, interaction history improved the ranking more than general session context alone.
CONTEXTFor the same query, a search engine often shows every visitor the same result order. This project tested whether previously viewed or purchased products could improve that order. Personalization still had to respect business rules, remain fast and return to the standard ranking when history was sparse.
SUMMARYI helped turn interactions into affinity scores and evaluate an XGBoost learning-to-rank model that reorders search results. The experiment covered about 26,000 events and 4,450 products. Each user’s final interaction was held out and ranked against 20 sampled negative products. This is a within-user temporal holdout, not necessarily one global cutoff date. The personalized model outperformed the context-only baseline on all three ranking-quality measures.
30-second read
The project, evidence and decision.
- Problem
- Personalize product order from previous behavior.
- My role
- Affinity features, XGBoost learning to rank and last-interaction-per-user evaluation.
- Scale
- Tens of thousands of events and several thousand products.
- Result
- Better offline ranking across three measures: NDCG, hit rate and mean reciprocal rank (MRR).
- Decision
- Use visitor affinities in the ranking and measure their causal impact in an A/B test.
- Status
- Professional prototype evaluated offline.
Key diagram
From interactions to personalized ranking
01 · HISTORYVIEW1×
CART3×
PURCHASE5×
→AGGREGATE
02 · AFFINITIESUser × ProductA0.72B0.48C0.86D0.34
→RERANK
03 · XGBOOST LTR01P402P103P304P2
Per-user holdout · 21 candidates
04 · OFFLINENDCG↑
HIT RATE↑
MRR↑
05 · ONLINEA/BClick · cart · conversion · latency
Illustrative schematic: weights, affinities and bars are not experiment values. Historical events create user-product affinities. The reranker reorders candidates, then an online experiment must measure actual impact.
An anonymized case study describing the methods and decisions.Contribution & decision03
Can past behavior improve personalized product rankings?
I turned past interactions into user-product affinity scores, then compared rankings on each user’s final interaction against 20 sampled negatives. The XGBoost learning-to-rank model used these affinities more effectively than general session information alone. An A/B test must now measure the effect on real visitors.
Next validationOffline ranking quality
Time required to rerank results
Changes in clicks, carts and conversions
TakeawaysUser-product affinities inferred from interaction history improve offline product ranking. An A/B test is still required to determine whether this personalization increases clicks, add-to-cart events or purchases.
- History provides ranking signal in the 21-candidate test; this score does not describe full-catalogue retrieval.
- Reranking retains a baseline engine and a fallback for visitors without history.
- Product use requires an online test measuring benefit and latency.
01 — Interaction history
Views, add-to-cart events and purchases describe past preferences.
Views, add-to-cart events and purchases are weighted by strength and recency. They are then connected with product attributes to create affinities across explored categories, brands, ranges or other available catalogue characteristics.
This representation supports score explanation and a fallback when history is insufficient. It also separates repeated preferences from isolated events without exposing identity or individual-level data in the public presentation.
02 — Learning to rank
The model learns to reorder a candidate list.
An XGBoost learning-to-rank model combines affinity features, available context and product signals to assign each candidate a score.
The search engine remains responsible for producing a relevant initial set. The reranker then operates on a bounded list, clarifying each component’s role and allowing personalization to be turned off without losing baseline results.
03 — Protocol
Hold out each user’s final interaction.
Affinities are built from history preceding each user’s final interaction. The model ranks that positive product against 20 sampled negatives, or 21 candidates. This is not full-catalog retrieval. NDCG, Hit Rate and Mean Reciprocal Rank (MRR) provide complementary measures.
The comparison isolated two hypotheses. At K = 5, the report gives approximately 0.52 / 0.61 / 0.27 for NDCG / Hit Rate / MRR, versus 0.05 / 0.21 / 0.09 for the context-only baseline. User-product affinities improved all three metrics, while a model based only on broad context remained weak. Integration experiments also exposed excessive latency for some reranking strategies, making it an architecture criterion.
04 — Limitation
The next step is an A/B test with real visitors.
Offline evaluation checks whether the model places relevant products closer to the top of the list. It does not yet measure the model’s real effect on visitor behavior.
The next step is to define eligible visitors, the ranking shown when personalization is unavailable, diversity rules and the A/B-test metrics: clicks, add-to-cart events, conversions and response time.