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)
-
You can use the following example code with the required values:
-
index id
—The ID of the index that the query applies to. -
query id
—The query that you want to provide feedback on. -
result id
—The ID of the query result that you want to provide feedback on. The query response contains the result ID. -
relevance value
—EitherRELEVANT
(the query result is relevant) orNOT_RELEVANT
(the query result is not relevant).
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)
-
-
Run the code. After the feedback has been submitted, the code displays a message.