Skip to content

get_recommendations

get_recommendations(
    *,
    config_overrides: Optional[PersonalizeRuntimeClientConfig] = None,
    campaign_arn: Optional[Arn] = None,
    item_id: Optional[ItemID] = None,
    user_id: Optional[UserID] = None,
    num_results: Optional[NumResults] = None,
    context: Optional[Context] = None,
    filter_arn: Optional[Arn] = None,
    filter_values: Optional[FilterValues] = None,
    recommender_arn: Optional[Arn] = None,
    promotions: Optional[PromotionList] = None,
    metadata_columns: Optional[MetadataColumns] = None,
) -> GetRecommendationsResponse

Returns a list of recommended items. For campaigns, the campaign's Amazon Resource Name (ARN) is required and the required user and item input depends on the recipe type used to create the solution backing the campaign as follows:

  • USER_PERSONALIZATION - userId required, itemId not used

  • RELATED_ITEMS - itemId required, userId not used

Campaigns that are backed by a solution created using a recipe of type PERSONALIZED_RANKING use the API.

For recommenders, the recommender's ARN is required and the required item and user input depends on the use case (domain-based recipe) backing the recommender. For information on use case requirements see Choosing recommender use cases.

Parameters:

  • campaign_arn (Optional[Arn], default: None ) –

    The Amazon Resource Name (ARN) of the campaign to use for getting recommendations.

  • item_id (Optional[ItemID], default: None ) –

    The item ID to provide recommendations for.

    Required for RELATED_ITEMS recipe type.

  • user_id (Optional[UserID], default: None ) –

    The user ID to provide recommendations for.

    Required for USER_PERSONALIZATION recipe type.

  • num_results (Optional[NumResults], default: None ) –

    The number of results to return. The default is 25. If you are including metadata in recommendations, the maximum is 50. Otherwise, the maximum is 500.

  • context (Optional[Context], default: None ) –

    The contextual metadata to use when getting recommendations. Contextual metadata includes any interaction information that might be relevant when getting a user's recommendations, such as the user's current location or device type.

  • filter_arn (Optional[Arn], default: None ) –

    The ARN of the filter to apply to the returned recommendations. For more information, see Filtering Recommendations.

    When using this parameter, be sure the filter resource is ACTIVE.

  • filter_values (Optional[FilterValues], default: None ) –

    The values to use when filtering recommendations. For each placeholder parameter in your filter expression, provide the parameter name (in matching case) as a key and the filter value(s) as the corresponding value. Separate multiple values for one parameter with a comma.

    For filter expressions that use an INCLUDE element to include items, you must provide values for all parameters that are defined in the expression. For filters with expressions that use an EXCLUDE element to exclude items, you can omit the filter-values.In this case, Amazon Personalize doesn't use that portion of the expression to filter recommendations.

    For more information, see Filtering recommendations and user segments.

  • recommender_arn (Optional[Arn], default: None ) –

    The Amazon Resource Name (ARN) of the recommender to use to get recommendations. Provide a recommender ARN if you created a Domain dataset group with a recommender for a domain use case.

  • promotions (Optional[PromotionList], default: None ) –

    The promotions to apply to the recommendation request. A promotion defines additional business rules that apply to a configurable subset of recommended items.

  • metadata_columns (Optional[MetadataColumns], default: None ) –

    If you enabled metadata in recommendations when you created or updated the campaign or recommender, specify the metadata columns from your Items dataset to include in item recommendations. The map key is ITEMS and the value is a list of column names from your Items dataset. The maximum number of columns you can provide is 10.

    For information about enabling metadata for a campaign, see Enabling metadata in recommendations for a campaign. For information about enabling metadata for a recommender, see Enabling metadata in recommendations for a recommender.

Raises:

