Skip to content

Commit 896aada

Browse files
committed
Use new recommendation endpoints
1 parent b73bd70 commit 896aada

12 files changed

+35
-41
lines changed

README.rst

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ Basic example
3232
3333
from recombee_api_client.api_client import RecombeeClient
3434
from recombee_api_client.exceptions import APIException
35-
from recombee_api_client.api_requests import AddPurchase, UserBasedRecommendation, Batch
35+
from recombee_api_client.api_requests import AddPurchase, RecommendItemsToUser, Batch
3636
import random
3737
38-
client = RecombeeClient('client-test', 'jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L')
38+
client = RecombeeClient('--my-database-id--', '--my-secret-token--'')
3939
4040
#Generate some random purchases of items by users
4141
PROBABILITY_PURCHASED = 0.1
@@ -55,29 +55,29 @@ Basic example
5555
client.send(Batch(purchase_requests))
5656
5757
# Get recommendations for user 'user-25'
58-
recommended = client.send(UserBasedRecommendation('user-25', 5))
58+
recommended = client.send(RecommendItemsToUser('user-25', 5))
5959
print("Recommended items: %s" % recommended)
6060
6161
except APIException as e:
6262
print(e)
6363
6464
65+
6566
---------------------
6667
Using property values
6768
---------------------
6869
6970
.. code-block:: python
7071
71-
7272
from recombee_api_client.api_client import RecombeeClient
7373
from recombee_api_client.api_requests import AddItemProperty, SetItemValues, AddPurchase
74-
from recombee_api_client.api_requests import ItemBasedRecommendation, Batch, ResetDatabase
74+
from recombee_api_client.api_requests import RecommendItemsToItem, Batch, ResetDatabase
7575
import random
7676
7777
NUM = 100
7878
PROBABILITY_PURCHASED = 0.1
7979
80-
client = RecombeeClient('client-test', 'jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L')
80+
client = RecombeeClient('--my-database-id--', '--my-secret-token--'')
8181
8282
#Clear the entire database
8383
client.send(ResetDatabase())
@@ -124,23 +124,21 @@ Using property values
124124
client.send(Batch(requests))
125125
126126
# Get 5 recommendations for user-42, who is currently viewing computer-6
127-
recommended = client.send(ItemBasedRecommendation('computer-6', 5, target_user_id='user-42'))
127+
recommended = client.send(RecommendItemsToItem('computer-6', 'user-42', 5))
128128
print("Recommended items: %s" % recommended)
129129
130-
# Get 5 recommendations for user-42, but recommend only computers that
131-
# have at least 3 cores
130+
# Recommend only computers that have at least 3 cores
132131
recommended = client.send(
133-
ItemBasedRecommendation('computer-6', 5, target_user_id='user-42', filter="'num-cores'>=3")
132+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'num-cores'>=3")
134133
)
135134
print("Recommended items with at least 3 processor cores: %s" % recommended)
136135
137-
# Get 5 recommendations for user-42, but recommend only items that
138-
# are more expensive then currently viewed item (up-sell)
136+
# Recommend only items that are more expensive then currently viewed item (up-sell)
139137
recommended = client.send(
140-
ItemBasedRecommendation('computer-6', 5, target_user_id='user-42', filter="'price' > context_item[\"price\"]")
138+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'price' > context_item[\"price\"]")
141139
)
142140
print("Recommended up-sell items: %s" % recommended)
143-
141+
144142
------------------
145143
Exception handling
146144
------------------
@@ -155,11 +153,11 @@ Example:
155153
156154
try:
157155
recommended = client.send(
158-
ItemBasedRecommendation('computer-6', 5,target_user_id='user-42', filter="'price' > context_item[\"price\"]")
156+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'price' > context_item[\"price\"]")
159157
)
160158
except ResponseException as e:
161159
#Handle errorneous request => use fallback
162160
except ApiTimeoutException as e:
163161
#Handle timeout => use fallback
164162
except APIException as e:
165-
#APIException is parent of both ResponseException and ApiTimeoutException
163+
#APIException is parent of both ResponseException and ApiTimeoutException

recombee_api_client/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def send(self, request):
6363

6464
@staticmethod
6565
def __get_http_headers(additional_headers=None):
66-
headers = {'User-Agent': 'recombee-python-api-client/1.6.0'}
66+
headers = {'User-Agent': 'recombee-python-api-client/2.0.0'}
6767
if additional_headers:
6868
headers.update(additional_headers)
6969
return headers

recombee_api_client/api_requests/item_based_recommendation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
class ItemBasedRecommendation(Request):
77
"""
8+
Deprecated since version 2.0.0. Use RecommendItemsToItem request instead.
9+
810
Recommends set of items that are somehow related to one given item, *X*. Typical scenario for using item-based recommendation is when user *A* is viewing *X*. Then you may display items to the user that he might be also interested in. Item-recommendation request gives you Top-N such items, optionally taking the target user *A* into account.
911
1012
It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.

recombee_api_client/api_requests/recommend_items_to_item.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
class RecommendItemsToItem(Request):
77
"""
8-
This feature is currently in beta.
9-
108
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.
119
1210
It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
@@ -41,9 +39,9 @@ def __init__(self, item_id, target_user_id, count, user_impact=DEFAULT, filter=D
4139
4240
Do not create some special dummy user for getting recommendations,
4341
44-
as it could cause mislead the recommendation models,
42+
as it could mislead the recommendation models,
4543
46-
leading to wrong recommendations.
44+
and result in wrong recommendations.
4745
4846
4947
For anonymous/unregistered users it is possible to use for example their session ID.
@@ -73,7 +71,7 @@ def __init__(self, item_id, target_user_id, count, user_impact=DEFAULT, filter=D
7371
7472
E{lb}
7573
76-
"recommId": "8ac80708afe9148130528757ebf6aaba",
74+
"recommId": "0c6189e7-dc1a-429a-b613-192696309361",
7775
7876
"recomms":
7977
@@ -126,7 +124,7 @@ def __init__(self, item_id, target_user_id, count, user_impact=DEFAULT, filter=D
126124
127125
E{lb}
128126
129-
"recommId": "c7dbfc503d262b80b77b4949ee9855fb",
127+
"recommId": "6842c725-a79f-4537-a02c-f34d668a3f80",
130128
131129
"recomms":
132130

recombee_api_client/api_requests/recommend_items_to_user.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
class RecommendItemsToUser(Request):
77
"""
8-
This feature is currently in beta.
9-
108
Based on user's past interactions (purchases, ratings, etc.) with the items, recommends top-N items that are most likely to be of high value for a given user.
119
1210
It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
@@ -39,7 +37,7 @@ def __init__(self, user_id, count, filter=DEFAULT, booster=DEFAULT, cascade_crea
3937
4038
E{lb}
4139
42-
"recommId": "1644e7b31759a08480da5f3b0a13045b",
40+
"recommId": "ce52ada4-e4d9-4885-943c-407db2dee837",
4341
4442
"recomms":
4543
@@ -92,7 +90,7 @@ def __init__(self, user_id, count, filter=DEFAULT, booster=DEFAULT, cascade_crea
9290
9391
E{lb}
9492
95-
"recommId": "e3ba43af1a4e59dd08a00adced1729a7",
93+
"recommId": "a86ee8d5-cd8e-46d1-886c-8b3771d0520b",
9694
9795
"recomms":
9896

recombee_api_client/api_requests/recommend_users_to_item.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
class RecommendUsersToItem(Request):
77
"""
8-
This feature is currently in beta.
9-
108
Recommend users that are likely to be interested in a given item.
119
1210
It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
@@ -39,7 +37,7 @@ def __init__(self, item_id, count, filter=DEFAULT, booster=DEFAULT, cascade_crea
3937
4038
E{lb}
4139
42-
"recommId": "9eeebc318508302529e3241f4570834d",
40+
"recommId": "039b71dc-b9cc-4645-a84f-62b841eecfce",
4341
4442
"recomms":
4543
@@ -84,7 +82,7 @@ def __init__(self, item_id, count, filter=DEFAULT, booster=DEFAULT, cascade_crea
8482
8583
E{lb}
8684
87-
"recommId": "d4c826635efc3e01a83470008c5697f1",
85+
"recommId": "b2b355dd-972a-4728-9c6b-2dc229db0678",
8886
8987
"recomms":
9088
@@ -133,7 +131,7 @@ def __init__(self, item_id, count, filter=DEFAULT, booster=DEFAULT, cascade_crea
133131
self.included_properties = included_properties
134132
self.diversity = diversity
135133
self.expert_settings = expert_settings
136-
self.timeout = 3000
134+
self.timeout = 50000
137135
self.ensure_https = False
138136
self.method = 'post'
139137
self.path = "/recomms/items/%s/users/" % (self.item_id)

recombee_api_client/api_requests/recommend_users_to_user.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
class RecommendUsersToUser(Request):
77
"""
8-
This feature is currently in beta.
9-
108
Get similar users as some given user, based on the user's past interactions (purchases, ratings, etc.) and values of properties.
119
1210
It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
@@ -39,7 +37,7 @@ def __init__(self, user_id, count, filter=DEFAULT, booster=DEFAULT, cascade_crea
3937
4038
E{lb}
4139
42-
"recommId": "32fc671480eb29d843e47def43503992",
40+
"recommId": "9cb9c55d-50ba-4478-84fd-ab456136156e",
4341
4442
"recomms":
4543
@@ -84,7 +82,7 @@ def __init__(self, user_id, count, filter=DEFAULT, booster=DEFAULT, cascade_crea
8482
8583
E{lb}
8684
87-
"recommId": "27d81ade643621f45cc6ba5d30d7d683",
85+
"recommId": "b326d82d-5d57-4b45-b362-c9d6f0895855",
8886
8987
"recomms":
9088
@@ -145,7 +143,7 @@ def __init__(self, user_id, count, filter=DEFAULT, booster=DEFAULT, cascade_crea
145143
self.rotation_rate = rotation_rate
146144
self.rotation_time = rotation_time
147145
self.expert_settings = expert_settings
148-
self.timeout = 3000
146+
self.timeout = 50000
149147
self.ensure_https = False
150148
self.method = 'post'
151149
self.path = "/recomms/users/%s/users/" % (self.user_id)

recombee_api_client/api_requests/user_based_recommendation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
class UserBasedRecommendation(Request):
77
"""
8+
Deprecated since version 2.0.0. Use RecommendItemsToUser request instead.
9+
810
Based on user's past interactions (purchases, ratings, etc.) with the items, recommends top-N items that are most likely to be of high value for a given user.
911
1012
It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
setup(
1212
name='recombee-api-client',
1313

14-
version='1.6.0',
14+
version='2.0.0',
1515

1616
description='Client for Recombee recommendation API',
1717
long_description=long_description,

tests/test_cases/add_entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_add_entity(self):
1919
req = self.create_request('valid_id')
2020
resp = self.client.send(req)
2121
# it 'fails with invalid entity id'
22-
req = self.create_request('...not_valid...')
22+
req = self.create_request('$$$not_valid$$$')
2323
try:
2424
self.client.send(req)
2525
self.assertFail()

0 commit comments

Comments
 (0)