RerankCommand

Reranks the relevance of sources based on queries. For more information, see Improve the relevance of query responses with a reranker model .

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { BedrockAgentRuntimeClient, RerankCommand } from "@aws-sdk/client-bedrock-agent-runtime"; // ES Modules import
// const { BedrockAgentRuntimeClient, RerankCommand } = require("@aws-sdk/client-bedrock-agent-runtime"); // CommonJS import
const client = new BedrockAgentRuntimeClient(config);
const input = { // RerankRequest
  queries: [ // RerankQueriesList // required
    { // RerankQuery
      type: "TEXT", // required
      textQuery: { // RerankTextDocument
        text: "STRING_VALUE",
      },
    },
  ],
  sources: [ // RerankSourcesList // required
    { // RerankSource
      type: "INLINE", // required
      inlineDocumentSource: { // RerankDocument
        type: "TEXT" || "JSON", // required
        textDocument: {
          text: "STRING_VALUE",
        },
        jsonDocument: "DOCUMENT_VALUE",
      },
    },
  ],
  rerankingConfiguration: { // RerankingConfiguration
    type: "BEDROCK_RERANKING_MODEL", // required
    bedrockRerankingConfiguration: { // BedrockRerankingConfiguration
      numberOfResults: Number("int"),
      modelConfiguration: { // BedrockRerankingModelConfiguration
        modelArn: "STRING_VALUE", // required
        additionalModelRequestFields: { // AdditionalModelRequestFields
          "<keys>": "DOCUMENT_VALUE",
        },
      },
    },
  },
  nextToken: "STRING_VALUE",
};
const command = new RerankCommand(input);
const response = await client.send(command);
// { // RerankResponse
//   results: [ // RerankResultsList // required
//     { // RerankResult
//       index: Number("int"), // required
//       relevanceScore: Number("float"), // required
//       document: { // RerankDocument
//         type: "TEXT" || "JSON", // required
//         textDocument: { // RerankTextDocument
//           text: "STRING_VALUE",
//         },
//         jsonDocument: "DOCUMENT_VALUE",
//       },
//     },
//   ],
//   nextToken: "STRING_VALUE",
// };

RerankCommand Input

See RerankCommandInput for more details

Parameter
Type
Description
queries
Required
RerankQuery[] | undefined

An array of objects, each of which contains information about a query to submit to the reranker model.

rerankingConfiguration
Required
RerankingConfiguration | undefined

Contains configurations for reranking.

sources
Required
RerankSource[] | undefined

An array of objects, each of which contains information about the sources to rerank.

nextToken
string | undefined

If the total number of results was greater than could fit in a response, a token is returned in the nextToken field. You can enter that token in this field to return the next batch of results.

RerankCommand Output

See RerankCommandOutput for details

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.
results
Required
RerankResult[] | undefined

An array of objects, each of which contains information about the results of reranking.

nextToken
string | undefined

If the total number of results is greater than can fit in the response, use this token in the nextToken field when making another request to return the next batch of results.

Throws

Name
Fault
Details
AccessDeniedException
client

The request is denied because of missing access permissions. Check your permissions and retry your request.

BadGatewayException
server

There was an issue with a dependency due to a server issue. Retry your request.

ConflictException
client

There was a conflict performing an operation. Resolve the conflict and retry your request.

DependencyFailedException
client

There was an issue with a dependency. Check the resource configurations and retry the request.

InternalServerException
server

An internal server error occurred. Retry your request.

ResourceNotFoundException
client

The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.

ServiceQuotaExceededException
client

The number of requests exceeds the service quota. Resubmit your request later.

ThrottlingException
client

The number of requests exceeds the limit. Resubmit your request later.

ValidationException
client

Input validation failed. Check your request parameters and retry the request.

BedrockAgentRuntimeServiceException
Base exception class for all service exceptions from BedrockAgentRuntime service.