Use a reranker model in Amazon Bedrock - Amazon Bedrock

Use a reranker model in Amazon Bedrock

You can use a reranker model directly or while retrieving results during knowledge base query. Choose the tab for your preferred method, and then follow the steps:

Console

You can't use a reranker model directly in the AWS Management Console, but you can use a reranker model when querying your knowledge base by doing the following:

  1. When you query a knowledge base, open up the Configurations pane by choosing the icon.

  2. Expand the Reranking section.

  3. Choose Select model and select a reranker model.

  4. If your Amazon Bedrock Knowledge Bases service role is missing permissions to use the reranker model, select Update service role to modify the role with the proper permissions.

  5. (Optional) In the Additional Reranking options section, modify any options that you need to.

  6. Enter a prompt and select Run. The response is the result after applying the reranker model.

For more detailed instructions about carrying out knowledge base query, see Query a knowledge base and retrieve data and Query a knowledge base and generate responses based off the retrieved data.

API

For instructions on using a reranker model during knowledge base query, see Query a knowledge base and retrieve data and Query a knowledge base and generate responses based off the retrieved data.

To use a reranker model directly with the Amazon Bedrock API, send a Rerank request with an Agents for Amazon Bedrock runtime endpoint.

The following fields are required:

Field Basic description
queries An array of one RerankQuery object. Specify TEXT as the type and include the query in the textQuery field.
sources An array of RerankSource objects to submit to the reranking model. For each RerankSource, specify INLINE as the type and include a RerankDocument object in the inlineDocumentSource field. See below for details about RerankDocument.
rerankingConfiguration Includes the Amazon Resource Name (ARN) of the reranking model to use, and the number of results to return after reranking, and, optionally, inference configurations for the model. You specify additional model configurations as key-value pairs. For more information, see Rerank on the Cohere documentation website.

The following fields are optional:

Field Use case
nextToken A token returned in a previous response that you can include to provide the next batch of results.

The format of the RerankSource object that you include depends on the format of the document. To see the format for different RerankSource types, choose the tab that corresponds to the format of the document:

StringJSON object
String

If the document is a string, then specify the value of the type field of the RerankDocument object as TEXT and include the document in the text field. For example:

{ "inlineDocumentSource": { "textDocument": { "text": "string" }, "type": "TEXT" }, "type": "INLINE" }
JSON object

If the document is a JSON object, then specify the value of the type field in the RerankDocument object as JSON and include the document in the jsonDocument field. For example:

{ "inlineDocumentSource": { "jsonDocument": JSON value, "type": "JSON" }, "type": "INLINE" }

The response to your Rerank request returns a list of RerankResult objects in the results field. Each object contains the following fields:

  • document – Includes information about the document that you submitted.

  • relevanceScore – A relevance score for the document, assigned by the reranking model.

  • index – Indicates the document's ranking relative to the other documents in the list. The lower the score, the higher the ranking.

If there are too many results to display, then the response returns a value in the nextToken field. In this case, to see the next batch of results, include that token in a subsequent request.