Filtering and Boosting

Filtering

In filtering, the expression must return boolean value for each item. If the returned value is true, the item passed the filter; if the value is false, the item does not pass and will be discarded. The value is computed from set property values of the individual items.

Consider the following table of items in sample movie-recommendation domain:

Name: string Year:int Director: string Genres: set Parental-Advisory:boolean
Pulp Fiction 1994 Quentin Tarantino
{“Crime Fiction”,”Drama”
“Thriller” }
true
King Kong 2005 Peter Jackson
{“Action”, “Drama”,
“Adventure” }
false
Fight Club 1999 David Fincher
{“Drama”, “Existentialism”}
true
The Lord of the Rings: The Return of the King 2003 Peter Jackson
{ “Adventure”, “Fantasy”,
“Action” }
false
The Dark Knight 2008 Christopher Nolan
{“Superhero”,”Drama”
,”Action”,”Adventure”,
“Thriller”,”Crime Fiction”}
false
Silence of the Lambs 1991 Jonathan Demme
{“Crime Fiction”, “Drama”,
“Thriller”, “Horror” }
true
Dead Alive 1992 Peter Jackson
{“Horror”, “Comedy”}
true
... and 10000 other movies

Example 1

By default, when items are to be recommended to a given user, the recommender selects any items which seem relevant to the user. However, it may be your policy not to recommend items with Parental-Advisory flag set on. Hence you may use the following simple ReQL filtering expression:

not 'Parental-Advisory'

Then the recommender may only choose from the following movies:

Name: string Year:int Director: string Genres: set Parental-Advisory:boolean
King Kong 2005 Peter Jackson
{“Action”, “Drama”,
“Adventure” }
false
The Lord of the Rings: The Return of the King 2003 Peter Jackson
{ “Adventure”, “Fantasy”,
“Action” }
false
The Dark Knight 2008 Christopher Nolan
{“Superhero”,”Drama”
,”Action”,”Adventure”,
“Thriller”,”Crime Fiction”}
false
... and 5926 other movies

Example 2

If you want to allow only items without Parental-Advisory which were directed by Peter Jackson (for example because a user selected such a filter at your site) you can do it by:

(not 'Parental-Advisory') and ('Director' == "Peter Jackson")

Note

You can access value of a property by putting name of the property into the single quotes. Strings are enclosed in double quotes.

Only following items can be recommended:

Name: string Year:int Director: string Genres: set Parental-Advisory:boolean
King Kong 2005 Peter Jackson
{“Action”, “Drama”,
“Adventure” }
false
The Lord of the Rings: The Return of the King 2003 Peter Jackson
{ “Adventure”, “Fantasy”,
“Action” }
false

Example 3

As another example, consider that user entered the Thriller section of your system’s catalog. Then you sure wish to recommend thrillers, ignoring the fact that usually, the user likes comedies. You may do this using another ReQL filtering expression:

"Thriller" in 'Genres'

Then only the following items will pass the filter:

Name: string Year:int Director: string Genres: set Parental-Advisory:boolean
Pulp Fiction 1994 Quentin Tarantino
{“Crime Fiction”,”Drama”
“Thriller” }
true
The Dark Knight 2008 Christopher Nolan
{“Superhero”,”Drama”
,”Action”,”Adventure”,
“Thriller”,”Crime Fiction”}
false
Silence of the Lambs 1991 Jonathan Demme
{“Crime Fiction”, “Drama”,
“Thriller”, “Horror” }
true
... and 3141 other movies

Handling deleted items

Filtering offers you an elegant way of handling deleted/obsolete items in the catalog. In many situations, it may happen that some items become unavailable and hence should not be recommended anymore. Considering interaction data, however, such items may still be important for the recommender. For example, the recommender may find out that users who liked a no more available item, x, will probably like another item, y, which is still actual. Therefore, it is undesirable to simply delete x, deleting also all the related interactions in cascade.

With filtering, you may handle item deletes using the following scheme:
  • Create a dedicated item property, such as deleted, of type boolean (the implicit value for all items will be null, which is OK).
  • For deleted items, set the value of deleted true.
  • For recommendations, use the following filter:
not 'deleted'
  • Occasionally, if the item becomes available again, you may set deleted false.

Such a mechanism cay easily be extended to control availability over different regions, customer licenses, etc.

Boosting

In advanced applications, besides filtering, you may wish to boost recommendation rates of some items. In contrast to filtering, where items may be completely blocked, in boosting, you may tell the recommender to prefer some items among others. Indeed, by default, it is a task of the recommender itself to select the items which are the most relevant. However, it may be your policy to purposefully bias the recommender toward your business goals.

For example, considering the above table of movies, one may wish to promote the movies which are new and were filmed after 2000, especially if they were filmed after 2005. Then the following boosting query can handle that:

if 'Year' <= 2000 then 1 else (if 'Year' <= 2005 then 1.5 else 2)

As you can see, boosting expressions return numbers rather than booleans as in case of filtering. Specifically, they provide the items with coefficients by which the internal scores determined by the recommender will be multiplied.

The boosting coefficients assigned by the query are shown in the following table:

Name: string Year:int Boosting
Pulp Fiction 1994 1.0
King Kong 2005 1.5
Fight Club 1999 1.0
The Lord of the Rings: The Return of the King 2003 1.5
The Dark Knight 2008 2.0
Silence of the Lambs 1991 1.0
Dead Alive 1992 1.0
... and 10000 other movies

Examples

  • Exclude some items from recommendations using their IDs

    Use filter:

    'itemId' not in {"item-127", "item-756", "item-568"}
    

    The three items will not be recommended.


  • Recommend related items by the same manufacturer

    Suppose that the items have a string property manufacturer and the user is viewing a product detail page.

    If you want to give the user related items using Recommend items to item, but restrict them to the manufacturer of the currently viewed item, use filter:

    'manufacturer' == context_item["manufacturer"]
    

    context_item function is used for retrieving property values of the item, that is currently viewed by the user.


  • Boost items that were published in last 24 hours

    Suppose that the items have a timestamp property published_date. Then you can use this booster:

    if 'published_date' >= now() - 24 * 60 * 60 then 2 else 1
    

    now returns current UTC timestamp in seconds.

    24 * 60 * 60 is the number of seconds in 24 hours.


  • Up-sell

    Suppose that the items have a double property price. Slightly boost items that are more expensive then the currently viewed one with following booster in Recommend items to item:

    if 'price' > context_item["price"] then 1.2 else 1
    

  • Recommend only items available in user’s city

    • Suppose that the items have a set property cities. It contains cities in which the items are available.
    • Suppose that the users have a string property city giving the city where each user live.

    To recommend only items available in a user’s city, use filter:

    context_user["city"] in 'cities'
    

    context_user function is used for retrieving property values of the user for which you request the recommendations.