Using the Amazon Kendra API to submit feedback - Amazon Kendra

Using the Amazon Kendra API to submit feedback

To use the Amazon Kendra API to submit query feedback, use the SubmitFeedback API. To identify the query, you supply the index ID of the index that the query applies to, and the query ID returned in the response from the Query API.

The following example shows how to submit click and relevance feedback using the Amazon Kendra API. You can submit multiple sets of feedback through the ClickFeedbackItems and RelevanceFeedbackItems arrays. This example submits a single click and a single relevance feedback item. The feedback submittal uses the current time.

To submit feedback for a search (AWS SDK)
  1. You can use the following example code with the required values:

    1. index id—The ID of the index that the query applies to.

    2. query id—The query that you want to provide feedback on.

    3. result id—The ID of the query result that you want to provide feedback on. The query response contains the result ID.

    4. relevance value—Either RELEVANT (the query result is relevant) or NOT_RELEVANT (the query result is not relevant).

    Python
    import boto3 import time kendra = boto3.client("kendra") # Provide the index ID index_id = "index-id" # Provide the query ID query_id = "query-id" # Provide the search result ID result_id = "result-id" # Configure the feedback item feedback_item = {"ClickTime": int(time.time()), "ResultId":result_id} # Configure the relevance value relevance_value = "RELEVANT" relevance_item = {"RelevanceValue": relevance_value, "ResultId": result_id } response = kendra.submit_feedback( QueryId = query_id, IndexId = index_id, ClickFeedbackItems = [feedback_item], RelevanceFeedbackItems = [relevance_item] ) print("Submitted feedback for query: " + query_id)
    Java
    package com.amazonaws.kendra; import java.time.Instant; import software.amazon.awssdk.services.kendra.KendraClient; import software.amazon.awssdk.services.kendra.model.ClickFeedback; import software.amazon.awssdk.services.kendra.model.RelevanceFeedback; import software.amazon.awssdk.services.kendra.model.RelevanceType; import software.amazon.awssdk.services.kendra.model.SubmitFeedbackRequest; import software.amazon.awssdk.services.kendra.model.SubmitFeedbackResponse; public class SubmitFeedbackExample { public static void main(String[] args) { KendraClient kendra = KendraClient.builder().build(); SubmitFeedbackRequest submitFeedbackRequest = SubmitFeedbackRequest .builder() .indexId("IndexId") .queryId("QueryId") .clickFeedbackItems( ClickFeedback .builder() .clickTime(Instant.now()) .resultId("ResultId") .build()) .relevanceFeedbackItems( RelevanceFeedback .builder() .relevanceValue(RelevanceType.RELEVANT) .resultId("ResultId") .build()) .build(); SubmitFeedbackResponse response = kendra.submitFeedback(submitFeedbackRequest); System.out.println("Feedback is submitted"); } }
  2. Run the code. After the feedback has been submitted, the code displays a message.