Context

NameDescriptionExample
context_item

Retrieves property value of the item, that is currently viewed by the user.

context_item["price"]
context_user

Retrieves property value of the user, that is about to obtain the recommendations.

context_user["country"]
context_segment

Retrieves the Segment on which the recommendations are based

context_segment["segmentId"]

Context item function is used in Recommend Items to Item and Recommend Item Segments to Item for retrieving property values of the item, that is currently viewed by the user.

context_item[property_name]
KeyTypeMeaning
property_namestring

Name of property to be retrieved. If property of this name does not exist, an error is produced.

(Note that Context item function is a bit special function – it takes no arguments and returns a map name of property -> value representing the context item. property_name placed in square brackets is the key to this map.)

Consider following sample items.

name
String
price
Number
category
String
"television-42"369

"television"

"television-49"449

"television"

"remote-control-13"25

remote-control

Suppose that the user is currently viewing television-42. Then the following expression returns 369, because that is the price of the context item.

context_item["price"]

Suppose that the user is currently viewing television-42. You can recommend him products from the same category with higher price. The filter would look like this:

'price' > context_item["price"] and 'category' == context_item["category"]

Considering the sample items above, only television-49 will pass the filter.

If you don’t want to be so restrictive about the cheaper products, you shall use booster instead of filter and boost the products with higher price. The booster could look like this:

if 'category' != context_item["category"] then 0.1 else if  'price' > context_item["price"] then 1 else 0.5

Context user function is used for retrieving property values of the user that the recommendations are for.

context_user[property_name]
KeyTypeMeaning
property_namestring

Name of property to be retrieved. If property of this name does not exist, an error is produced.

(Note that Context user function is a bit special function – it takes no arguments and returns a map name of property -> value representing the context user. property_name placed in square brackets is the key to this map.)

Consider following sample users, which have specified languages they understand:

userId
String
languages
Set
"user-27"["EN"]
"user-29"["EN", "FR"]

And sample items, which are some movies:

itemId
String
language
String
"Pulp Fiction""EN"
"Le fabuleux destin d Amelie Poulain""FR"
"Fight Club""EN"
"Kolja""CS"

Suppose that I want to recommend movies to users, but only movies that the users can understand. I can use the following filter:

'language' in context_user["languages"]

For user-27 (which can speak only english) Pulp Fiction or Fight Club can be recommended.

For user-29 (which can speak english and french) Pulp Fiction, Fight Club or Le fabuleux destin d Amelie Poulain can be recommended.

Context Segment function is used in Recommend Item Segments to Item Segment for retrieving the Item Segment to which is being recommended.

context_segment[property_name]
KeyTypeMeaning
property_namestring

Name of property to be retrieved. Currently only segmentId is supported.

// If the context Segment is "fairy tales"
// then explicitly disallow "tabloid news" Segment to be ever recommended

if context_segment["segmentId"] == "fairy tales"
	then 'segmentId' != "tabloid news"
	else true
© Copyright 2026, Recombee s.r.o
docs.recombee.com