Skip to main content

Profile First, Session After — Resolving "Apple" in Search

Updated 3 min readMarkdown

A marketplace selling groceries and electronics had a problem with one word. Search “apple” and the first page mixed Granny Smiths with iPhone chargers. Whatever the shopper meant, half the page was noise.

The textbook fix is a personalisation model: a machine-learning system trained on each shopper’s history to predict what they mean. The estimate was a quarter. The data for a simpler answer already existed.

Step 1: Spot the ambiguous queries

A table rebuilt every night from click logs recorded which product categories each query leads to. Let P(c|q) be the share of clicks for query q that land in category c. A query’s clarity is the share of its strongest category:

$$clarity(q) = \max_c P(c|q)$$

“Bananas” scores 0.97: nearly every click goes to Fresh Fruit. “Apple” scores 0.55, split between fruit and phone accessories. Queries below 0.85 count as ambiguous.

Step 2: Build a profile

For each returning shopper, a nightly job computes a profile: the mix of categories behind their past searches. Recent searches count more, using a weight that halves every h days (the half-life):

$$w_i=0.5^{\frac{age_i}{h}}$$

The profile share for category c is the weighted fraction of past searches that landed there:

$$prof(c)=\frac{\sum_i w_i[ci=c]}{\sum_i w_i}$$

The square brackets mean “1 if true, 0 if false”.

Step 3: Blend in the session

A session is one visit: the run of searches before the shopper leaves. The profile describes the shopper in general, while the session says what they’re doing right now. Both go into a context mix.

The first search of a visit uses the profile alone. The second averages the profile with the first query’s category mix. The third averages the profile with the first two, and so on. For the k-th search:

$$ctx_k(c)=\frac{1}{k}(prof(c)+\sum_{j<k}P(c|q_j))$$

So “apple” after “usb-c hub” and “laptop stand” leans toward electronics, even for a shopper who usually buys groceries.

Step 4: Nudge, don’t filter

For an ambiguous query, each product’s score is multiplied by a small boost based on its category’s share in the context mix:

$$score'=score \cdot (1+\beta \cdot ctx(c_{item}))$$

β sets the maximum strength. Nothing is removed, so the other meaning still appears on the first page, just lower.

The result

An AB test, which splits traffic between the old and new ranking, showed more clicks on top results for ambiguous queries. The gain was bigger for later searches in a visit than for first searches: what a shopper just typed turned out to be a stronger clue than what they did last month. There was no model to train, and every nudge could be explained from two tables.

No comments yet. Be the first to comment.