# Reranking - quickstart

> A quickstart guide for performing reranking with Cohere's Reranking models (v2 API).

Cohere's reranking models are available via the Rerank endpoint. This endpoint provides a powerful semantic boost to the search quality of any keyword or vector search system.

This quickstart guide shows you how to perform reranking with the Rerank endpoint.

<Steps>
  ### Setup

  First, install the Cohere Python SDK with the following command.

  ```bash
  pip install -U cohere
  ```

  Next, import the library and create a client.

  <Tabs>
    <Tab title="Cohere Platform">
      ```python PYTHON
      import cohere

      co = cohere.ClientV2(
          "COHERE_API_KEY"
      )  # Get your free API key here: https://dashboard.cohere.com/api-keys
      ```
    </Tab>

    <Tab title="Private Deployment">
      ```python PYTHON
      import cohere

      co = cohere.ClientV2(
          api_key="",  # Leave this blank
          base_url="<YOUR_DEPLOYMENT_URL>",
      )
      ```
    </Tab>

    <Tab title="Bedrock">
      ```python PYTHON
      import cohere

      co = cohere.BedrockClientV2(
          aws_region="AWS_REGION",
          aws_access_key="AWS_ACCESS_KEY_ID",
          aws_secret_key="AWS_SECRET_ACCESS_KEY",
          aws_session_token="AWS_SESSION_TOKEN",
      )

      # Get the model name: https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html
      ```
    </Tab>

    <Tab title="SageMaker">
      ```python PYTHON
      import cohere

      co = cohere.SagemakerClientV2(
          aws_region="AWS_REGION",
          aws_access_key="AWS_ACCESS_KEY_ID",
          aws_secret_key="AWS_SECRET_ACCESS_KEY",
          aws_session_token="AWS_SESSION_TOKEN",
      )
      ```
    </Tab>

    <Tab title="Azure AI">
      ```python PYTHON
      import cohere

      co = cohere.ClientV2(
          api_key="AZURE_API_KEY",
          base_url="AZURE_ENDPOINT",
      )
      ```
    </Tab>
  </Tabs>

  ### Retrieved Documents

  First, define the list of documents to be reranked.

  ```python PYTHON
  documents = [
      "Reimbursing Travel Expenses: Easily manage your travel expenses by submitting them through our finance tool. Approvals are prompt and straightforward.",
      "Working from Abroad: Working remotely from another country is possible. Simply coordinate with your manager and ensure your availability during core hours.",
      "Health and Wellness Benefits: We care about your well-being and offer gym memberships, on-site yoga classes, and comprehensive health insurance.",
      "Performance Reviews Frequency: We conduct informal check-ins every quarter and formal performance reviews twice a year.",
  ]
  ```

  ### Reranking

  Then, perform reranking by passing the documents and the user query to the Rerank endpoint.

  <Tabs>
    <Tab title="Cohere Platform">
      ```python PYTHON
      # Add the user query
      query = "Are there fitness-related perks?"

      # Rerank the documents
      results = co.rerank(
          model="rerank-v4.0-pro", query=query, documents=documents, top_n=2
      )

      for result in results.results:
          print(result)
      ```
    </Tab>

    <Tab title="Private Deployment">
      ```python PYTHON
      # Add the user query
      query = "Are there fitness-related perks?"

      # Rerank the documents
      results = co.rerank(
          model="rerank-v4.0-pro", query=query, documents=documents, top_n=2
      )

      for result in results.results:
          print(result)
      ```
    </Tab>

    <Tab title="Bedrock">
      ```python PYTHON
      # Add the user query
      query = "Are there fitness-related perks?"

      # Rerank the documents
      results = co.rerank(
          model="YOUR_MODEL_NAME", query=query, documents=documents, top_n=2
      )

      for result in results.results:
          print(result)
      ```
    </Tab>

    <Tab title="SageMaker">
      ```python PYTHON
      # Add the user query
      query = "Are there fitness-related perks?"

      # Rerank the documents
      results = co.rerank(
          model="YOUR_ENDPOINT_NAME",
          query=query,
          documents=documents,
          top_n=2,
      )

      for result in results.results:
          print(result)
      ```
    </Tab>

    <Tab title="Azure AI">
      ```python PYTHON
      # Add the user query
      query = "Are there fitness-related perks?"

      # Rerank the documents
      results = co.rerank(
          model="model",  # Pass a dummy string
          query=query,
          documents=documents,
          top_n=2,
      )

      for result in results.results:
          print(result)
      ```
    </Tab>
  </Tabs>

  ```mdx wordWrap
  document=None index=2 relevance_score=0.115670934
  document=None index=1 relevance_score=0.01729751
  ```
</Steps>

## Further Resources

* [Rerank endpoint API reference](https://docs.cohere.com/reference/rerank)
* [Documentation on reranking](https://docs.cohere.com/docs/rerank-overview)
* [LLM University chapter on reranking](https://cohere.com/llmu/reranking)