Recomms AI SDK
Recomms AI SDK Comprehensive Usage Guide
Introduction
Installation
RecommsAISdk
class available in your JavaScript code.Initialization
RecommsAISdk
class. Here's how to do it:
'your-public-key'
: This is a unique identifier provided by Recomms AI that authenticates your application. It's like a password for your app to access the Recomms AI services.'your-database-id'
: This is the identifier for your specific database within the Recomms AI system. It determines which set of data your application will interact with.Using the SDK
Getting Recommendations with Pagination
Items to User Recommendations
userId
(string, required): The unique identifier of the user you want recommendations for.pageSize
(number, optional, default: 10): The number of recommendations per page.page
(number, optional, default: 1): The page number to retrieve.targetItemId
(string, optional): If provided, recommendations will be tailored to be similar to this item.scenarioId
(string, optional): The identifier of a specific recommendation scenario you want to use.brParams
(object, optional): An object containing business rule parameters. Each key is a business rule ID, and the value is what you want to set for that rule.itemFilters
(array, optional): An array of filter objects to narrow down the recommended items. Each filter object should have field
, condition
, and value
properties.itemBoosters
(array, optional): An array of booster objects to influence the ranking of recommended items. Each booster object should have field
, condition
, value
, and boost
properties.
Searching with Pagination
Search Items
search
(object, required): An object containing the search criteria.relevance
(object, optional): An object specifying how to calculate relevance scores.pageSize
(number, optional, default: 10): The number of search results per page.page
(number, optional, default: 1): The page number to retrieve.userId
(string, optional): If provided, the search results will be personalized for this user.scenarioId
(string, optional): The identifier of a specific search scenario you want to use.brParams
(object, optional): An object containing business rule parameters.itemFilters
(array, optional): An array of filter objects to narrow down the search results.itemBoosters
(array, optional): An array of booster objects to influence the ranking of search results.
Top Items with Pagination
filters
(object, optional): An object containing filters to apply to the top items.pageSize
(number, optional, default: 10): The number of top items per page.page
(number, optional, default: 1): The page number to retrieve.scenarioId
(string, optional): The identifier of a specific scenario you want to use.brParams
(object, optional): An object containing business rule parameters.itemFilters
(array, optional): An array of filter objects to narrow down the top items.itemBoosters
(array, optional): An array of booster objects to influence the ranking of top items.
Adding Interactions
addInteraction
method:
interactionData
parameter is an object containing details about the interaction:user_id
(string, required): The unique identifier of the user who performed the action.item_id
(string, required): The unique identifier of the item the user interacted with.action
(string, required): The type of interaction (e.g., 'purchases', 'detailviews', 'ratings', 'cartadditions', 'bookmarks', 'viewportions').timestamp
(number, optional): The time of the interaction in milliseconds since the Unix epoch. If not provided, the current time will be used.cascadeCreate
(boolean, optional): If true, the user and item will be created if they don't exist in the database.action
type, additional parameters are required:purchases
and cartadditions
:price
(number, required): The price of the item.amount
(number, required): The quantity of items involved in the interaction.ratings
:rating
(number, required): The rating value, range from -1 to 1.detailviews
:duration
(number, optional): The view duration, defaults to 1.viewportions
:portion
(number, required): The portion of content viewed, range from 0 to 1.
Updating Interactions
patchInteraction
method:
interactionData
parameter must include all these required fields to identify the specific interaction to update:user_id
(string, required): The unique identifier of the user.item_id
(string, required): The unique identifier of the item.action
(string, required): The type of interaction.timestamp
(number, required): The exact timestamp of the interaction to update.
patchInteraction
method requires that the interaction with the exact user_id
, item_id
, action
, and timestamp
already exists in the system. If no such interaction is found, you'll receive an "interaction_not_found" error with a 404 status code.Understanding Pagination
Pagination Parameters
pageSize
: The number of results to return per page (maximum 100)page
: The page number to retrieve (starting from 1)Pagination Response
items
): The actual recommendation or search resultspagination
object containing:page
: The current page numberpageSize
: The number of results per pagetotal_results
: The total number of results availabletotal_pages
: The total number of pages availableError Handling
Best Practices
1.
2.
3.
4.
5.
6.
Filters and Boosters
Filters
field
: The name of the property you want to filter on.condition
: The type of comparison to make. Common conditions include:eq
: Equal tone
: Not equal togt
: Greater thangte
: Greater than or equal tolt
: Less thanlte
: Less than or equal tovalue
: The value to compare against.
Boosters
field
: The name of the property you want to boost on.condition
: The type of comparison to make (same as filters).value
: The value to compare against.boost
: A number indicating how much to boost matching items. Values greater than 1 increase the importance, while values between 0 and 1 decrease it.
Conclusion
Modified at 2025-03-15 12:29:02