Use a reranker model in Amazon Bedrock
You can use a reranker model directly or while retrieving results during knowledge base query. 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.
Note
You can't use a reranker model directly in the AWS Management Console, but you can use a reranker model in a Retrieve or RetrieveAndGenerate workflow in the console by opening up the Configurations pane.
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 |
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 use case. To see the format for different RerankSource
types, expand the section that corresponds to your use case:
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" }
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.