:doc:`AgentsforBedrockRuntime <../../bedrock-agent-runtime>` / Client / rerank

******
rerank
******



.. py:method:: 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 <https://docs.aws.amazon.com/bedrock/latest/userguide/rerank.html>`__.

  

  See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/bedrock-agent-runtime-2023-07-26/Rerank>`_  


  **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'
            },
        ]
    )
    
  :type nextToken: string
  :param nextToken: 

    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.

    

  
  :type queries: list
  :param queries: **[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.

        

      
    

  :type rerankingConfiguration: dict
  :param rerankingConfiguration: **[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) --* 

          
            - (:ref:`document<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.

      

    
  
  :type sources: list
  :param sources: **[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** (:ref:`document<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.

        

      
    

  
  :rtype: 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** (:ref:`document<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 original index of the document from the input sources array.

            
          

          - **relevanceScore** *(float) --* 

            The relevance score of the document.

            
      
    
  
  **Exceptions**
  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.ResourceNotFoundException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.ConflictException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.ValidationException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.InternalServerException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.DependencyFailedException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.BadGatewayException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.ThrottlingException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.AccessDeniedException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.ServiceQuotaExceededException`

  