選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

語義上對搜索服務的結果進行排名 - Amazon Kendra

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

語義上對搜索服務的結果進行排名

Amazon Kendra 智能排名使用 Amazon Kendra的語義搜索功能來重新排名搜索服務的結果。它會考慮到搜尋查詢的前後關聯,以及搜尋服務文件中的所有可用資訊來達成此目的。 Amazon Kendra 智能排名可以改善簡單的關鍵字匹配。

CreateRescoreExecutionPlanAPI 會建立用於佈建重新分數 API 的 Amazon Kendra 智慧排名資源。RescoreAPI 會重新排列搜尋服務的搜尋結果,例如 OpenSearch (自我管理)

打電話時CreateRescoreExecutionPlan,您可以設定所需的容量單位,以重新排名搜尋服務的結果。如果您不需要超出單一單位預設值的更多容量單位,請勿變更預設值。僅提供重新評分執行計劃的名稱。您最多可以設置 1000 個額外單位。如需單一容量單位所包含項目的資訊,請參閱調整容量。佈建 Amazon Kendra 智慧排名後,系統會根據您設定的容量單位,每小時向您收取費用。請參閱免費方案和定價資訊

重新評分執行計劃 ID 會產生,並在您呼叫CreateRescoreExecutionPlan時傳回回應中。RescoreAPI 會使用重新評分執行計畫 ID,使用您設定的容量來重新排名搜尋服務的結果。您可以在搜尋服務的組態檔案中包含重新評分執行計畫 ID。例如,如果您使用 OpenSearch (自我管理),您可以將重新評分執行計劃識別碼納入您的碼頭組成 .yml 或 opensearch.yml 檔案中 — 請參閱智慧排名 (自助服務) 結果。 OpenSearch

當您調CreateRescoreExecutionPlan用 Amazon 資源名稱(ARN)也會在響應中生成。您可以使用此 ARN 在 AWS Identity and Access Management (IAM) 中建立權限原則,以限制使用者對特定重新評分執行計畫之特定 ARN 的存取。如需授與針對特定重新評分執行計畫使用 Rescore API 之權限的 IAM 原則範例,請參閱自我 OpenSearch管理的Amazon Kendra 智慧排名

以下是建立容量單位設為 1 的重新評分執行計畫的範例。

CLI
aws kendra-ranking create-rescore-execution-plan \ --name MyRescoreExecutionPlan \ --capacity-units '{"RescoreCapacityUnits":1}' Response: { "Id": "<rescore execution plan ID>", "Arn": "arn:aws:kendra-ranking:<region>:<account-id>:rescore-execution-plan/<rescore-execution-plan-id>" }
Python
import boto3 from botocore.exceptions import ClientError import pprint import time kendra_ranking = boto3.client("kendra-ranking") print("Create a rescore execution plan.") # Provide a name for the rescore execution plan name = "MyRescoreExecutionPlan" # Set your required additional capacity units # Don't set capacity units if you don't require more than 1 unit given by default capacity_units = 1 try: rescore_execution_plan_response = kendra_ranking.create_rescore_execution_plan( Name = name, CapacityUnits = {"RescoreCapacityUnits":capacity_units} ) pprint.pprint(rescore_execution_plan_response) rescore_execution_plan_id = rescore_execution_plan_response["Id"] print("Wait for Amazon Kendra to create the rescore execution plan.") while True: # Get the details of the rescore execution plan, such as the status rescore_execution_plan_description = kendra_ranking.describe_rescore_execution_plan( Id = rescore_execution_plan_id ) # When status is not CREATING quit. status = rescore_execution_plan_description["Status"] print(" Creating rescore execution plan. Status: "+status) time.sleep(60) if status != "CREATING": break except ClientError as e: print("%s" % e) print("Program ends.")
Java
import java.util.concurrent.TimeUnit; import software.amazon.awssdk.services.kendraranking.KendraRankingClient; import software.amazon.awssdk.services.kendraranking.model.CapacityUnitsConfiguration; import software.amazon.awssdk.services.kendraranking.model.CreateRescoreExecutionPlanRequest; import software.amazon.awssdk.services.kendraranking.model.CreateRescoreExecutionPlanResponse; import software.amazon.awssdk.services.kendraranking.model.DescribeRescoreExecutionPlanRequest; import software.amazon.awssdk.services.kendraranking.model.DescribeRescoreExecutionPlanResponse; import software.amazon.awssdk.services.kendraranking.model.RescoreExecutionPlanStatus; public class CreateRescoreExecutionPlanExample { public static void main(String[] args) throws InterruptedException { String rescoreExecutionPlanName = "MyRescoreExecutionPlan"; int capacityUnits = 1; KendraRankingClient kendraRankingClient = KendraRankingClient.builder().build(); System.out.println(String.format("Creating a rescore execution plan named %s", rescoreExecutionPlanName)); CreateRescoreExecutionPlanResponse createResponse = kendraRankingClient.createRescoreExecutionPlan( CreateRescoreExecutionPlanRequest.builder() .name(rescoreExecutionPlanName) .capacityUnits( CapacityUnitsConfiguration.builder() .rescoreCapacityUnits(capacityUnits) .build() ) .build() ); String rescoreExecutionPlanId = createResponse.id(); System.out.println(String.format("Waiting for rescore execution plan with id %s to finish creating.", rescoreExecutionPlanId)); while (true) { DescribeRescoreExecutionPlanResponse describeResponse = kendraRankingClient.describeRescoreExecutionPlan( DescribeRescoreExecutionPlanRequest.builder() .id(rescoreExecutionPlanId) .build() ); RescoreExecutionPlanStatus rescoreExecutionPlanStatus = describeResponse.status(); if (rescoreExecutionPlanStatus != RescoreExecutionPlanStatus.CREATING) { break; } TimeUnit.SECONDS.sleep(60); } System.out.println("Rescore execution plan creation is complete."); } }
aws kendra-ranking create-rescore-execution-plan \ --name MyRescoreExecutionPlan \ --capacity-units '{"RescoreCapacityUnits":1}' Response: { "Id": "<rescore execution plan ID>", "Arn": "arn:aws:kendra-ranking:<region>:<account-id>:rescore-execution-plan/<rescore-execution-plan-id>" }

