recombee_api_client 2.1.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +28 -14
- data/lib/recombee_api_client.rb +2 -2
- data/lib/recombee_api_client/api/add_bookmark.rb +8 -2
- data/lib/recombee_api_client/api/add_cart_addition.rb +8 -2
- data/lib/recombee_api_client/api/add_detail_view.rb +8 -2
- data/lib/recombee_api_client/api/add_item_property.rb +16 -0
- data/lib/recombee_api_client/api/add_purchase.rb +8 -2
- data/lib/recombee_api_client/api/add_rating.rb +8 -2
- data/lib/recombee_api_client/api/add_user_property.rb +13 -1
- data/lib/recombee_api_client/api/merge_users.rb +1 -1
- data/lib/recombee_api_client/api/recommend_items_to_item.rb +50 -17
- data/lib/recombee_api_client/api/recommend_items_to_user.rb +52 -15
- data/lib/recombee_api_client/api/recommend_next_items.rb +69 -0
- data/lib/recombee_api_client/api/recommend_users_to_item.rb +41 -13
- data/lib/recombee_api_client/api/recommend_users_to_user.rb +44 -16
- data/lib/recombee_api_client/api/search_items.rb +178 -0
- data/lib/recombee_api_client/api/set_view_portion.rb +8 -2
- data/lib/recombee_api_client/api/user_based_recommendation.rb +1 -1
- data/lib/recombee_api_client/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c24717b90f3a557ec2ceda5bf24f0c62f1ae80384b0a993c7545c156b8586ddd
|
4
|
+
data.tar.gz: d1a88f7d65d7dc7456068975263d435d06059838d9e8c4a1deedf9cbce42e8c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b33bd56d774de4240d04decbc4752b7c506062b26519b1d9e5afb335a61603bd2ba6723faeea545fe773cd659f54fb72490bafe66a112b6b31438eb7d2b0f6f
|
7
|
+
data.tar.gz: 1ea09e4189c88f8aa13f2e35ba36c1792da8877ae40ee1ca787f2f414ebc1da149f3557c0f26c09575106b25ec8019692d4b83e1ae1de88dce22574bdab8051c
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ Or install it yourself as:
|
|
29
29
|
require 'recombee_api_client'
|
30
30
|
include RecombeeApiClient
|
31
31
|
|
32
|
-
client = RecombeeClient('--my-database-id--', '--
|
32
|
+
client = RecombeeClient('--my-database-id--', '--db-private-token--')
|
33
33
|
|
34
34
|
# Generate some random purchases of items by users
|
35
35
|
NUM = 100
|
@@ -55,8 +55,13 @@ begin
|
|
55
55
|
client.send(Batch.new(purchases))
|
56
56
|
|
57
57
|
# Get recommendations for user 'user-25'
|
58
|
-
|
59
|
-
puts "Recommended items for user-25: #{
|
58
|
+
response = client.send(RecommendItemsToUser.new('user-25', 5))
|
59
|
+
puts "Recommended items for user-25: #{response}"
|
60
|
+
|
61
|
+
# User scrolled down - get next 3 recommended items
|
62
|
+
response = client.send(RecommendNextItems.new(response['recommId'], 3))
|
63
|
+
puts "Next recommended items for user-25: #{response}"
|
64
|
+
|
60
65
|
rescue APIError => e
|
61
66
|
puts e
|
62
67
|
# Use fallback
|
@@ -71,8 +76,8 @@ include RecombeeApiClient
|
|
71
76
|
NUM = 100
|
72
77
|
PROBABILITY_PURCHASED = 0.1
|
73
78
|
|
74
|
-
client = RecombeeClient('--my-database-id--', '--
|
75
|
-
client.send(ResetDatabase.new) # Clear everything from the database
|
79
|
+
client = RecombeeClient('--my-database-id--', '--db-private-token--')
|
80
|
+
client.send(ResetDatabase.new) # Clear everything from the database (asynchronous)
|
76
81
|
|
77
82
|
# We will use computers as items in this example
|
78
83
|
# Computers have five properties
|
@@ -103,7 +108,7 @@ requests = (1..NUM).map do |i|
|
|
103
108
|
},
|
104
109
|
#optional parameters:
|
105
110
|
{
|
106
|
-
|
111
|
+
:cascade_create => true # Use cascade_create for creating item
|
107
112
|
# with given itemId, if it doesn't exist
|
108
113
|
}
|
109
114
|
)
|
@@ -117,29 +122,38 @@ requests = []
|
|
117
122
|
(1..NUM).map{|i| "computer-#{i}"}.each do |item_id|
|
118
123
|
user_ids = (1..NUM).map{|i| "user-#{i}"}
|
119
124
|
user_ids = user_ids.select { |_| rand(0.0..1.0) < PROBABILITY_PURCHASED }
|
120
|
-
# Use
|
121
|
-
user_ids.each { |user_id| requests.push(AddPurchase.new(user_id, item_id,
|
125
|
+
# Use cascade_create to create unexisting users
|
126
|
+
user_ids.each { |user_id| requests.push(AddPurchase.new(user_id, item_id, :cascade_create => true)) }
|
122
127
|
end
|
123
128
|
|
124
129
|
# Send purchases to the recommender system
|
125
130
|
client.send(Batch.new(requests))
|
126
131
|
|
127
132
|
# Get 5 recommendations for user-42, who is currently viewing computer-6
|
128
|
-
recommended = client.send(RecommendItemsToItem.new('computer-6', 'user-42', 5) )
|
129
|
-
puts "Recommended items: #{recommended}"
|
130
|
-
|
131
133
|
# Recommend only computers that have at least 3 cores
|
132
134
|
recommended = client.send(
|
133
|
-
RecommendItemsToItem.new('computer-6', 'user-42', 5, {
|
135
|
+
RecommendItemsToItem.new('computer-6', 'user-42', 5, {:filter => "'num-cores'>=3"})
|
134
136
|
)
|
135
137
|
puts "Recommended items with at least 3 processor cores: #{recommended}"
|
136
138
|
|
137
|
-
# Recommend only items
|
139
|
+
# Recommend only items that are more expensive then currently viewed item (up-sell)
|
138
140
|
recommended = client.send(
|
139
141
|
RecommendItemsToItem.new('computer-6', 'user-42', 5,
|
140
|
-
{
|
142
|
+
{:filter => "'price' > context_item[\"price\"]"})
|
141
143
|
)
|
142
144
|
puts "Recommended up-sell items: #{recommended}"
|
145
|
+
|
146
|
+
# Filters, boosters and other settings can be also set in the Admin UI (admin.recombee.com)
|
147
|
+
# when scenario is specified
|
148
|
+
recommended = client.send(
|
149
|
+
RecommendItemsToItem.new('computer-6', 'user-42', 5, {:scenario => 'product_detail'})
|
150
|
+
)
|
151
|
+
|
152
|
+
# Perform personalized full-text search with a user's search query (e.g. 'computers').
|
153
|
+
matches = client.send(
|
154
|
+
SearchItems.new('user-42', 'computers', 5, {:scenario => 'search_top'})
|
155
|
+
)
|
156
|
+
puts "Matched items: #{matches}"
|
143
157
|
```
|
144
158
|
|
145
159
|
### Exception handling
|
data/lib/recombee_api_client.rb
CHANGED
@@ -18,13 +18,13 @@ module RecombeeApiClient
|
|
18
18
|
include HTTParty
|
19
19
|
|
20
20
|
BATCH_MAX_SIZE = 10000
|
21
|
-
USER_AGENT = {'User-Agent' => 'recombee-ruby-api-client/
|
21
|
+
USER_AGENT = {'User-Agent' => 'recombee-ruby-api-client/3.1.0'}
|
22
22
|
|
23
23
|
##
|
24
24
|
# - +account+ -> Name of your account at Recombee
|
25
25
|
# - +token+ -> Secret token obtained from Recombee for signing requests
|
26
26
|
# - +protocol+ -> Default protocol for sending requests. Possible values: 'http', 'https'.
|
27
|
-
def initialize(account, token, protocol = '
|
27
|
+
def initialize(account, token, protocol = 'https', options = {})
|
28
28
|
@account = account
|
29
29
|
@token = token
|
30
30
|
@protocol = protocol
|
@@ -10,7 +10,7 @@ module RecombeeApiClient
|
|
10
10
|
#Adds a bookmark of a given item made by a given user.
|
11
11
|
#
|
12
12
|
class AddBookmark < ApiRequest
|
13
|
-
attr_reader :user_id, :item_id, :timestamp, :cascade_create
|
13
|
+
attr_reader :user_id, :item_id, :timestamp, :cascade_create, :recomm_id, :additional_data
|
14
14
|
attr_accessor :timeout
|
15
15
|
attr_accessor :ensure_https
|
16
16
|
|
@@ -22,6 +22,8 @@ module RecombeeApiClient
|
|
22
22
|
# * *Optional arguments (given as hash optional)*
|
23
23
|
# - +timestamp+ -> UTC timestamp of the bookmark as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
|
24
24
|
# - +cascadeCreate+ -> Sets whether the given user/item should be created if not present in the database.
|
25
|
+
# - +recommId+ -> If this bookmark is based on a recommendation request, `recommId` is the id of the clicked recommendation.
|
26
|
+
# - +additionalData+ -> A dictionary of additional data for the interaction.
|
25
27
|
#
|
26
28
|
def initialize(user_id, item_id, optional = {})
|
27
29
|
@user_id = user_id
|
@@ -29,11 +31,13 @@ module RecombeeApiClient
|
|
29
31
|
optional = normalize_optional(optional)
|
30
32
|
@timestamp = optional['timestamp']
|
31
33
|
@cascade_create = optional['cascadeCreate']
|
34
|
+
@recomm_id = optional['recommId']
|
35
|
+
@additional_data = optional['additionalData']
|
32
36
|
@optional = optional
|
33
37
|
@timeout = 1000
|
34
38
|
@ensure_https = false
|
35
39
|
@optional.each do |par, _|
|
36
|
-
fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate"].include? par
|
40
|
+
fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","recommId","additionalData"].include? par
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
@@ -49,6 +53,8 @@ module RecombeeApiClient
|
|
49
53
|
p['itemId'] = @item_id
|
50
54
|
p['timestamp'] = @optional['timestamp'] if @optional.include? 'timestamp'
|
51
55
|
p['cascadeCreate'] = @optional['cascadeCreate'] if @optional.include? 'cascadeCreate'
|
56
|
+
p['recommId'] = @optional['recommId'] if @optional.include? 'recommId'
|
57
|
+
p['additionalData'] = @optional['additionalData'] if @optional.include? 'additionalData'
|
52
58
|
p
|
53
59
|
end
|
54
60
|
|
@@ -10,7 +10,7 @@ module RecombeeApiClient
|
|
10
10
|
#Adds a cart addition of a given item made by a given user.
|
11
11
|
#
|
12
12
|
class AddCartAddition < ApiRequest
|
13
|
-
attr_reader :user_id, :item_id, :timestamp, :cascade_create, :amount, :price
|
13
|
+
attr_reader :user_id, :item_id, :timestamp, :cascade_create, :amount, :price, :recomm_id, :additional_data
|
14
14
|
attr_accessor :timeout
|
15
15
|
attr_accessor :ensure_https
|
16
16
|
|
@@ -24,6 +24,8 @@ module RecombeeApiClient
|
|
24
24
|
# - +cascadeCreate+ -> Sets whether the given user/item should be created if not present in the database.
|
25
25
|
# - +amount+ -> Amount (number) added to cart. The default is 1. For example if `user-x` adds two `item-y` during a single order (session...), the `amount` should equal to 2.
|
26
26
|
# - +price+ -> Price of the added item. If `amount` is greater than 1, sum of prices of all the items should be given.
|
27
|
+
# - +recommId+ -> If this cart addition is based on a recommendation request, `recommId` is the id of the clicked recommendation.
|
28
|
+
# - +additionalData+ -> A dictionary of additional data for the interaction.
|
27
29
|
#
|
28
30
|
def initialize(user_id, item_id, optional = {})
|
29
31
|
@user_id = user_id
|
@@ -33,11 +35,13 @@ module RecombeeApiClient
|
|
33
35
|
@cascade_create = optional['cascadeCreate']
|
34
36
|
@amount = optional['amount']
|
35
37
|
@price = optional['price']
|
38
|
+
@recomm_id = optional['recommId']
|
39
|
+
@additional_data = optional['additionalData']
|
36
40
|
@optional = optional
|
37
41
|
@timeout = 1000
|
38
42
|
@ensure_https = false
|
39
43
|
@optional.each do |par, _|
|
40
|
-
fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","amount","price"].include? par
|
44
|
+
fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","amount","price","recommId","additionalData"].include? par
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
@@ -55,6 +59,8 @@ module RecombeeApiClient
|
|
55
59
|
p['cascadeCreate'] = @optional['cascadeCreate'] if @optional.include? 'cascadeCreate'
|
56
60
|
p['amount'] = @optional['amount'] if @optional.include? 'amount'
|
57
61
|
p['price'] = @optional['price'] if @optional.include? 'price'
|
62
|
+
p['recommId'] = @optional['recommId'] if @optional.include? 'recommId'
|
63
|
+
p['additionalData'] = @optional['additionalData'] if @optional.include? 'additionalData'
|
58
64
|
p
|
59
65
|
end
|
60
66
|
|
@@ -10,7 +10,7 @@ module RecombeeApiClient
|
|
10
10
|
#Adds a detail view of a given item made by a given user.
|
11
11
|
#
|
12
12
|
class AddDetailView < ApiRequest
|
13
|
-
attr_reader :user_id, :item_id, :timestamp, :duration, :cascade_create
|
13
|
+
attr_reader :user_id, :item_id, :timestamp, :duration, :cascade_create, :recomm_id, :additional_data
|
14
14
|
attr_accessor :timeout
|
15
15
|
attr_accessor :ensure_https
|
16
16
|
|
@@ -23,6 +23,8 @@ module RecombeeApiClient
|
|
23
23
|
# - +timestamp+ -> UTC timestamp of the view as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
|
24
24
|
# - +duration+ -> Duration of the view
|
25
25
|
# - +cascadeCreate+ -> Sets whether the given user/item should be created if not present in the database.
|
26
|
+
# - +recommId+ -> If this detail view is based on a recommendation request, `recommId` is the id of the clicked recommendation.
|
27
|
+
# - +additionalData+ -> A dictionary of additional data for the interaction.
|
26
28
|
#
|
27
29
|
def initialize(user_id, item_id, optional = {})
|
28
30
|
@user_id = user_id
|
@@ -31,11 +33,13 @@ module RecombeeApiClient
|
|
31
33
|
@timestamp = optional['timestamp']
|
32
34
|
@duration = optional['duration']
|
33
35
|
@cascade_create = optional['cascadeCreate']
|
36
|
+
@recomm_id = optional['recommId']
|
37
|
+
@additional_data = optional['additionalData']
|
34
38
|
@optional = optional
|
35
39
|
@timeout = 1000
|
36
40
|
@ensure_https = false
|
37
41
|
@optional.each do |par, _|
|
38
|
-
fail UnknownOptionalParameter.new(par) unless ["timestamp","duration","cascadeCreate"].include? par
|
42
|
+
fail UnknownOptionalParameter.new(par) unless ["timestamp","duration","cascadeCreate","recommId","additionalData"].include? par
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
@@ -52,6 +56,8 @@ module RecombeeApiClient
|
|
52
56
|
p['timestamp'] = @optional['timestamp'] if @optional.include? 'timestamp'
|
53
57
|
p['duration'] = @optional['duration'] if @optional.include? 'duration'
|
54
58
|
p['cascadeCreate'] = @optional['cascadeCreate'] if @optional.include? 'cascadeCreate'
|
59
|
+
p['recommId'] = @optional['recommId'] if @optional.include? 'recommId'
|
60
|
+
p['additionalData'] = @optional['additionalData'] if @optional.include? 'additionalData'
|
55
61
|
p
|
56
62
|
end
|
57
63
|
|
@@ -20,6 +20,22 @@ module RecombeeApiClient
|
|
20
20
|
#
|
21
21
|
# - +type+ -> Value type of the item property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`, `image` or `imageList`.
|
22
22
|
#
|
23
|
+
#* `int`- Signed integer number.
|
24
|
+
#
|
25
|
+
#* `double` - Floating point number. It uses 64-bit base-2 format (IEEE 754 standard).
|
26
|
+
#
|
27
|
+
#* `string` - UTF-8 string.
|
28
|
+
#
|
29
|
+
#* `boolean` - *true* / *false*
|
30
|
+
#
|
31
|
+
#* `timestamp` - Value representing date and time.
|
32
|
+
#
|
33
|
+
#* `set` - Set of strings.
|
34
|
+
#
|
35
|
+
#* `image` - URL of an image (`jpeg`, `png` or `gif`).
|
36
|
+
#
|
37
|
+
#* `imageList` - List of URLs that refer to images.
|
38
|
+
#
|
23
39
|
#
|
24
40
|
def initialize(property_name, type)
|
25
41
|
@property_name = property_name
|
@@ -10,7 +10,7 @@ module RecombeeApiClient
|
|
10
10
|
#Adds a purchase of a given item made by a given user.
|
11
11
|
#
|
12
12
|
class AddPurchase < ApiRequest
|
13
|
-
attr_reader :user_id, :item_id, :timestamp, :cascade_create, :amount, :price, :profit
|
13
|
+
attr_reader :user_id, :item_id, :timestamp, :cascade_create, :amount, :price, :profit, :recomm_id, :additional_data
|
14
14
|
attr_accessor :timeout
|
15
15
|
attr_accessor :ensure_https
|
16
16
|
|
@@ -25,6 +25,8 @@ module RecombeeApiClient
|
|
25
25
|
# - +amount+ -> Amount (number) of purchased items. The default is 1. For example if `user-x` purchases two `item-y` during a single order (session...), the `amount` should equal to 2.
|
26
26
|
# - +price+ -> Price paid by the user for the item. If `amount` is greater than 1, sum of prices of all the items should be given.
|
27
27
|
# - +profit+ -> Your profit from the purchased item. The profit is natural in e-commerce domain (for example if `user-x` purchases `item-y` for $100 and the gross margin is 30 %, then the profit is $30), but is applicable also in other domains (for example at a news company it may be income from displayed advertisement on article page). If `amount` is greater than 1, sum of profit of all the items should be given.
|
28
|
+
# - +recommId+ -> If this purchase is based on a recommendation request, `recommId` is the id of the clicked recommendation.
|
29
|
+
# - +additionalData+ -> A dictionary of additional data for the interaction.
|
28
30
|
#
|
29
31
|
def initialize(user_id, item_id, optional = {})
|
30
32
|
@user_id = user_id
|
@@ -35,11 +37,13 @@ module RecombeeApiClient
|
|
35
37
|
@amount = optional['amount']
|
36
38
|
@price = optional['price']
|
37
39
|
@profit = optional['profit']
|
40
|
+
@recomm_id = optional['recommId']
|
41
|
+
@additional_data = optional['additionalData']
|
38
42
|
@optional = optional
|
39
43
|
@timeout = 1000
|
40
44
|
@ensure_https = false
|
41
45
|
@optional.each do |par, _|
|
42
|
-
fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","amount","price","profit"].include? par
|
46
|
+
fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","amount","price","profit","recommId","additionalData"].include? par
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
@@ -58,6 +62,8 @@ module RecombeeApiClient
|
|
58
62
|
p['amount'] = @optional['amount'] if @optional.include? 'amount'
|
59
63
|
p['price'] = @optional['price'] if @optional.include? 'price'
|
60
64
|
p['profit'] = @optional['profit'] if @optional.include? 'profit'
|
65
|
+
p['recommId'] = @optional['recommId'] if @optional.include? 'recommId'
|
66
|
+
p['additionalData'] = @optional['additionalData'] if @optional.include? 'additionalData'
|
61
67
|
p
|
62
68
|
end
|
63
69
|
|
@@ -10,7 +10,7 @@ module RecombeeApiClient
|
|
10
10
|
#Adds a rating of given item made by a given user.
|
11
11
|
#
|
12
12
|
class AddRating < ApiRequest
|
13
|
-
attr_reader :user_id, :item_id, :timestamp, :rating, :cascade_create
|
13
|
+
attr_reader :user_id, :item_id, :timestamp, :rating, :cascade_create, :recomm_id, :additional_data
|
14
14
|
attr_accessor :timeout
|
15
15
|
attr_accessor :ensure_https
|
16
16
|
|
@@ -23,6 +23,8 @@ module RecombeeApiClient
|
|
23
23
|
# * *Optional arguments (given as hash optional)*
|
24
24
|
# - +timestamp+ -> UTC timestamp of the rating as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
|
25
25
|
# - +cascadeCreate+ -> Sets whether the given user/item should be created if not present in the database.
|
26
|
+
# - +recommId+ -> If this rating is based on a recommendation request, `recommId` is the id of the clicked recommendation.
|
27
|
+
# - +additionalData+ -> A dictionary of additional data for the interaction.
|
26
28
|
#
|
27
29
|
def initialize(user_id, item_id, rating, optional = {})
|
28
30
|
@user_id = user_id
|
@@ -31,11 +33,13 @@ module RecombeeApiClient
|
|
31
33
|
optional = normalize_optional(optional)
|
32
34
|
@timestamp = optional['timestamp']
|
33
35
|
@cascade_create = optional['cascadeCreate']
|
36
|
+
@recomm_id = optional['recommId']
|
37
|
+
@additional_data = optional['additionalData']
|
34
38
|
@optional = optional
|
35
39
|
@timeout = 1000
|
36
40
|
@ensure_https = false
|
37
41
|
@optional.each do |par, _|
|
38
|
-
fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate"].include? par
|
42
|
+
fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","recommId","additionalData"].include? par
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
@@ -52,6 +56,8 @@ module RecombeeApiClient
|
|
52
56
|
p['rating'] = @rating
|
53
57
|
p['timestamp'] = @optional['timestamp'] if @optional.include? 'timestamp'
|
54
58
|
p['cascadeCreate'] = @optional['cascadeCreate'] if @optional.include? 'cascadeCreate'
|
59
|
+
p['recommId'] = @optional['recommId'] if @optional.include? 'recommId'
|
60
|
+
p['additionalData'] = @optional['additionalData'] if @optional.include? 'additionalData'
|
55
61
|
p
|
56
62
|
end
|
57
63
|
|
@@ -18,7 +18,19 @@ module RecombeeApiClient
|
|
18
18
|
# * *Required arguments*
|
19
19
|
# - +property_name+ -> Name of the user property to be created. Currently, the following names are reserved:`id`, `userid`, case insensitively. Also, the length of the property name must not exceed 63 characters.
|
20
20
|
#
|
21
|
-
# - +type+ -> Value type of the user property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set
|
21
|
+
# - +type+ -> Value type of the user property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`.
|
22
|
+
#
|
23
|
+
#* `int` - Signed integer number.
|
24
|
+
#
|
25
|
+
#* `double` - Floating point number. It uses 64-bit base-2 format (IEEE 754 standard).
|
26
|
+
#
|
27
|
+
#* `string` - UTF-8 string.
|
28
|
+
#
|
29
|
+
#* `boolean` - *true* / *false*
|
30
|
+
#
|
31
|
+
#* `timestamp` - Value representing date and time.
|
32
|
+
#
|
33
|
+
#* `set` - Set of strings.
|
22
34
|
#
|
23
35
|
#
|
24
36
|
def initialize(property_name, type)
|
@@ -10,7 +10,7 @@ module RecombeeApiClient
|
|
10
10
|
#Merges interactions (purchases, ratings, bookmarks, detail views ...) of two different users under a single user ID. This is especially useful for online e-commerce applications working with anonymous users identified by unique tokens such as the session ID. In such applications, it may often happen that a user owns a persistent account, yet accesses the system anonymously while, e.g., putting items into a shopping cart. At some point in time, such as when the user wishes to confirm the purchase, (s)he logs into the system using his/her username and password. The interactions made under anonymous session ID then become connected with the persistent account, and merging these two together becomes desirable.
|
11
11
|
#
|
12
12
|
#
|
13
|
-
#Merging happens between two users referred to as the *target* and the *source*. After the merge, all the interactions of the source user are attributed to the target user, and the source user is **deleted
|
13
|
+
#Merging happens between two users referred to as the *target* and the *source*. After the merge, all the interactions of the source user are attributed to the target user, and the source user is **deleted**.
|
14
14
|
#
|
15
15
|
class MergeUsers < ApiRequest
|
16
16
|
attr_reader :target_user_id, :source_user_id, :cascade_create
|
@@ -9,10 +9,17 @@ module RecombeeApiClient
|
|
9
9
|
##
|
10
10
|
#Recommends set of items that are somehow related to one given item, *X*. Typical scenario is when user *A* is viewing *X*. Then you may display items to the user that he might be also interested in. Recommend items to item request gives you Top-N such items, optionally taking the target user *A* into account.
|
11
11
|
#
|
12
|
+
#The returned items are sorted by relevance (first item being the most relevant).
|
13
|
+
#
|
14
|
+
#Besides the recommended items, also a unique `recommId` is returned in the response. It can be used to:
|
15
|
+
#
|
16
|
+
#- Let Recombee know that this recommendation was successful (e.g. user clicked one of the recommended items). See [Reported metrics](https://docs.recombee.com/admin_ui.html#reported-metrics).
|
17
|
+
#- Get subsequent recommended items when the user scrolls down (*infinite scroll*) or goes to the next page. See [Recommend Next Items](https://docs.recombee.com/api.html#recommend-next-items).
|
18
|
+
#
|
12
19
|
#It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
|
13
20
|
#
|
14
21
|
class RecommendItemsToItem < ApiRequest
|
15
|
-
attr_reader :item_id, :target_user_id, :count, :
|
22
|
+
attr_reader :item_id, :target_user_id, :count, :scenario, :cascade_create, :return_properties, :included_properties, :filter, :booster, :logic, :user_impact, :diversity, :min_relevance, :rotation_rate, :rotation_time, :expert_settings, :return_ab_group
|
16
23
|
attr_accessor :timeout
|
17
24
|
attr_accessor :ensure_https
|
18
25
|
|
@@ -40,12 +47,13 @@ module RecombeeApiClient
|
|
40
47
|
# - +count+ -> Number of items to be recommended (N for the top-N recommendation).
|
41
48
|
#
|
42
49
|
# * *Optional arguments (given as hash optional)*
|
43
|
-
# - +
|
50
|
+
# - +scenario+ -> Scenario defines a particular application of recommendations. It can be for example "homepage", "cart" or "emailing".
|
51
|
+
#
|
52
|
+
#You can set various settings to the [scenario](https://docs.recombee.com/scenarios.html) in the [Admin UI](https://admin.recombee.com). You can also see performance of each scenario in the Admin UI separately, so you can check how well each application performs.
|
53
|
+
#
|
54
|
+
#The AI which optimizes models in order to get the best results may optimize different scenarios separately, or even use different models in each of the scenarios.
|
44
55
|
#
|
45
|
-
# - +filter+ -> Boolean-returning [ReQL](https://docs.recombee.com/reql.html) expression which allows you to filter recommended items based on the values of their attributes.
|
46
|
-
# - +booster+ -> Number-returning [ReQL](https://docs.recombee.com/reql.html) expression which allows you to boost recommendation rate of some items based on the values of their attributes.
|
47
56
|
# - +cascadeCreate+ -> If item of given *itemId* or user of given *targetUserId* doesn't exist in the database, it creates the missing entity/entities and returns some (non-personalized) recommendations. This allows for example rotations in the following recommendations for the user of given *targetUserId*, as the user will be already known to the system.
|
48
|
-
# - +scenario+ -> Scenario defines a particular application of recommendations. It can be for example "homepage", "cart" or "emailing". You can see each scenario in the UI separately, so you can check how well each application performs. The AI which optimizes models in order to get the best results may optimize different scenarios separately, or even use different models in each of the scenarios.
|
49
57
|
# - +returnProperties+ -> With `returnProperties=true`, property values of the recommended items are returned along with their IDs in a JSON dictionary. The acquired property values can be used for easy displaying of the recommended items to the user.
|
50
58
|
#
|
51
59
|
#Example response:
|
@@ -72,7 +80,8 @@ module RecombeeApiClient
|
|
72
80
|
# "url": "myshop.com/mixer-42"
|
73
81
|
# }
|
74
82
|
# }
|
75
|
-
# ]
|
83
|
+
# ],
|
84
|
+
# "numberNextRecommsCalls": 0
|
76
85
|
# }
|
77
86
|
#```
|
78
87
|
#
|
@@ -98,13 +107,31 @@ module RecombeeApiClient
|
|
98
107
|
# "price": 39
|
99
108
|
# }
|
100
109
|
# }
|
101
|
-
# ]
|
110
|
+
# ],
|
111
|
+
# "numberNextRecommsCalls": 0
|
102
112
|
# }
|
103
113
|
#```
|
104
114
|
#
|
115
|
+
# - +filter+ -> Boolean-returning [ReQL](https://docs.recombee.com/reql.html) expression which allows you to filter recommended items based on the values of their attributes.
|
116
|
+
#
|
117
|
+
#Filters can be also assigned to a [scenario](https://docs.recombee.com/scenarios.html) in the [Admin UI](https://admin.recombee.com).
|
118
|
+
#
|
119
|
+
# - +booster+ -> Number-returning [ReQL](https://docs.recombee.com/reql.html) expression which allows you to boost recommendation rate of some items based on the values of their attributes.
|
120
|
+
#
|
121
|
+
#Boosters can be also assigned to a [scenario](https://docs.recombee.com/scenarios.html) in the [Admin UI](https://admin.recombee.com).
|
122
|
+
#
|
123
|
+
# - +logic+ -> Logic specifies particular behavior of the recommendation models. You can pick tailored logic for your domain and use case.
|
124
|
+
#See [this section](https://docs.recombee.com/recommendation_logics.html) for list of available logics and other details.
|
125
|
+
#
|
126
|
+
#The difference between `logic` and `scenario` is that `logic` specifies mainly behavior, while `scenario` specifies the place where recommendations are shown to the users.
|
127
|
+
#
|
128
|
+
#Logic can be also set to a [scenario](https://docs.recombee.com/scenarios.html) in the [Admin UI](https://admin.recombee.com).
|
129
|
+
#
|
130
|
+
# - +userImpact+ -> **Expert option** If *targetUserId* parameter is present, the recommendations are biased towards the given user. Using *userImpact*, you may control this bias. For an extreme case of `userImpact=0.0`, the interactions made by the user are not taken into account at all (with the exception of history-based blacklisting), for `userImpact=1.0`, you'll get user-based recommendation. The default value is `0`.
|
131
|
+
#
|
105
132
|
# - +diversity+ -> **Expert option** Real number from [0.0, 1.0] which determines how much mutually dissimilar should the recommended items be. The default value is 0.0, i.e., no diversification. Value 1.0 means maximal diversification.
|
106
133
|
#
|
107
|
-
# - +minRelevance+ -> **Expert option** If the *targetUserId* is provided: Specifies the threshold of how much relevant must the recommended items be to the user. Possible values one of: "low", "medium", "high". The default value is "low", meaning that the system attempts to recommend number of items equal to *count* at any cost. If there are not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations to be appended to reach the full *count*. This behavior may be suppressed by using "medium" or "high" values. In such case, the system only recommends items of at least the requested
|
134
|
+
# - +minRelevance+ -> **Expert option** If the *targetUserId* is provided: Specifies the threshold of how much relevant must the recommended items be to the user. Possible values one of: "low", "medium", "high". The default value is "low", meaning that the system attempts to recommend number of items equal to *count* at any cost. If there are not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations to be appended to reach the full *count*. This behavior may be suppressed by using "medium" or "high" values. In such case, the system only recommends items of at least the requested relevance, and may return less than *count* items when there is not enough data to fulfill it.
|
108
135
|
#
|
109
136
|
# - +rotationRate+ -> **Expert option** If the *targetUserId* is provided: If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items.
|
110
137
|
#
|
@@ -112,29 +139,33 @@ module RecombeeApiClient
|
|
112
139
|
#
|
113
140
|
# - +expertSettings+ -> Dictionary of custom options.
|
114
141
|
#
|
142
|
+
# - +returnAbGroup+ -> If there is a custom AB-testing running, return name of group to which the request belongs.
|
143
|
+
#
|
115
144
|
#
|
116
145
|
def initialize(item_id, target_user_id, count, optional = {})
|
117
146
|
@item_id = item_id
|
118
147
|
@target_user_id = target_user_id
|
119
148
|
@count = count
|
120
149
|
optional = normalize_optional(optional)
|
121
|
-
@user_impact = optional['userImpact']
|
122
|
-
@filter = optional['filter']
|
123
|
-
@booster = optional['booster']
|
124
|
-
@cascade_create = optional['cascadeCreate']
|
125
150
|
@scenario = optional['scenario']
|
151
|
+
@cascade_create = optional['cascadeCreate']
|
126
152
|
@return_properties = optional['returnProperties']
|
127
153
|
@included_properties = optional['includedProperties']
|
154
|
+
@filter = optional['filter']
|
155
|
+
@booster = optional['booster']
|
156
|
+
@logic = optional['logic']
|
157
|
+
@user_impact = optional['userImpact']
|
128
158
|
@diversity = optional['diversity']
|
129
159
|
@min_relevance = optional['minRelevance']
|
130
160
|
@rotation_rate = optional['rotationRate']
|
131
161
|
@rotation_time = optional['rotationTime']
|
132
162
|
@expert_settings = optional['expertSettings']
|
163
|
+
@return_ab_group = optional['returnAbGroup']
|
133
164
|
@optional = optional
|
134
165
|
@timeout = 3000
|
135
166
|
@ensure_https = false
|
136
167
|
@optional.each do |par, _|
|
137
|
-
fail UnknownOptionalParameter.new(par) unless ["
|
168
|
+
fail UnknownOptionalParameter.new(par) unless ["scenario","cascadeCreate","returnProperties","includedProperties","filter","booster","logic","userImpact","diversity","minRelevance","rotationRate","rotationTime","expertSettings","returnAbGroup"].include? par
|
138
169
|
end
|
139
170
|
end
|
140
171
|
|
@@ -148,18 +179,20 @@ module RecombeeApiClient
|
|
148
179
|
p = Hash.new
|
149
180
|
p['targetUserId'] = @target_user_id
|
150
181
|
p['count'] = @count
|
151
|
-
p['userImpact'] = @optional['userImpact'] if @optional.include? 'userImpact'
|
152
|
-
p['filter'] = @optional['filter'] if @optional.include? 'filter'
|
153
|
-
p['booster'] = @optional['booster'] if @optional.include? 'booster'
|
154
|
-
p['cascadeCreate'] = @optional['cascadeCreate'] if @optional.include? 'cascadeCreate'
|
155
182
|
p['scenario'] = @optional['scenario'] if @optional.include? 'scenario'
|
183
|
+
p['cascadeCreate'] = @optional['cascadeCreate'] if @optional.include? 'cascadeCreate'
|
156
184
|
p['returnProperties'] = @optional['returnProperties'] if @optional.include? 'returnProperties'
|
157
185
|
p['includedProperties'] = @optional['includedProperties'] if @optional.include? 'includedProperties'
|
186
|
+
p['filter'] = @optional['filter'] if @optional.include? 'filter'
|
187
|
+
p['booster'] = @optional['booster'] if @optional.include? 'booster'
|
188
|
+
p['logic'] = @optional['logic'] if @optional.include? 'logic'
|
189
|
+
p['userImpact'] = @optional['userImpact'] if @optional.include? 'userImpact'
|
158
190
|
p['diversity'] = @optional['diversity'] if @optional.include? 'diversity'
|
159
191
|
p['minRelevance'] = @optional['minRelevance'] if @optional.include? 'minRelevance'
|
160
192
|
p['rotationRate'] = @optional['rotationRate'] if @optional.include? 'rotationRate'
|
161
193
|
p['rotationTime'] = @optional['rotationTime'] if @optional.include? 'rotationTime'
|
162
194
|
p['expertSettings'] = @optional['expertSettings'] if @optional.include? 'expertSettings'
|
195
|
+
p['returnAbGroup'] = @optional['returnAbGroup'] if @optional.include? 'returnAbGroup'
|
163
196
|
p
|
164
197
|
end
|
165
198
|
|