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 Integer | 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:
Then the recommender may only choose from the following movies:
Name String | Year Integer | 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:
You can access value of a property by putting name of the property into the single quotes. Strings are enclosed in double quotes.
Only the following items can be recommended:
Name String | Year Integer | 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.
As the Genres is a set property, you can use the in operator for checking whether Thriller is listed in the item’s genres:
Only the following items pass the filter:
Name String | Year Integer | 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 available. 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 typeboolean(the implicit value for all items will benull, which is OK). -
For deleted items, set the value of
deletedtrue. -
For recommendations, use the following filter:
-
If the item becomes available again, you may set
deletedtofalse.
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:
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 Integer | 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:
The three items will not be recommended.
Re-rank a Given Set of Items
Use filter (usually sent as a dynamic parameter of the API recommendation request):
- The recommendation engine will re-rank the given set of items for the particular user.
- It is supported to provide thousands of IDs in the query
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:
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:
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 than the currently viewed one with the following booster in Recommend Items to Item:
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
citygiving the city where each user live.
To recommend only items available in a user’s city, use filter:
context_user function is used for retrieving property values of the user for which you request the recommendations.
Recommend Only Items from Subscribed Topics
Assume your site contains articles about various topics. The users can choose which topics are interesting for them in order to receive personalized newsletters with articles from these topics.
The subscribed topics are stored for each user in a User property of type set called subscribed_topics.
Each article can belong to multiple topics, stored in the topics item property of the type set.
The following filter allows only items that contain at least one matching topic to be recommended:
The & operator returns the intersection of the two sets, which must be non-empty.