Session Contextualization

Categories

TL;DR

Yes, there is a way to help shoppers find what they need, without tracking or collecting personal information.

It’s called session contextualization and, here at Empathy.co, it is how we interpret shoppers’ interactions in an ecommerce store, in order to provide a delightful user experience.

You can rest assured that there are some things we just won’t do. On one hand, we strongly believe that tracking people is none of our business. On the other hand, there are better ways we can help shoppers, that we believe are more respectful and ethical.

Analogy

Imagine entering a grocery store in your neighborhood and being approached by an employee saying:

“Before you start shopping, please tell me your name, age, gender, size, contact information, nationality, and interests.”

Creepy. No, the store shouldn’t need your personal data. There’s no way of telling anything about your intent in this particular time and place, just from your demographics or profile. One could argue that if you’re searching for a t-shirt, then your size and favorite color may be relevant. Even then, you might be searching for something for someone else. But what if they added:

“Oh, and before you came in, I observed you and learned a few things. You just bought beer and mustard in that other store. Also, you invited Mary and John over for a barbecue this weekend. So, would you like some burgers?”

That’s even worse. It’s a very stick-your-nose-elsewhere-please, sort of situation. (We don’t extract data from other sources and, of course, we don’t leak data out.) As if that wasn’t intrusive enough, they might say:

“Hey, wait! Here’s our selection of bread knives. You asked for a bread knife 13 days ago but you didn’t pick one, in the end.”

Maybe you already bought it somewhere else or you found the one that you had lost at home. In addition to being a weird and invasive experience, remembering what you searched for in the past is useless, most of the time.

Let’s give this scenario a fresh start, keeping in mind that for session contextualization, what matters is what is happening here and now.

“Hello, how can I help you?”

This is behavior that you’d find more suitable, right? Well, this is our equivalent of a blank search box. At most, you’d expect some popular items to be exhibited at the counter and on the endcaps, but not anything particularly directed at you.

From this point on, you’d start hinting at your interests via different inputs. When you ask for peanut butter, browse the fine wines section, or put cured ham into your basket, all of these interactions contribute to building the current session.

The store employee would then observe your actions and apply their expertise accordingly, to try to help you.

Session contextualization basically means matching the current session with previously learned behaviors, then suggesting next actions that are statistically relevant.

Sessions

A session is composed of a timeline of events (shopper interactions). Events are defined by their type and attributes.

  • General attributes: Store instance, language, and timestamp; applied to all events.
  • Search event: A search on the store’s webpage. Attributes here are the query terms entered and (optional) active filters.
  • Click event: A click on an item. Attributes defining the interaction are the product identifier and product attributes from the store’s catalog (e.g., the product clicked is classified as Fruit, the t-shirt clicked is size: L and color: Red).
  • Add2Cart event: An item added to the shopping cart by the shopper; defined by the same attributes as click events.
Example of a session
The shopper initially searched for “orange” and then refined the query to “orange juice”. Next, they clicked on one of the search results but ended up adding a product from another brand to the cart. Finally, the shopper searched for “butter” and added one item to their cart from the results presented.

As a result of our design principles at Empathy.co, there are certain boundaries that we can guarantee about shopper sessions and how we handle them:

  • Store Isolation: Session spaces are hard-partitioned by store. That is, we don’t mix session data between stores (e.g., the scope of store A in Spanish is completely isolated from the scope of store B in English)
  • No PII: No personal data is collected as part of the session. Instead, a session ID is used to correlate shopper interactions.
  • Fresh Start: Given that the lifespan of the session ID is the span of the visit to the store, a session starts when a shopper enters the ecommerce store and finishes when they leave. If the same person enters more than once at different times, those are considered to be two independent sessions and are not correlated at all.
  • In-memory Storage: We don’t store shoppers' sessions, but instead keep active sessions alive in memory. Once a session is over, we simply learn from it by contributing to wisdom of the crowd, then forget about it individually.

Use Cases

So, how can we help shoppers? By taking into context what has happened in the current session:

Recommend Searches

Suggest other search terms to try next, noting a semantic difference about the suggestions.

  • Next Queries: Different term that is associated with a shopper's most recent searches
Since you searched for “lemon”, you may find “orange” a useful term for your next search.
  • Related Tags: Suggested refinement of the shopper's last search, to help narrow down results
Since you searched for “orange”, you may want to try “orange juice” for more specific results.

Recommend Products

Present recommended next items.

  • Similar: Show items similar to the current product being viewed, giving the shopper the ability to compare options.
Since you searched for “orange” and you’re taking a look at orange juice by the brand “L’Orange” you may want to compare it with this other orange juice by the brand “Naranjito”.
  • Complementary: Suggest other items that are commonly bought together, after some products have been selected by the shopper.
Since you are browsing our “barbecue” section and you already added burgers to your basket, you may want to see our selection of ketchup.

Sort Results

Affect search results by boosting certain attributes. Show items that are statistically more relevant to the context at the top of the results page.

Since you have looked at several products in our “fresh produce” department, for your following search for “tomato”, we’ll show you items belonging to this category first in the search results.

Techniques

Now that it’s clear what sessions are, let’s take a look at the techniques we use to contextualize them and apply them to the use cases we laid out.

Query Graphs

Query graphs analyze sequences of search terms that were used in sessions, then add them up and connect them as nodes in graphs. We measure the quantity and performance of the searches, which give us the weights of the connections.

We use query graphs for search recommendations like Next Queries and Related Tags. Speaking of recommendations, this post on Graph Modeling is a great read that goes more in-depth on this topic!

Example of a query graph

This technique provides contextualization using the latest search events in the shopper’s current session.

Frequent Pattern Mining

Frequent pattern mining analyzes the attributes of events from sessions, and then finds the most common, relevant patterns. A pattern comes in the form of sequences, e.g., A → B → C

We then consider the sequence a rule. Antecedent: A → B, Consequence: C

If the shopper’s current session matches the antecedent pattern A → B, then we derive that C may be a relevant suggestion for their next action.

Example of a "Frequent Pattern Mining" rule
Here, the shopper has already added some products from the “barbecue” section to their cart, and now they are searching for “tomato”. Product 19 (ketchup) will be boosted based on the context, so that it appears in the first position of the results shown to the shopper.

We apply frequent pattern mining in two ways: ordered and unordered.

Prefix-Span (ordered):

This algorithm preserves the order of the events in the original sessions to generate patterns. This becomes relevant in understanding a search event followed by an interaction with a product as a cause-effect relationship.

FP-Growth (unordered):

This algorithm doesn’t look at the order of events when generating patterns. This may seem like a limitation but it works perfectly when learning about items that are usually bought together or items that are similar. In those use cases, the order doesn’t matter much.

Clustering

Clustering is a technique that divides the sessions into buckets, based on their similarity. For each cluster, we have a representative session that is a mixture of all the sessions that were aggregated to it.

We can analyze a shopper’s current session and match it with the most similar representative. Then, we can use that information to make suggestions. For example, if a session matches 87% to cluster K1 and only 5% to cluster K2, the shopper would be shown items that were bought in sessions similar to K1.

We can also use clustering combined with the other techniques to divide the scope of rules into several independent spaces. That way, the ruleset selected matches that of the representative used.

Wrap-up

What you would expect from a physical store is respect, common sense and empathy. That’s exactly what our session contextualization approach allows ecommerce stores to offer their customers.


We design our systems to behave the way we would like to be treated: respectfully. Session contextualization helps shoppers find what they are looking for, without the use of tracking or personal data. By implementing techniques that are non-invasive, businesses have the ability to recommend products, searches, and sort results to provide a user experience that shoppers can trust.