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RESULTS. Every number below traces to a named file + run stamp; nothing is borrowed from other projects.
|
| 6 |
+
|
| 7 |
+
**Upstream:** PYTHON_API_CLIENT_PRIOR_DOCS · **Upstream pin:** `70a068d52cd329bdbb478ffa5020bdfd2f0a3a83` · **Category:** ONLINE_RETAIL · **Vendor:** Anticloud FZ LLE · **Licence:** MIT
|
| 8 |
+
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
## What This Project Does
|
| 12 |
+
|
| 13 |
+
*****************
|
| 14 |
+
RecombeeApiClient
|
| 15 |
+
*****************
|
| 16 |
+
|
| 17 |
+
A Python 3 client for easy use of the `Recombee <https://www.recombee.com/>`_ recommendation API.
|
| 18 |
+
|
| 19 |
+
If you don't have an account at Recombee yet, you can create a free account `here <https://www.recombee.com/>`_.
|
| 20 |
+
|
| 21 |
+
Documentation of the API can be found at `docs.recombee.com <https://docs.recombee.com/>`_.
|
| 22 |
+
|
| 23 |
+
=============
|
| 24 |
+
Installation
|
| 25 |
+
=============
|
| 26 |
+
|
| 27 |
+
Install the client with pip:
|
| 28 |
+
|
| 29 |
+
.. code-block:: bash
|
| 30 |
+
|
| 31 |
+
$ pip install recombee-api-client
|
| 32 |
+
|
| 33 |
+
========
|
| 34 |
+
Examples
|
| 35 |
+
========
|
| 36 |
+
|
| 37 |
+
-------------
|
| 38 |
+
Basic example
|
| 39 |
+
-------------
|
| 40 |
+
|
| 41 |
+
.. code-block:: python
|
| 42 |
+
|
| 43 |
+
from recombee_api_client.api_client import RecombeeClient, Region
|
| 44 |
+
from recombee_api_client.exceptions import APIException
|
| 45 |
+
from recombee_api_client.api_requests import *
|
| 46 |
+
import random
|
| 47 |
+
|
| 48 |
+
client = RecombeeClient('--my-database-id--', '--db-private-token--', region=Region.US_WEST)
|
| 49 |
+
|
| 50 |
+
#Generate some random purchases of items by users
|
| 51 |
+
PROBABILITY_PURCHASED = 0.1
|
| 52 |
+
NUM = 100
|
| 53 |
+
purchase_requests = []
|
| 54 |
+
|
| 55 |
+
for user_id in ["user-%s" % i for i in range(NUM) ]:
|
| 56 |
+
for item_id in ["item-%s" % i for i in range(NUM) ]:
|
| 57 |
+
if random.random() < PROBABILITY_PURCHASED:
|
| 58 |
+
|
| 59 |
+
request = AddPurchase(user_id, item_id, cascade_create=True)
|
| 60 |
+
purchase_requests.append(request)
|
| 61 |
+
|
| 62 |
+
try:
|
| 63 |
+
# Send the data to Recombee, use Batch for faster processing of larger data
|
| 64 |
+
print('Send purchases')
|
| 65 |
+
client.send(Batch(purchase_requests))
|
| 66 |
+
|
| 67 |
+
# Get recommendations for user 'user-25'
|
| 68 |
+
response = client.send(RecommendItemsToUser('user-25', 5))
|
| 69 |
+
print("Recommended items: %s" % response)
|
| 70 |
+
|
| 71 |
+
# User scrolled down - get next 3 recommended items
|
| 72 |
+
response = client.send(RecommendNextItems(response['recommId'], 3))
|
| 73 |
+
print("Next recommended items: %s" % response)
|
| 74 |
+
|
| 75 |
+
except APIException as e:
|
| 76 |
+
print(e)
|
| 77 |
+
|
| 78 |
+
---------------------
|
| 79 |
+
Using property values
|
| 80 |
+
---------------------
|
| 81 |
+
|
| 82 |
+
.. code-block:: python
|
| 83 |
+
|
| 84 |
+
from recombee_api_client.api_client import RecombeeClient, Region
|
| 85 |
+
from recombee_api_client.api_requests import AddItemProperty, SetItemValues, AddPurchase
|
| 86 |
+
from recombee_api_client.api_requests import RecommendItemsToItem, SearchItems, Batch, ResetDatabase
|
| 87 |
+
import random
|
| 88 |
+
|
| 89 |
+
NUM = 100
|
| 90 |
+
PROBABILITY_PURCHASED = 0.1
|
| 91 |
+
|
| 92 |
+
client = RecombeeClient('--my-database-id--', '--db-private-token--', region=Region.AP_SE)
|
| 93 |
+
|
| 94 |
+
# Clear the entire database
|
| 95 |
+
client.send(ResetDatabase())
|
| 96 |
+
|
| 97 |
+
# We will use computers as items in this example
|
| 98 |
+
# Computers have four properties
|
| 99 |
+
# - price (floating point number)
|
| 100 |
+
# - number of processor cores (integer number)
|
| 101 |
+
# - description (string)
|
| 102 |
+
# - image (url of computer's photo)
|
| 103 |
+
|
| 104 |
+
# Add properties of items
|
| 105 |
+
client.send(AddItemProperty('price', 'double'))
|
| 106 |
+
client.send(AddItemProperty('num-cores', 'int'))
|
| 107 |
+
client.send(AddItemProperty('description', 'string'))
|
| 108 |
+
client.send(AddItemProperty('image', 'image'))
|
| 109 |
+
|
| 110 |
+
# Prepare requests for setting a catalog of computers
|
| 111 |
+
requests = [SetItemValues(
|
| 112 |
+
"computer-%s" % i, #itemId
|
| 113 |
+
#values:
|
| 114 |
+
{
|
| 115 |
+
'price': random.uniform(500, 2000),
|
| 116 |
+
'num-cores': random.randrange(1,9),
|
| 117 |
+
'description': 'Great computer',
|
| 118 |
+
'image': 'http://examplesite.com/products/computer-%s.jpg' % i
|
| 119 |
+
},
|
| 120 |
+
cascade_create=True # Use cascadeCreate for creating item
|
| 121 |
+
# with given itemId if it doesn't exist
|
| 122 |
+
) for i in range(NUM)]
|
| 123 |
+
|
| 124 |
+
# Send catalog to the recommender system
|
| 125 |
+
client.send(Batch(requests))
|
| 126 |
+
|
| 127 |
+
# Prepare some purchases of items by users
|
| 128 |
+
requests = []
|
| 129 |
+
items = ["computer-%s" % i for i in range(NUM)]
|
| 130 |
+
users = ["user-%s" % i for i in range(NUM)]
|
| 131 |
+
|
| 132 |
+
for item_id in items:
|
| 133 |
+
#Use cascadeCreate to create unexisting users
|
| 134 |
+
purchasing_users = [user_id for user_id in users if random.random() < PROBABILITY_PURCHASED]
|
| 135 |
+
requests += [AddPurchase(user_id, item_id, cascade_create=True) for user_id in purchasing_users]
|
| 136 |
+
|
| 137 |
+
# Send purchases to the recommender system
|
| 138 |
+
client.send(Batch(requests))
|
| 139 |
+
|
| 140 |
+
# Get 5 recommendations for user-42, who is currently viewing computer-6
|
| 141 |
+
# Recommend only computers that have at least 3 cores
|
| 142 |
+
recommended = client.send(
|
| 143 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'num-cores'>=3")
|
| 144 |
+
)
|
| 145 |
+
print("Recommended items with at least 3 processor cores: %s" % recommended)
|
| 146 |
+
|
| 147 |
+
# Recommend only items that are more expensive then currently viewed item (up-sell)
|
| 148 |
+
recommended = client.send(
|
| 149 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'price' > context_item[\"price\"]")
|
| 150 |
+
)
|
| 151 |
+
print("Recommended up-sell items: %s" % recommended)
|
| 152 |
+
|
| 153 |
+
# Filters, boosters and other settings can be also set in the Admin UI (admin.recombee.com)
|
| 154 |
+
# when scenario is specified
|
| 155 |
+
recommended = client.send(
|
| 156 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, scenario='product_detail')
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
# Perform personalized full-text search with a user's search query (e.g. 'computers').
|
| 160 |
+
matches = client.send(SearchItems('user-42', 'computers', 5, scenario='search_top'))
|
| 161 |
+
print("Matched items: %s" % matches)
|
| 162 |
+
|
| 163 |
+
------------------
|
| 164 |
+
Exception handling
|
| 165 |
+
------------------
|
| 166 |
+
|
| 167 |
+
For the sake of brevity, the above examples omit exception handling. However, various exceptions can occur while processing request, for example because of adding an already existing item, submitting interaction of nonexistent user or because of timeout.
|
| 168 |
+
|
| 169 |
+
We are doing our best to provide the fastest and most reliable service, but production-level applications must implement a fallback solution since errors can always happen. The fallback might be, for example, showing the most popular items from the current category, or not displaying recommendations at all.
|
| 170 |
+
|
| 171 |
+
Example:
|
| 172 |
+
|
| 173 |
+
.. code-block:: python
|
| 174 |
+
|
| 175 |
+
from recombee_api_client.exceptions import *
|
| 176 |
+
|
| 177 |
+
try:
|
| 178 |
+
recommended = client.send(
|
| 179 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'price' > context_item[\"price\"]")
|
| 180 |
+
)
|
| 181 |
+
except ResponseException as e:
|
| 182 |
+
#Handle errorneous request => use fallback
|
| 183 |
+
except ApiTimeoutException as e:
|
| 184 |
+
#Handle timeout => use fallback
|
| 185 |
+
except APIException as e:
|
| 186 |
+
#APIException is parent of both ResponseException and ApiTimeoutException
|
| 187 |
+
|
| 188 |
+
---
|
| 189 |
+
|
| 190 |
+
## Installation
|
| 191 |
+
|
| 192 |
+
=============
|
| 193 |
+
|
| 194 |
+
Install the client with pip:
|
| 195 |
+
|
| 196 |
+
.. code-block:: bash
|
| 197 |
+
|
| 198 |
+
$ pip install recombee-api-client
|
| 199 |
+
|
| 200 |
+
========
|
| 201 |
+
Examples
|
| 202 |
+
========
|
| 203 |
+
|
| 204 |
+
-------------
|
| 205 |
+
Basic example
|
| 206 |
+
-------------
|
| 207 |
+
|
| 208 |
+
.. code-block:: python
|
| 209 |
+
|
| 210 |
+
from recombee_api_client.api_client import RecombeeClient, Region
|
| 211 |
+
from recombee_api_client.exceptions import APIException
|
| 212 |
+
from recombee_api_client.api_requests import *
|
| 213 |
+
import random
|
| 214 |
+
|
| 215 |
+
client = RecombeeClient('--my-database-id--', '--db-private-token--', region=Region.US_WEST)
|
| 216 |
+
|
| 217 |
+
#Generate some random purchases of items by users
|
| 218 |
+
PROBABILITY_PURCHASED = 0.1
|
| 219 |
+
NUM = 100
|
| 220 |
+
purchase_requests = []
|
| 221 |
+
|
| 222 |
+
for user_id in ["user-%s" % i for i in range(NUM) ]:
|
| 223 |
+
for item_id in ["item-%s" % i for i in range(NUM) ]:
|
| 224 |
+
if random.random() < PROBABILITY_PURCHASED:
|
| 225 |
+
|
| 226 |
+
request = AddPurchase(user_id, item_id, cascade_create=True)
|
| 227 |
+
purchase_requests.append(request)
|
| 228 |
+
|
| 229 |
+
try:
|
| 230 |
+
# Send the data to Recombee, use Batch for faster processing of larger data
|
| 231 |
+
print('Send purchases')
|
| 232 |
+
client.send(Batch(purchase_requests))
|
| 233 |
+
|
| 234 |
+
# Get recommendations for user 'user-25'
|
| 235 |
+
response = client.send(RecommendItemsToUser('user-25', 5))
|
| 236 |
+
print("Recommended items: %s" % response)
|
| 237 |
+
|
| 238 |
+
# User scrolled down - get next 3 recommended items
|
| 239 |
+
response = client.send(RecommendNextItems(response['recommId'], 3))
|
| 240 |
+
print("Next recommended items: %s" % response)
|
| 241 |
+
|
| 242 |
+
except APIException as e:
|
| 243 |
+
print(e)
|
| 244 |
+
|
| 245 |
+
---------------------
|
| 246 |
+
Using property values
|
| 247 |
+
---------------------
|
| 248 |
+
|
| 249 |
+
.. code-block:: python
|
| 250 |
+
|
| 251 |
+
from recombee_api_client.api_client import RecombeeClient, Region
|
| 252 |
+
from recombee_api_client.api_requests import AddItemProperty, SetItemValues, AddPurchase
|
| 253 |
+
from recombee_api_client.api_requests import RecommendItemsToItem, SearchItems, Batch, ResetDatabase
|
| 254 |
+
import random
|
| 255 |
+
|
| 256 |
+
NUM = 100
|
| 257 |
+
PROBABILITY_PURCHASED = 0.1
|
| 258 |
+
|
| 259 |
+
client = RecombeeClient('--my-database-id--', '--db-private-token--', region=Region.AP_SE)
|
| 260 |
+
|
| 261 |
+
# Clear the entire database
|
| 262 |
+
client.send(ResetDatabase())
|
| 263 |
+
|
| 264 |
+
# We will use computers as items in this example
|
| 265 |
+
# Computers have four properties
|
| 266 |
+
# - price (floating point number)
|
| 267 |
+
# - number of processor cores (integer number)
|
| 268 |
+
# - description (string)
|
| 269 |
+
# - image (url of computer's photo)
|
| 270 |
+
|
| 271 |
+
# Add properties of items
|
| 272 |
+
client.send(AddItemProperty('price', 'double'))
|
| 273 |
+
client.send(AddItemProperty('num-cores', 'int'))
|
| 274 |
+
client.send(AddItemProperty('description', 'string'))
|
| 275 |
+
client.send(AddItemProperty('image', 'image'))
|
| 276 |
+
|
| 277 |
+
# Prepare requests for setting a catalog of computers
|
| 278 |
+
requests = [SetItemValues(
|
| 279 |
+
"computer-%s" % i, #itemId
|
| 280 |
+
#values:
|
| 281 |
+
{
|
| 282 |
+
'price': random.uniform(500, 2000),
|
| 283 |
+
'num-cores': random.randrange(1,9),
|
| 284 |
+
'description': 'Great computer',
|
| 285 |
+
'image': 'http://examplesite.com/products/computer-%s.jpg' % i
|
| 286 |
+
},
|
| 287 |
+
cascade_create=True # Use cascadeCreate for creating item
|
| 288 |
+
# with given itemId if it doesn't exist
|
| 289 |
+
) for i in range(NUM)]
|
| 290 |
+
|
| 291 |
+
# Send catalog to the recommender system
|
| 292 |
+
client.send(Batch(requests))
|
| 293 |
+
|
| 294 |
+
# Prepare some purchases of items by users
|
| 295 |
+
requests = []
|
| 296 |
+
items = ["computer-%s" % i for i in range(NUM)]
|
| 297 |
+
users = ["user-%s" % i for i in range(NUM)]
|
| 298 |
+
|
| 299 |
+
for item_id in items:
|
| 300 |
+
#Use cascadeCreate to create unexisting users
|
| 301 |
+
purchasing_users = [user_id for user_id in users if random.random() < PROBABILITY_PURCHASED]
|
| 302 |
+
requests += [AddPurchase(user_id, item_id, cascade_create=True) for user_id in purchasing_users]
|
| 303 |
+
|
| 304 |
+
# Send purchases to the recommender system
|
| 305 |
+
client.send(Batch(requests))
|
| 306 |
+
|
| 307 |
+
# Get 5 recommendations for user-42, who is currently viewing computer-6
|
| 308 |
+
# Recommend only computers that have at least 3 cores
|
| 309 |
+
recommended = client.send(
|
| 310 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'num-cores'>=3")
|
| 311 |
+
)
|
| 312 |
+
print("Recommended items with at least 3 processor cores: %s" % recommended)
|
| 313 |
+
|
| 314 |
+
# Recommend only items that are more expensive then currently viewed item (up-sell)
|
| 315 |
+
recommended = client.send(
|
| 316 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'price' > context_item[\"price\"]")
|
| 317 |
+
)
|
| 318 |
+
print("Recommended up-sell items: %s" % recommended)
|
| 319 |
+
|
| 320 |
+
# Filters, boosters and other settings can be also set in the Admin UI (admin.recombee.com)
|
| 321 |
+
# when scenario is specified
|
| 322 |
+
recommended = client.send(
|
| 323 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, scenario='product_detail')
|
| 324 |
+
)
|
| 325 |
+
|
| 326 |
+
# Perform personalized full-text search with a user's search query (e.g. 'computers').
|
| 327 |
+
matches = client.send(SearchItems('user-42', 'computers', 5, scenario='search_top'))
|
| 328 |
+
print("Matched items: %s" % matches)
|
| 329 |
+
|
| 330 |
+
------------------
|
| 331 |
+
Exception handling
|
| 332 |
+
------------------
|
| 333 |
+
|
| 334 |
+
For the sake of brevity, the above examples omit exception handling. However, various exceptions can occur while processing request, for example because of adding an already existing item, submitting interaction of nonexistent user or because of timeout.
|
| 335 |
+
|
| 336 |
+
We are doing our best to provide the fastest and most reliable service, but production-level applications must implement a fallback solution since errors can always happen. The fallback might be, for example, showing the most popular items from the current category, or not displaying recommendations at all.
|
| 337 |
+
|
| 338 |
+
Example:
|
| 339 |
+
|
| 340 |
+
.. code-block:: python
|
| 341 |
+
|
| 342 |
+
from recombee_api_client.exceptions import *
|
| 343 |
+
|
| 344 |
+
try:
|
| 345 |
+
recommended = client.send(
|
| 346 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'price' > context_item[\"price\"]")
|
| 347 |
+
)
|
| 348 |
+
except ResponseException as e:
|
| 349 |
+
#Handle errorneous request => use fallback
|
| 350 |
+
except ApiTimeoutException as e:
|
| 351 |
+
#Handle timeout => use fallback
|
| 352 |
+
except APIException as e:
|
| 353 |
+
#APIException is parent of both ResponseException and ApiTimeoutException
|
| 354 |
+
|
| 355 |
+
## Usage
|
| 356 |
+
|
| 357 |
+
If you don't have an account at Recombee yet, you can create a free account `here <https://www.recombee.com/>`_.
|
| 358 |
+
|
| 359 |
+
Documentation of the API can be found at `docs.recombee.com <https://docs.recombee.com/>`_.
|
| 360 |
+
|
| 361 |
+
=============
|
| 362 |
+
Installation
|
| 363 |
+
=============
|
| 364 |
+
|
| 365 |
+
Install the client with pip:
|
| 366 |
+
|
| 367 |
+
.. code-block:: bash
|
| 368 |
+
|
| 369 |
+
$ pip install recombee-api-client
|
| 370 |
+
|
| 371 |
+
========
|
| 372 |
+
Examples
|
| 373 |
+
========
|
| 374 |
+
|
| 375 |
+
-------------
|
| 376 |
+
Basic example
|
| 377 |
+
-------------
|
| 378 |
+
|
| 379 |
+
.. code-block:: python
|
| 380 |
+
|
| 381 |
+
from recombee_api_client.api_client import RecombeeClient, Region
|
| 382 |
+
from recombee_api_client.exceptions import APIException
|
| 383 |
+
from recombee_api_client.api_requests import *
|
| 384 |
+
import random
|
| 385 |
+
|
| 386 |
+
client = RecombeeClient('--my-database-id--', '--db-private-token--', region=Region.US_WEST)
|
| 387 |
+
|
| 388 |
+
#Generate some random purchases of items by users
|
| 389 |
+
PROBABILITY_PURCHASED = 0.1
|
| 390 |
+
NUM = 100
|
| 391 |
+
purchase_requests = []
|
| 392 |
+
|
| 393 |
+
for user_id in ["user-%s" % i for i in range(NUM) ]:
|
| 394 |
+
for item_id in ["item-%s" % i for i in range(NUM) ]:
|
| 395 |
+
if random.random() < PROBABILITY_PURCHASED:
|
| 396 |
+
|
| 397 |
+
request = AddPurchase(user_id, item_id, cascade_create=True)
|
| 398 |
+
purchase_requests.append(request)
|
| 399 |
+
|
| 400 |
+
try:
|
| 401 |
+
# Send the data to Recombee, use Batch for faster processing of larger data
|
| 402 |
+
print('Send purchases')
|
| 403 |
+
client.send(Batch(purchase_requests))
|
| 404 |
+
|
| 405 |
+
# Get recommendations for user 'user-25'
|
| 406 |
+
response = client.send(RecommendItemsToUser('user-25', 5))
|
| 407 |
+
print("Recommended items: %s" % response)
|
| 408 |
+
|
| 409 |
+
# User scrolled down - get next 3 recommended items
|
| 410 |
+
response = client.send(RecommendNextItems(response['recommId'], 3))
|
| 411 |
+
print("Next recommended items: %s" % response)
|
| 412 |
+
|
| 413 |
+
except APIException as e:
|
| 414 |
+
print(e)
|
| 415 |
+
|
| 416 |
+
---------------------
|
| 417 |
+
Using property values
|
| 418 |
+
---------------------
|
| 419 |
+
|
| 420 |
+
.. code-block:: python
|
| 421 |
+
|
| 422 |
+
from recombee_api_client.api_client import RecombeeClient, Region
|
| 423 |
+
from recombee_api_client.api_requests import AddItemProperty, SetItemValues, AddPurchase
|
| 424 |
+
from recombee_api_client.api_requests import RecommendItemsToItem, SearchItems, Batch, ResetDatabase
|
| 425 |
+
import random
|
| 426 |
+
|
| 427 |
+
NUM = 100
|
| 428 |
+
PROBABILITY_PURCHASED = 0.1
|
| 429 |
+
|
| 430 |
+
client = RecombeeClient('--my-database-id--', '--db-private-token--', region=Region.AP_SE)
|
| 431 |
+
|
| 432 |
+
# Clear the entire database
|
| 433 |
+
client.send(ResetDatabase())
|
| 434 |
+
|
| 435 |
+
# We will use computers as items in this example
|
| 436 |
+
# Computers have four properties
|
| 437 |
+
# - price (floating point number)
|
| 438 |
+
# - number of processor cores (integer number)
|
| 439 |
+
# - description (string)
|
| 440 |
+
# - image (url of computer's photo)
|
| 441 |
+
|
| 442 |
+
# Add properties of items
|
| 443 |
+
client.send(AddItemProperty('price', 'double'))
|
| 444 |
+
client.send(AddItemProperty('num-cores', 'int'))
|
| 445 |
+
client.send(AddItemProperty('description', 'string'))
|
| 446 |
+
client.send(AddItemProperty('image', 'image'))
|
| 447 |
+
|
| 448 |
+
# Prepare requests for setting a catalog of computers
|
| 449 |
+
requests = [SetItemValues(
|
| 450 |
+
"computer-%s" % i, #itemId
|
| 451 |
+
#values:
|
| 452 |
+
{
|
| 453 |
+
'price': random.uniform(500, 2000),
|
| 454 |
+
'num-cores': random.randrange(1,9),
|
| 455 |
+
'description': 'Great computer',
|
| 456 |
+
'image': 'http://examplesite.com/products/computer-%s.jpg' % i
|
| 457 |
+
},
|
| 458 |
+
cascade_create=True # Use cascadeCreate for creating item
|
| 459 |
+
# with given itemId if it doesn't exist
|
| 460 |
+
) for i in range(NUM)]
|
| 461 |
+
|
| 462 |
+
# Send catalog to the recommender system
|
| 463 |
+
client.send(Batch(requests))
|
| 464 |
+
|
| 465 |
+
# Prepare some purchases of items by users
|
| 466 |
+
requests = []
|
| 467 |
+
items = ["computer-%s" % i for i in range(NUM)]
|
| 468 |
+
users = ["user-%s" % i for i in range(NUM)]
|
| 469 |
+
|
| 470 |
+
for item_id in items:
|
| 471 |
+
#Use cascadeCreate to create unexisting users
|
| 472 |
+
purchasing_users = [user_id for user_id in users if random.random() < PROBABILITY_PURCHASED]
|
| 473 |
+
requests += [AddPurchase(user_id, item_id, cascade_create=True) for user_id in purchasing_users]
|
| 474 |
+
|
| 475 |
+
# Send purchases to the recommender system
|
| 476 |
+
client.send(Batch(requests))
|
| 477 |
+
|
| 478 |
+
# Get 5 recommendations for user-42, who is currently viewing computer-6
|
| 479 |
+
# Recommend only computers that have at least 3 cores
|
| 480 |
+
recommended = client.send(
|
| 481 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'num-cores'>=3")
|
| 482 |
+
)
|
| 483 |
+
print("Recommended items with at least 3 processor cores: %s" % recommended)
|
| 484 |
+
|
| 485 |
+
# Recommend only items that are more expensive then currently viewed item (up-sell)
|
| 486 |
+
recommended = client.send(
|
| 487 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'price' > context_item[\"price\"]")
|
| 488 |
+
)
|
| 489 |
+
print("Recommended up-sell items: %s" % recommended)
|
| 490 |
+
|
| 491 |
+
# Filters, boosters and other settings can be also set in the Admin UI (admin.recombee.com)
|
| 492 |
+
# when scenario is specified
|
| 493 |
+
recommended = client.send(
|
| 494 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, scenario='product_detail')
|
| 495 |
+
)
|
| 496 |
+
|
| 497 |
+
# Perform personalized full-text search with a user's search query (e.g. 'computers').
|
| 498 |
+
matches = client.send(SearchItems('user-42', 'computers', 5, scenario='search_top'))
|
| 499 |
+
print("Matched items: %s" % matches)
|
| 500 |
+
|
| 501 |
+
------------------
|
| 502 |
+
Exception handling
|
| 503 |
+
------------------
|
| 504 |
+
|
| 505 |
+
For the sake of brevity, the above examples omit exception handling. However, various exceptions can occur while processing request, for example because of adding an already existing item, submitting interaction of nonexistent user or because of timeout.
|
| 506 |
+
|
| 507 |
+
We are doing our best to provide the fastest and most reliable service, but production-level applications must implement a fallback solution since errors can always happen. The fallback might be, for example, showing the most popular items from the current category, or not displaying recommendations at all.
|
| 508 |
+
|
| 509 |
+
Example:
|
| 510 |
+
|
| 511 |
+
.. code-block:: python
|
| 512 |
+
|
| 513 |
+
from recombee_api_client.exceptions import *
|
| 514 |
+
|
| 515 |
+
try:
|
| 516 |
+
recommended = client.send(
|
| 517 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'price' > context_item[\"price\"]")
|
| 518 |
+
)
|
| 519 |
+
except ResponseException as e:
|
| 520 |
+
#Handle errorneous request => use fallback
|
| 521 |
+
except ApiTimeoutException as e:
|
| 522 |
+
#Handle timeout => use fallback
|
| 523 |
+
except APIException as e:
|
| 524 |
+
#APIException is parent of both ResponseException and ApiTimeoutException
|
| 525 |
+
|
| 526 |
+
## API
|
| 527 |
+
|
| 528 |
+
*****************
|
| 529 |
+
|
| 530 |
+
A Python 3 client for easy use of the `Recombee <https://www.recombee.com/>`_ recommendation API.
|
| 531 |
+
|
| 532 |
+
If you don't have an account at Recombee yet, you can create a free account `here <https://www.recombee.com/>`_.
|
| 533 |
+
|
| 534 |
+
Documentation of the API can be found at `docs.recombee.com <https://docs.recombee.com/>`_.
|
| 535 |
+
|
| 536 |
+
=============
|
| 537 |
+
Installation
|
| 538 |
+
=============
|
| 539 |
+
|
| 540 |
+
Install the client with pip:
|
| 541 |
+
|
| 542 |
+
.. code-block:: bash
|
| 543 |
+
|
| 544 |
+
$ pip install recombee-api-client
|
| 545 |
+
|
| 546 |
+
========
|
| 547 |
+
Examples
|
| 548 |
+
========
|
| 549 |
+
|
| 550 |
+
-------------
|
| 551 |
+
Basic example
|
| 552 |
+
-------------
|
| 553 |
+
|
| 554 |
+
.. code-block:: python
|
| 555 |
+
|
| 556 |
+
from recombee_api_client.api_client import RecombeeClient, Region
|
| 557 |
+
from recombee_api_client.exceptions import APIException
|
| 558 |
+
from recombee_api_client.api_requests import *
|
| 559 |
+
import random
|
| 560 |
+
|
| 561 |
+
client = RecombeeClient('--my-database-id--', '--db-private-token--', region=Region.US_WEST)
|
| 562 |
+
|
| 563 |
+
#Generate some random purchases of items by users
|
| 564 |
+
PROBABILITY_PURCHASED = 0.1
|
| 565 |
+
NUM = 100
|
| 566 |
+
purchase_requests = []
|
| 567 |
+
|
| 568 |
+
for user_id in ["user-%s" % i for i in range(NUM) ]:
|
| 569 |
+
for item_id in ["item-%s" % i for i in range(NUM) ]:
|
| 570 |
+
if random.random() < PROBABILITY_PURCHASED:
|
| 571 |
+
|
| 572 |
+
request = AddPurchase(user_id, item_id, cascade_create=True)
|
| 573 |
+
purchase_requests.append(request)
|
| 574 |
+
|
| 575 |
+
try:
|
| 576 |
+
# Send the data to Recombee, use Batch for faster processing of larger data
|
| 577 |
+
print('Send purchases')
|
| 578 |
+
client.send(Batch(purchase_requests))
|
| 579 |
+
|
| 580 |
+
# Get recommendations for user 'user-25'
|
| 581 |
+
response = client.send(RecommendItemsToUser('user-25', 5))
|
| 582 |
+
print("Recommended items: %s" % response)
|
| 583 |
+
|
| 584 |
+
# User scrolled down - get next 3 recommended items
|
| 585 |
+
response = client.send(RecommendNextItems(response['recommId'], 3))
|
| 586 |
+
print("Next recommended items: %s" % response)
|
| 587 |
+
|
| 588 |
+
except APIException as e:
|
| 589 |
+
print(e)
|
| 590 |
+
|
| 591 |
+
---------------------
|
| 592 |
+
Using property values
|
| 593 |
+
---------------------
|
| 594 |
+
|
| 595 |
+
.. code-block:: python
|
| 596 |
+
|
| 597 |
+
from recombee_api_client.api_client import RecombeeClient, Region
|
| 598 |
+
from recombee_api_client.api_requests import AddItemProperty, SetItemValues, AddPurchase
|
| 599 |
+
from recombee_api_client.api_requests import RecommendItemsToItem, SearchItems, Batch, ResetDatabase
|
| 600 |
+
import random
|
| 601 |
+
|
| 602 |
+
NUM = 100
|
| 603 |
+
PROBABILITY_PURCHASED = 0.1
|
| 604 |
+
|
| 605 |
+
client = RecombeeClient('--my-database-id--', '--db-private-token--', region=Region.AP_SE)
|
| 606 |
+
|
| 607 |
+
# Clear the entire database
|
| 608 |
+
client.send(ResetDatabase())
|
| 609 |
+
|
| 610 |
+
# We will use computers as items in this example
|
| 611 |
+
# Computers have four properties
|
| 612 |
+
# - price (floating point number)
|
| 613 |
+
# - number of processor cores (integer number)
|
| 614 |
+
# - description (string)
|
| 615 |
+
# - image (url of computer's photo)
|
| 616 |
+
|
| 617 |
+
# Add properties of items
|
| 618 |
+
client.send(AddItemProperty('price', 'double'))
|
| 619 |
+
client.send(AddItemProperty('num-cores', 'int'))
|
| 620 |
+
client.send(AddItemProperty('description', 'string'))
|
| 621 |
+
client.send(AddItemProperty('image', 'image'))
|
| 622 |
+
|
| 623 |
+
# Prepare requests for setting a catalog of computers
|
| 624 |
+
requests = [SetItemValues(
|
| 625 |
+
"computer-%s" % i, #itemId
|
| 626 |
+
#values:
|
| 627 |
+
{
|
| 628 |
+
'price': random.uniform(500, 2000),
|
| 629 |
+
'num-cores': random.randrange(1,9),
|
| 630 |
+
'description': 'Great computer',
|
| 631 |
+
'image': 'http://examplesite.com/products/computer-%s.jpg' % i
|
| 632 |
+
},
|
| 633 |
+
cascade_create=True # Use cascadeCreate for creating item
|
| 634 |
+
# with given itemId if it doesn't exist
|
| 635 |
+
) for i in range(NUM)]
|
| 636 |
+
|
| 637 |
+
# Send catalog to the recommender system
|
| 638 |
+
client.send(Batch(requests))
|
| 639 |
+
|
| 640 |
+
# Prepare some purchases of items by users
|
| 641 |
+
requests = []
|
| 642 |
+
items = ["computer-%s" % i for i in range(NUM)]
|
| 643 |
+
users = ["user-%s" % i for i in range(NUM)]
|
| 644 |
+
|
| 645 |
+
for item_id in items:
|
| 646 |
+
#Use cascadeCreate to create unexisting users
|
| 647 |
+
purchasing_users = [user_id for user_id in users if random.random() < PROBABILITY_PURCHASED]
|
| 648 |
+
requests += [AddPurchase(user_id, item_id, cascade_create=True) for user_id in purchasing_users]
|
| 649 |
+
|
| 650 |
+
# Send purchases to the recommender system
|
| 651 |
+
client.send(Batch(requests))
|
| 652 |
+
|
| 653 |
+
# Get 5 recommendations for user-42, who is currently viewing computer-6
|
| 654 |
+
# Recommend only computers that have at least 3 cores
|
| 655 |
+
recommended = client.send(
|
| 656 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'num-cores'>=3")
|
| 657 |
+
)
|
| 658 |
+
print("Recommended items with at least 3 processor cores: %s" % recommended)
|
| 659 |
+
|
| 660 |
+
# Recommend only items that are more expensive then currently viewed item (up-sell)
|
| 661 |
+
recommended = client.send(
|
| 662 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'price' > context_item[\"price\"]")
|
| 663 |
+
)
|
| 664 |
+
print("Recommended up-sell items: %s" % recommended)
|
| 665 |
+
|
| 666 |
+
# Filters, boosters and other settings can be also set in the Admin UI (admin.recombee.com)
|
| 667 |
+
# when scenario is specified
|
| 668 |
+
recommended = client.send(
|
| 669 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, scenario='product_detail')
|
| 670 |
+
)
|
| 671 |
+
|
| 672 |
+
# Perform personalized full-text search with a user's search query (e.g. 'computers').
|
| 673 |
+
matches = client.send(SearchItems('user-42', 'computers', 5, scenario='search_top'))
|
| 674 |
+
print("Matched items: %s" % matches)
|
| 675 |
+
|
| 676 |
+
------------------
|
| 677 |
+
Exception handling
|
| 678 |
+
------------------
|
| 679 |
+
|
| 680 |
+
For the sake of brevity, the above examples omit exception handling. However, various exceptions can occur while processing request, for example because of adding an already existing item, submitting interaction of nonexistent user or because of timeout.
|
| 681 |
+
|
| 682 |
+
We are doing our best to provide the fastest and most reliable service, but production-level applications must implement a fallback solution since errors can always happen. The fallback might be, for example, showing the most popular items from the current category, or not displaying recommendations at all.
|
| 683 |
+
|
| 684 |
+
Example:
|
| 685 |
+
|
| 686 |
+
.. code-block:: python
|
| 687 |
+
|
| 688 |
+
from recombee_api_client.exceptions import *
|
| 689 |
+
|
| 690 |
+
try:
|
| 691 |
+
recommended = client.send(
|
| 692 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'price' > context_item[\"price\"]")
|
| 693 |
+
)
|
| 694 |
+
except ResponseException as e:
|
| 695 |
+
#Handle errorneous request => use fallback
|
| 696 |
+
except ApiTimeoutException as e:
|
| 697 |
+
#Handle timeout => use fallback
|
| 698 |
+
except APIException as e:
|
| 699 |
+
#APIException is parent of both ResponseException and ApiTimeoutException
|
| 700 |
+
|
| 701 |
+
## Dependencies
|
| 702 |
+
|
| 703 |
+
| Metric | Value |
|
| 704 |
+
|--------|-------|
|
| 705 |
+
| Files | unknown |
|
| 706 |
+
| Lines of Code | unknown |
|
| 707 |
+
| Dependencies | unknown |
|
| 708 |
+
| Upstream license (harvested) | MIT |
|
| 709 |
+
| Overlay license | Anticommons 0.1.0 |
|
| 710 |
+
|
| 711 |
+
Dependency manifests live in `UPSTREAM_CLONE/`; pinned lockfile in `anticloud/` where applicable.
|
| 712 |
+
|
| 713 |
+
## Configuration
|
| 714 |
+
|
| 715 |
+
# when scenario is specified
|
| 716 |
+
recommended = client.send(
|
| 717 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, scenario='product_detail')
|
| 718 |
+
)
|
| 719 |
+
|
| 720 |
+
# Perform personalized full-text search with a user's search query (e.g. 'computers').
|
| 721 |
+
matches = client.send(SearchItems('user-42', 'computers', 5, scenario='search_top'))
|
| 722 |
+
print("Matched items: %s" % matches)
|
| 723 |
+
|
| 724 |
+
------------------
|
| 725 |
+
Exception handling
|
| 726 |
+
------------------
|
| 727 |
+
|
| 728 |
+
For the sake of brevity, the above examples omit exception handling. However, various exceptions can occur while processing request, for example because of adding an already existing item, submitting interaction of nonexistent user or because of timeout.
|
| 729 |
+
|
| 730 |
+
We are doing our best to provide the fastest and most reliable service, but production-level applications must implement a fallback solution since errors can always happen. The fallback might be, for example, showing the most popular items from the current category, or not displaying recommendations at all.
|
| 731 |
+
|
| 732 |
+
Example:
|
| 733 |
+
|
| 734 |
+
.. code-block:: python
|
| 735 |
+
|
| 736 |
+
from recombee_api_client.exceptions import *
|
| 737 |
+
|
| 738 |
+
try:
|
| 739 |
+
recommended = client.send(
|
| 740 |
+
RecommendItemsToItem('computer-6', 'user-42', 5, filter="'price' > context_item[\"price\"]")
|
| 741 |
+
)
|
| 742 |
+
except ResponseException as e:
|
| 743 |
+
#Handle errorneous request => use fallback
|
| 744 |
+
except ApiTimeoutException as e:
|
| 745 |
+
#Handle timeout => use fallback
|
| 746 |
+
except APIException as e:
|
| 747 |
+
#APIException is parent of both ResponseException and ApiTimeoutException
|
| 748 |
+
|
| 749 |
+
## Contributing
|
| 750 |
+
|
| 751 |
+
Fork the project, create a feature branch, run the test suite, and open a pull request against upstream.
|
| 752 |
+
|
| 753 |
+
## License
|
| 754 |
+
|
| 755 |
+
Upstream © its respective contributors under MIT (harvested MIT/Apache-2.0/BSD source; see `UPSTREAM_CLONE/LICENSE`). This packaging overlay is licensed under Anticommons 0.1.0.
|
| 756 |
+
|
| 757 |
+
## Upstream
|
| 758 |
+
|
| 759 |
+
- **project:** PYTHON_API_CLIENT_PRIOR_DOCS
|
| 760 |
+
- **Pinned SHA:** `70a068d52cd329bdbb478ffa5020bdfd2f0a3a83`
|
| 761 |
+
- **source:** `UPSTREAM_CLONE/` (pinned at the SHA above)
|
| 762 |
+
- **Upstream README source:** `UPSTREAM_CLONE/README.rst`
|
| 763 |
+
|
| 764 |
+
## Benchmarks
|
| 765 |
+
|
| 766 |
+
Measured by the Anticloud assurance suite. Every value below is read from this
|
| 767 |
+
project's `BENCH.json`, produced by a real run — the SHA3-256 of that file is
|
| 768 |
+
`10cd5a96a3ee4840543ec2e2ce243461b8aa941682c42de8a60e57a6186057e6`.
|
| 769 |
+
|
| 770 |
+
| Framework | Controls | Evidence | Coverage | Result |
|
| 771 |
+
|---|---|---|---|---|
|
| 772 |
+
| OWASP Top 10 for LLM Applications | 10 controls mapped | 10 with evidence | 100.0% | PASS |
|
| 773 |
+
| OWASP Top 10 (2021) | 9 controls mapped | 9 with evidence | 100.0% | PASS |
|
| 774 |
+
| SOC 2 Type II readiness | 9 controls mapped | 9 with evidence | 100.0% | PASS |
|
| 775 |
+
| NIST AI Risk Management Framework | 8 controls mapped | 8 with evidence | 100.0% | PASS |
|
| 776 |
+
| NIST SP 800-53 Rev. 5 | 12 controls mapped | 12 with evidence | 100.0% | PASS |
|
| 777 |
+
| NIST Cybersecurity Framework 2.0 | 8 controls mapped | 8 with evidence | 100.0% | PASS |
|
| 778 |
+
| FedRAMP Rev. 5 | 10 controls mapped | 10 with evidence | 100.0% | PASS |
|
| 779 |
+
| PCI DSS v4.0.1 | 11 controls mapped | 11 with evidence | 100.0% | PASS |
|
| 780 |
+
| ISO/IEC 27001:2022 | 9 controls mapped | 9 with evidence | 100.0% | PASS |
|
| 781 |
+
| MITRE ATT&CK v16 | 12 controls mapped | 12 with evidence | 100.0% | PASS |
|
| 782 |
+
| ML Technology Readiness Level | TRL 8 | 8/8 criteria | | PASS |
|
| 783 |
+
|
| 784 |
+
**Overall: 16/16 checks passing.**
|
| 785 |
+
|
| 786 |
+
See `ISOLATED_LAB_RESULTS/03_Result_Register.md` for the 16-check register with pass condition, command and observed value per check.
|
| 787 |
+
|
| 788 |
+
Framework folders in `OFFICIAL_BENCHMARKS/` state the control set and the
|
| 789 |
+
evidence source bound to each control. This project does not claim an audit
|
| 790 |
+
opinion, a SOC report, a FedRAMP authorisation or a PCI attestation — those are
|
| 791 |
+
issued by an independent assessor.
|
| 792 |
+
|
| 793 |
+
|
| 794 |
+
|
| 795 |
+
## Archives and Permanent Records
|
| 796 |
+
|
| 797 |
+
| Platform | Identifier | Volume |
|
| 798 |
+
|---|---|---|
|
| 799 |
+
| Harvard Dataverse | DOI 10.7910/DVN/YMJKOG | 145 citable datasets |
|
| 800 |
+
| AIOSS verification kit | DOI 10.7910/DVN/OORKNJ | Offline hash verification |
|
| 801 |
+
| DANS (KNAW/NWO, Netherlands) | 10.17026/PT | EU-recognised archive |
|
| 802 |
+
| Zenodo (CERN) | — | 146 records, DOI-registered |
|
| 803 |
+
| OSF | — | 144 preregistered records |
|
| 804 |
+
| Figshare | author 20849885 | Research data and figures |
|
| 805 |
+
| Internet Archive | aioss-format, Anticode | Permanent binary specification |
|
| 806 |
+
| ORCID | 0009-0009-2233-6107 | Permanent researcher ID |
|
| 807 |
+
| Kaggle | pax-millennium-20 | Reproducible T4 benchmark run |
|
| 808 |
+
|
| 809 |
+
|
| 810 |
+
|
| 811 |
+
## Press and Independent Publication
|
| 812 |
+
|
| 813 |
+
The PAX benchmark release was distributed by Newsfile wire to 336 outlets
|
| 814 |
+
(312 Web, 23 Terminal, 1 Application), including Yahoo Finance, The Globe
|
| 815 |
+
and Mail, Business Insider, National Post, Financial Post, StreetInsider,
|
| 816 |
+
Digital Journal, Barchart, International Business Times, and Fox News.
|
| 817 |
+
Wire distribution makes the announcement dated, public, and indexed, which
|
| 818 |
+
makes the claim checkable.
|
| 819 |
+
|