以下是更新重新評分執行計畫以將容量單位設定為 2 的範例。

CLI
aws kendra-ranking update-rescore-execution-plan \ --id <rescore execution plan ID> \ --capacity-units '{"RescoreCapacityUnits":2}'
Python
import boto3 from botocore.exceptions import ClientError import pprint import time kendra_ranking = boto3.client("kendra-ranking") print("Update a rescore execution plan.") # Provide the ID of the rescore execution plan id = <rescore execution plan ID> # Re-set your required additional capacity units capacity_units = 2 try: kendra_ranking.update_rescore_execution_plan( Id = id, CapacityUnits = {"RescoreCapacityUnits":capacity_units} ) print("Wait for Amazon Kendra to update the rescore execution plan.") while True: # Get the details of the rescore execution plan, such as the status rescore_execution_plan_description = kendra_ranking.describe_rescore_execution_plan( Id = id ) # When status is not UPDATING quit. status = rescore_execution_plan_description["Status"] print(" Updating rescore execution plan. Status: "+status) time.sleep(60) if status != "UPDATING": break except ClientError as e: print("%s" % e) print("Program ends.")
Java
import java.util.concurrent.TimeUnit; import software.amazon.awssdk.services.kendraranking.KendraRankingClient; import software.amazon.awssdk.services.kendraranking.model.CapacityUnitsConfiguration; import software.amazon.awssdk.services.kendraranking.model.DescribeRescoreExecutionPlanRequest; import software.amazon.awssdk.services.kendraranking.model.DescribeRescoreExecutionPlanResponse; import software.amazon.awssdk.services.kendraranking.model.RescoreExecutionPlanStatus; import software.amazon.awssdk.services.kendraranking.model.UpdateRescoreExecutionPlanRequest; import software.amazon.awssdk.services.kendraranking.model.UpdateRescoreExecutionPlanResponse; public class UpdateRescoreExecutionPlanExample { public static void main(String[] args) throws InterruptedException { String rescoreExecutionPlanId = <rescore execution plan ID>; int newCapacityUnits = 2; KendraRankingClient kendraRankingClient = KendraRankingClient.builder().build(); System.out.println(String.format("Updating a rescore execution plan named %s", rescoreExecutionPlanId)); UpdateRescoreExecutionPlanResponse updateResponse = kendraRankingClient.updateRescoreExecutionPlan( UpdateRescoreExecutionPlanRequest.builder() .id(rescoreExecutionPlanId) .capacityUnits( CapacityUnitsConfiguration.builder() .rescoreCapacityUnits(newCapacityUnits) .build() ) .build() ); System.out.println(String.format("Waiting for rescore execution plan with id %s to finish updating.", rescoreExecutionPlanId)); while (true) { DescribeRescoreExecutionPlanResponse describeResponse = kendraRankingClient.describeRescoreExecutionPlan( DescribeRescoreExecutionPlanRequest.builder() .id(rescoreExecutionPlanId) .build() ); RescoreExecutionPlanStatus rescoreExecutionPlanStatus = describeResponse.status(); if (rescoreExecutionPlanStatus != RescoreExecutionPlanStatus.UPDATING) { break; } TimeUnit.SECONDS.sleep(60); } System.out.println("Rescore execution plan update is complete."); } }
aws kendra-ranking update-rescore-execution-plan \ --id <rescore execution plan ID> \ --capacity-units '{"RescoreCapacityUnits":2}'

