Skip to main content
Contextual affinities are attributes relevant to your users only in specific contexts. They ensure that certain preferences apply only where they make sense. This improves the relevance and accuracy of personalized search results. For example, if a user buys white furniture, search results could guide them to other white furniture items. However, search results for other categories shouldn’t rely on the user’s color preferences. Preferring white furniture doesn’t mean they prefer white hardware tools. By applying contextual affinities, personalization becomes more precise and effective. It gives your users search results that match their interests and needs in the right context.

Preparing your index

To enable contextual affinities, add a new attribute to your . You can add it by hand, or automate the task with a script. This attribute stores context-specific details in each of your . This gives more relevant search results based on the user’s situation. The following example adds hierarchicalAffinities as a contextual affinity attribute:
JSON
The first record is tagged with Hard Goods > Desk Chairs > White. This approach considers user preferences, such as a liking for white chairs, only when recommending desk chairs. In the second record, the hierarchicalAffinities attribute is more flexible. It categorizes the iPhone 15 under “Hard Goods” and “Cell Phones”. It also sets the color as “Gold” with Hard Goods > Cell Phones > Gold. It adds a brand-specific categorization under Apple > Gold. This approach lets you capture detailed preferences like color and brand affinity in each context.

Adding a contextual affinity to your configuration

After you add the contextual affinity to all records in your index, declare it as a facet. Then, select it as an affinity on the Advanced Personalization Configuration page. Here, you can simplify your configuration by consolidating attributes. For example, instead of separate color and brand attributes, use a hierarchicalAffinities attribute that stores color and brand details for each context.
Last modified on September 16, 2026