Source code in docs_src/capo_personalize_runtime/_services/personalize_runtime.py
def get_recommendations(
    self,
    *,
    config_overrides: Optional[PersonalizeRuntimeClientConfig] = None,
    campaign_arn: Optional["capo_personalize_runtime.types.arn.Arn"] = None,
    item_id: Optional["capo_personalize_runtime.types.item_id.ItemID"] = None,
    user_id: Optional["capo_personalize_runtime.types.user_id.UserID"] = None,
    num_results: Optional[
        "capo_personalize_runtime.types.num_results.NumResults"
    ] = None,
    context: Optional["capo_personalize_runtime.types.context.Context"] = None,
    filter_arn: Optional["capo_personalize_runtime.types.arn.Arn"] = None,
    filter_values: Optional[
        "capo_personalize_runtime.types.filter_values.FilterValues"
    ] = None,
    recommender_arn: Optional["capo_personalize_runtime.types.arn.Arn"] = None,
    promotions: Optional[
        "capo_personalize_runtime.types.promotion_list.PromotionList"
    ] = None,
    metadata_columns: Optional[
        "capo_personalize_runtime.types.metadata_columns.MetadataColumns"
    ] = None,
) -> "capo_personalize_runtime.types.get_recommendations_response.GetRecommendationsResponse":
    """<p>Returns a list of recommended items. For campaigns, the campaign's Amazon Resource Name (ARN) is required and the required user and item input depends on the recipe type used to create the solution backing the campaign as follows:</p> <ul> <li> <p>USER_PERSONALIZATION - <code>userId</code> required, <code>itemId</code> not used</p> </li> <li> <p>RELATED_ITEMS - <code>itemId</code> required, <code>userId</code> not used</p> </li> </ul> <note> <p>Campaigns that are backed by a solution created using a recipe of type PERSONALIZED_RANKING use the API.</p> </note> <p> For recommenders, the recommender's ARN is required and the required item and user input depends on the use case (domain-based recipe) backing the recommender. For information on use case requirements see <a href="https://docs.aws.amazon.com/personalize/latest/dg/domain-use-cases.html">Choosing recommender use cases</a>. </p>

    Args:
        campaign_arn: <p>The Amazon Resource Name (ARN) of the campaign to use for getting recommendations.</p>
        item_id: <p>The item ID to provide recommendations for.</p> <p>Required for <code>RELATED_ITEMS</code> recipe type.</p>
        user_id: <p>The user ID to provide recommendations for.</p> <p>Required for <code>USER_PERSONALIZATION</code> recipe type.</p>
        num_results: <p>The number of results to return. The default is 25. If you are including metadata in recommendations, the maximum is 50. Otherwise, the maximum is 500.</p>
        context: <p>The contextual metadata to use when getting recommendations. Contextual metadata includes any interaction information that might be relevant when getting a user's recommendations, such as the user's current location or device type.</p>
        filter_arn: <p>The ARN of the filter to apply to the returned recommendations. For more information, see <a href="https://docs.aws.amazon.com/personalize/latest/dg/filter.html">Filtering Recommendations</a>.</p> <p>When using this parameter, be sure the filter resource is <code>ACTIVE</code>.</p>
        filter_values: <p>The values to use when filtering recommendations. For each placeholder parameter in your filter expression, provide the parameter name (in matching case) as a key and the filter value(s) as the corresponding value. Separate multiple values for one parameter with a comma. </p> <p>For filter expressions that use an <code>INCLUDE</code> element to include items, you must provide values for all parameters that are defined in the expression. For filters with expressions that use an <code>EXCLUDE</code> element to exclude items, you can omit the <code>filter-values</code>.In this case, Amazon Personalize doesn't use that portion of the expression to filter recommendations.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/personalize/latest/dg/filter.html">Filtering recommendations and user segments</a>.</p>
        recommender_arn: <p>The Amazon Resource Name (ARN) of the recommender to use to get recommendations. Provide a recommender ARN if you created a Domain dataset group with a recommender for a domain use case.</p>
        promotions: <p>The promotions to apply to the recommendation request. A promotion defines additional business rules that apply to a configurable subset of recommended items.</p>
        metadata_columns: <p>If you enabled metadata in recommendations when you created or updated the campaign or recommender, specify the metadata columns from your Items dataset to include in item recommendations. The map key is <code>ITEMS</code> and the value is a list of column names from your Items dataset. The maximum number of columns you can provide is 10.</p> <p> For information about enabling metadata for a campaign, see <a href="https://docs.aws.amazon.com/personalize/latest/dg/campaigns.html#create-campaign-return-metadata">Enabling metadata in recommendations for a campaign</a>. For information about enabling metadata for a recommender, see <a href="https://docs.aws.amazon.com/personalize/latest/dg/creating-recommenders.html#create-recommender-return-metadata">Enabling metadata in recommendations for a recommender</a>. </p>

    Raises:
        capo_personalize_runtime.errors.invalid_input_exception.InvalidInputException: <p>Provide a valid value for the field or parameter.</p>
        capo_personalize_runtime.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource does not exist.</p>
        capo_personalize_runtime.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_personalize_runtime.types.get_recommendations_request.GetRecommendationsRequest]",
    ) -> OperationResponse[
        "capo_personalize_runtime.types.get_recommendations_response.GetRecommendationsResponse"
    ]:
        import capo_personalize_runtime._operations.amazon_personalize_runtime.get_recommendations

        output, http_response = (
            capo_personalize_runtime._operations.amazon_personalize_runtime.get_recommendations.get_recommendations(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_personalize_runtime.types.get_recommendations_request.GetRecommendationsRequest",
    ) -> dict[str, Any]:
        import capo_personalize_runtime.types.get_recommendations_request

        return capo_personalize_runtime.types.get_recommendations_request.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_personalize_runtime.types.get_recommendations_response.GetRecommendationsResponse",
    ) -> dict[str, Any]:
        import capo_personalize_runtime.types.get_recommendations_response

        return capo_personalize_runtime.types.get_recommendations_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "GetRecommendations",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_personalize_runtime.types.get_recommendations_request.GetRecommendationsRequest = {}
    if campaign_arn is not None:
        input_["campaign_arn"] = campaign_arn
    if item_id is not None:
        input_["item_id"] = item_id
    if user_id is not None:
        input_["user_id"] = user_id
    if num_results is not None:
        input_["num_results"] = num_results
    if context is not None:
        input_["context"] = context
    if filter_arn is not None:
        input_["filter_arn"] = filter_arn
    if filter_values is not None:
        input_["filter_values"] = filter_values
    if recommender_arn is not None:
        input_["recommender_arn"] = recommender_arn
    if promotions is not None:
        input_["promotions"] = promotions
    if metadata_columns is not None:
        input_["metadata_columns"] = metadata_columns

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output