以下是使用 Rescore API 的範例。

CLI
aws kendra-ranking rescore \ --rescore-execution-plan-id <rescore execution plan ID> \ --search-query "intelligent systems" \ --documents "[{\"Id\": \"DocId1\",\"Title\": \"Smart systems\", \"Body\": \"intelligent systems in everyday life\",\"OriginalScore\": 2.0}, {\"Id\": \"DocId2\",\"Title\": \"Smarter systems\", \"Body\": \"living with intelligent systems\",\"OriginalScore\": 1.0}]"
Python
import boto3 from botocore.exceptions import ClientError import pprint kendra_ranking = boto3.client("kendra-ranking") print("Use the Rescore API.") # Provide the ID of the rescore execution plan id = <rescore execution plan ID> # The search query from the search service query = "intelligent systems" # The list of documents for Intelligent Ranking to rescore document_list = [ {"Id": "DocId1", "Title": "Smart systems", "Body": "intelligent systems in everyday life", "OriginalScore": 2.0}, {"Id": "DocId2", "Title": "Smarter systems", "Body": "living with intelligent systems", "OriginalScore": 1.0} ] try: rescore_response = kendra_ranking.rescore( rescore_execution_plan_id = id, search_query = query, documents = document_list ) print(rescore_response["RescoreId"]) print(rescore_resposne["ResultItems"]) except ClientError as e: print("%s" % e) print("Program ends.")
Java
import java.util.ArrayList; import java.util.List; import software.amazon.awssdk.services.kendraranking.KendraRankingClient; import software.amazon.awssdk.services.kendraranking.model.RescoreRequest; import software.amazon.awssdk.services.kendraranking.model.RescoreResponse; import software.amazon.awssdk.services.kendraranking.model.Document; public class RescoreExample { public static void main(String[] args) { String rescoreExecutionPlanId = <rescore execution plan ID>; String query = "intelligent systems"; List<Document> documentList = new ArrayList<>(); documentList.add( Document.builder() .id("DocId1") .originalScore(2.0F) .body("intelligent systems in everyday life") .title("Smart systems") .build() ); documentList.add( Document.builder() .id("DocId2") .originalScore(1.0F) .body("living with intelligent systems") .title("Smarter systems") .build() ); KendraRankingClient kendraRankingClient = KendraRankingClient.builder().build(); RescoreResponse rescoreResponse = kendraRankingClient.rescore( RescoreRequest.builder() .rescoreExecutionPlanId(rescoreExecutionPlanId) .searchQuery(query) .documents(documentList) .build() ); System.out.println(rescoreResponse.rescoreId()); System.out.println(rescoreResponse.resultItems()); } }
aws kendra-ranking rescore \ --rescore-execution-plan-id <rescore execution plan ID> \ --search-query "intelligent systems" \ --documents "[{\"Id\": \"DocId1\",\"Title\": \"Smart systems\", \"Body\": \"intelligent systems in everyday life\",\"OriginalScore\": 2.0}, {\"Id\": \"DocId2\",\"Title\": \"Smarter systems\", \"Body\": \"living with intelligent systems\",\"OriginalScore\": 1.0}]"
隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。