AgentsforBedrockRuntime / Client / rerank

rerank#

AgentsforBedrockRuntime.Client.rerank(**kwargs)#

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

See also: AWS API Documentation

Request Syntax

response = client.rerank(
    nextToken='string',
    queries=[
        {
            'textQuery': {
                'text': 'string'
            },
            'type': 'TEXT'
        },
    ],
    rerankingConfiguration={
        'bedrockRerankingConfiguration': {
            'modelConfiguration': {
                'additionalModelRequestFields': {
                    'string': {...}|[...]|123|123.4|'string'|True|None
                },
                'modelArn': 'string'
            },
            'numberOfResults': 123
        },
        'type': 'BEDROCK_RERANKING_MODEL'
    },
    sources=[
        {
            'inlineDocumentSource': {
                'jsonDocument': {...}|[...]|123|123.4|'string'|True|None,
                'textDocument': {
                    'text': 'string'
                },
                'type': 'TEXT'|'JSON'
            },
            'type': 'INLINE'
        },
    ]
)
Parameters:
  • nextToken (string) – 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.

  • queries (list) –

    [REQUIRED]

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

    • (dict) –

      Contains information about a query to submit to the reranker model.

      • textQuery (dict) – [REQUIRED]

        Contains information about a text query.

        • text (string) –

          The text of the document.

      • type (string) – [REQUIRED]

        The type of the query.

  • rerankingConfiguration (dict) –

    [REQUIRED]

    Contains configurations for reranking.

    • bedrockRerankingConfiguration (dict) – [REQUIRED]

      Contains configurations for an Amazon Bedrock reranker.

      • modelConfiguration (dict) – [REQUIRED]

        Contains configurations for a reranker model.

        • additionalModelRequestFields (dict) –

          A JSON object whose keys are request fields for the model and whose values are values for those fields.

          • (string) –

            • (document) –

        • modelArn (string) – [REQUIRED]

          The ARN of the reranker model.

      • numberOfResults (integer) –

        The number of results to return after reranking.

    • type (string) – [REQUIRED]

      The type of reranker that the configurations apply to.

  • sources (list) –

    [REQUIRED]

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

    • (dict) –

      Contains information about a source for reranking.

      • inlineDocumentSource (dict) – [REQUIRED]

        Contains an inline definition of a source for reranking.

        • jsonDocument (document) –

          Contains a JSON document to rerank.

        • textDocument (dict) –

          Contains information about a text document to rerank.

          • text (string) –

            The text of the document.

        • type (string) – [REQUIRED]

          The type of document to rerank.

      • type (string) – [REQUIRED]

        The type of the source.

Return type:

dict

Returns:

Response Syntax

{
    'nextToken': 'string',
    'results': [
        {
            'document': {
                'jsonDocument': {...}|[...]|123|123.4|'string'|True|None,
                'textDocument': {
                    'text': 'string'
                },
                'type': 'TEXT'|'JSON'
            },
            'index': 123,
            'relevanceScore': ...
        },
    ]
}

Response Structure

  • (dict) –

    • nextToken (string) –

      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.

    • results (list) –

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

      • (dict) –

        Contains information about a document that was reranked.

        • document (dict) –

          Contains information about the document.

          • jsonDocument (document) –

            Contains a JSON document to rerank.

          • textDocument (dict) –

            Contains information about a text document to rerank.

            • text (string) –

              The text of the document.

          • type (string) –

            The type of document to rerank.

        • index (integer) –

          The ranking of the document. The lower a number, the higher the document is ranked.

        • relevanceScore (float) –

          The relevance score of the document.

Exceptions

  • AgentsforBedrockRuntime.Client.exceptions.ConflictException

  • AgentsforBedrockRuntime.Client.exceptions.ResourceNotFoundException

  • AgentsforBedrockRuntime.Client.exceptions.ValidationException

  • AgentsforBedrockRuntime.Client.exceptions.InternalServerException

  • AgentsforBedrockRuntime.Client.exceptions.DependencyFailedException

  • AgentsforBedrockRuntime.Client.exceptions.BadGatewayException

  • AgentsforBedrockRuntime.Client.exceptions.ThrottlingException

  • AgentsforBedrockRuntime.Client.exceptions.AccessDeniedException

  • AgentsforBedrockRuntime.Client.exceptions.ServiceQuotaExceededException