ReQL Functions

Functions may be used to enhance your ReQL queries – for example up-sell or getting nearby items can be achieved easily by functions.

There are various functions like math functions (rounding, computing square root …), string functions (converting case), function for getting size of set or string, getting current timestamp, functions for conversions between types (for example conversion between date in a text representation and timestamp) or even lambda functions. If you are missing some function that you would like to use, please let us know.

ReQL function can take arguments and returns a single value. Arguments are placed between parentheses and are separated by commas – for example computing base 2 logarithm of 8 looks like this: log(8,2). If the function takes no arguments the parentheses may be omitted (for e.g. now). If the function is given wrong number of arguments, or the arguments have unsupported type, an error is produced. If any of the arguments is null, then result is also a null value.

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"]
NameDescriptionExample
now

Returns current timestamp

now() > timestamp("2015-06-24T17:35:50Z")
random

Returns a random number between 0 and 1

1>=random()>=0
size

Returns the length of a string or number of objects in a set

size("Recombee") == 8
item_values

Returns property values of a particular item as a dictionary

item_values("item-42")["description"]
reduce

Reduces a set into a single value using an operator

reduce("+", {1, 2, 3}) == 6
NameDescriptionExample
map

Applies the lambda expression to every member of a set

map(lambda 'x': 2*'x', {1, 2, 3}) == {2, 4, 6}
select

Returns only those values of input set for which the lambda expression returns true

select(lambda 'x': 'x' > 5, {10, 2, 13, 1}) == {10, 13}
exists

Returns true if lambda expression is satisfied for at least one element of the input set

exists(lambda 'x': 'x' > 5, {2, 13, 4})
NameDescriptionExample
boolean

Converts the argument to boolean

boolean("") == False
number

Converts the argument to number

number("456") == 456
string

Converts the argument to string

string(123) == "123"
timestamp

Converts the argument to timestamp

timestamp("2015-06-25T11:08:44Z") == timestamp(1435230524)
NameDescriptionExample
max

Returns the maximum of n arguments

max(147,42,81.9) == 147
min

Returns the minimum of n arguments

min(147,42,81.9) == 42
avg

Returns the average of n numbers

avg(2, 4) == 3
round

Returns closest integer

round(4.5) == 5
floor

Returns largest preceding integer

floor(4.3) == 4
ceil

Returns smallest following integer

ceil(4.3) == 5
abs

Returns non-negative value of the argument without regard to its sign

abs(-4.3) == 4.3
sqrt

Returns the square root of the argument

sqrt(4) == 2
powReturns 𝑓𝑖𝑟𝑠𝑡_𝑎𝑟𝑔𝑢𝑚𝑒𝑛𝑡𝑠𝑒𝑐𝑜𝑛𝑑_𝑎𝑟𝑔𝑢𝑚𝑒𝑛𝑡
pow(10,3) == 1000
log

Returns the logarithm of the argument

log(1000) == 3
NameDescriptionExample
upper

Converts all letters to the capital letters

upper("AbCdefG") == "ABCDEFG"
lower

Converts all letters to the small letters

lower("AbCdefG") == "abcdefg"
split

Splits a string into sub-strings using a separator

split("abc,def,ghi", ",") == ["abc", "def", "ghi"]
NameDescriptionExample
user_interactions

Returns list of interactions by a particular user

user_interactions(context_user["userId"], {"purchases"})
NameDescriptionExample
num_item_bookmarks

Returns the number of bookmarks of an item

num_item_bookmarks('itemId') < 10
num_item_detail_views

Returns the number of detail views of an item

num_item_detail_views('itemId') < 10
num_item_purchases

Returns the number of purchases of an item

num_item_purchases('itemId') < 10
num_item_ratings

Returns the number of ratings of an item

num_item_ratings('itemId', "negative") < 10
NameDescriptionExample
segment_items

Get items in a Segment

'itemId' in segment_items("genres", "thriller")
item_segments

Get Item Segments to which the item belongs

"thriller" in item_segments("genres", 'itemId')
NameDescriptionExample
earth_distance

Returns the orthodromic distance between two points (given as their latitude and longitude in degrees) in meters

earth_distance(50.075538,14.437800,52.520007,13.404954) < 282000
geo_polygon

Creates a spherical polygon represented by points with geographical coordinates

geo_polygon([[40.800, -73.957], [40.767, -73.981], [40.764, -73.972], [40.796, -73.949]])
geo_radius

Creates a spherical cap represented by a center with geographical coordinates and a radius in km

geo_radius([40.689167, -74.044444], 10)
© Copyright 2026, Recombee s.r.o
docs.recombee.com