AmazonPersonalize#

class langchain_experimental.recommenders.amazon_personalize.AmazonPersonalize(campaign_arn: str | None = None, recommender_arn: str | None = None, client: Any | None = None, credentials_profile_name: str | None = None, region_name: str | None = None)[source]#

Amazon Personalize Runtime wrapper for executing real-time operations.

See [this link for more details](https://docs.aws.amazon.com/personalize/latest/dg/API_Operations_Amazon_Personalize_Runtime.html).

Parameters:
  • campaign_arn (str | None) – str, Optional: The Amazon Resource Name (ARN) of the campaign to use for getting recommendations.

  • recommender_arn (str | None) – str, Optional: The Amazon Resource Name (ARN) of the recommender to use to get recommendations

  • client (Any | None) – Optional: boto3 client

  • credentials_profile_name (str | None) – str, Optional :AWS profile name

  • region_name (str | None) – str, Optional: AWS region, e.g., us-west-2

Example


personalize_client = AmazonPersonalize (

campaignArn=’<my-campaign-arn>’ )

Methods

__init__([campaign_arn,Β recommender_arn,Β ...])

get_personalized_ranking(user_id,Β input_list)

Re-ranks a list of recommended items for the given user.

get_recommendations([user_id,Β item_id,Β ...])

Get recommendations from Amazon Personalize service.

__init__(campaign_arn: str | None = None, recommender_arn: str | None = None, client: Any | None = None, credentials_profile_name: str | None = None, region_name: str | None = None)[source]#
Parameters:
  • campaign_arn (str | None) –

  • recommender_arn (str | None) –

  • client (Any | None) –

  • credentials_profile_name (str | None) –

  • region_name (str | None) –

get_personalized_ranking(user_id: str, input_list: List[str], filter_arn: str | None = None, filter_values: Mapping[str, str] | None = None, context: Mapping[str, str] | None = None, metadata_columns: Mapping[str, Sequence[str]] | None = None, **kwargs: Any) β†’ Mapping[str, Any][source]#

Re-ranks a list of recommended items for the given user.

https://docs.aws.amazon.com/personalize/latest/dg/API_RS_GetPersonalizedRanking.html

Parameters:
  • user_id (str) – str, Required: The user identifier for which to retrieve recommendations

  • input_list (List[str]) – List[str], Required: A list of items (by itemId) to rank

  • filter_arn (str | None) – str, Optional: The ARN of the filter to apply

  • filter_values (Mapping[str, str] | None) – Mapping, Optional: The values to use when filtering recommendations.

  • context (Mapping[str, str] | None) – Mapping, Optional: The contextual metadata to use when getting recommendations

  • metadata_columns (Mapping[str, Sequence[str]] | None) – Mapping, Optional: The metadata Columns to be returned as part of the response.

  • kwargs (Any) –

Returns:

Mapping[str, Any]: Returns personalizedRanking

and recommendationId.

Return type:

response

Example


personalize_client = AmazonPersonalize(campaignArn=’<my-campaign-arn>’ )

response = personalize_client.get_personalized_ranking(user_id=”1”,

input_list=[β€œ123,”256”])

get_recommendations(user_id: str | None = None, item_id: str | None = None, filter_arn: str | None = None, filter_values: Mapping[str, str] | None = None, num_results: int | None = 10, context: Mapping[str, str] | None = None, promotions: Sequence[Mapping[str, Any]] | None = None, metadata_columns: Mapping[str, Sequence[str]] | None = None, **kwargs: Any) β†’ Mapping[str, Any][source]#

Get recommendations from Amazon Personalize service.

See more details at: https://docs.aws.amazon.com/personalize/latest/dg/API_RS_GetRecommendations.html

Parameters:
  • user_id (str | None) – str, Optional: The user identifier for which to retrieve recommendations

  • item_id (str | None) – str, Optional: The item identifier for which to retrieve recommendations

  • filter_arn (str | None) – str, Optional: The ARN of the filter to apply to the returned recommendations

  • filter_values (Mapping[str, str] | None) – Mapping, Optional: The values to use when filtering recommendations.

  • num_results (int | None) – int, Optional: Default=10: The number of results to return

  • context (Mapping[str, str] | None) – Mapping, Optional: The contextual metadata to use when getting recommendations

  • promotions (Sequence[Mapping[str, Any]] | None) – Sequence, Optional: The promotions to apply to the recommendation request.

  • metadata_columns (Mapping[str, Sequence[str]] | None) – Mapping, Optional: The metadata Columns to be returned as part of the response.

  • kwargs (Any) –

Returns:

Mapping[str, Any]: Returns an itemList and recommendationId.

Return type:

response

Example


personalize_client = AmazonPersonalize(campaignArn=’<my-campaign-arn>’ )

response = personalize_client.get_recommendations(user_id=”1”)