> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portkey.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Rerank

> Rerank documents with Google Vertex AI

Portkey exposes Google Vertex AI's [Discovery Engine ranking API](https://cloud.google.com/generative-ai-app-builder/docs/ranking) through the unified `/v1/rerank` endpoint.

<Note>
  Enable the **Discovery Engine API** on the GCP project backing your Vertex AI provider before making rerank requests.
</Note>

## Supported Models

* `semantic-ranker-default@latest` (default)
* `semantic-ranker-fast@latest`
* `semantic-ranker-512@latest`
* Specific versions: `semantic-ranker-default-004`, `semantic-ranker-fast-004`, `semantic-ranker-default-003`, `semantic-ranker-default-002`

## Rerank documents

<CodeGroup>
  ```sh cURL theme={"system"}
  curl --location 'https://api.portkey.ai/v1/rerank' \
  --header 'x-portkey-api-key: $PORTKEY_API_KEY' \
  --header 'x-portkey-provider: @VERTEX_AI_PROVIDER_SLUG' \
  --header 'Content-Type: application/json' \
  --data '{
      "model": "semantic-ranker-default@latest",
      "query": "What is the capital of the United States?",
      "top_n": 3,
      "documents": [
          "Carson City is the capital city of the American state of Nevada.",
          "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
          "Washington, D.C. is the capital of the United States.",
          "Capitalization is the use of a capital letter at the start of a word."
      ]
  }'
  ```

  ```python Python theme={"system"}
  from portkey_ai import Portkey

  client = Portkey(
      api_key="PORTKEY_API_KEY",
      provider="@VERTEX_AI_PROVIDER_SLUG"
  )

  result = client.post(
      "/rerank",
      model="semantic-ranker-default@latest",
      query="What is the capital of the United States?",
      top_n=3,
      documents=[
          "Carson City is the capital city of the American state of Nevada.",
          "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
          "Washington, D.C. is the capital of the United States.",
          "Capitalization is the use of a capital letter at the start of a word."
      ]
  )

  print(result)
  ```

  ```javascript NodeJS theme={"system"}
  import Portkey from 'portkey-ai';

  const portkey = new Portkey({
      apiKey: "PORTKEY_API_KEY",
      provider: "@VERTEX_AI_PROVIDER_SLUG"
  });

  const result = await portkey.post('/rerank', {
      model: "semantic-ranker-default@latest",
      query: "What is the capital of the United States?",
      top_n: 3,
      documents: [
          "Carson City is the capital city of the American state of Nevada.",
          "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
          "Washington, D.C. is the capital of the United States.",
          "Capitalization is the use of a capital letter at the start of a word."
      ]
  });

  console.log(result);
  ```
</CodeGroup>

## Parameters

| Parameter          | Type                   | Required | Description                                                                |
| ------------------ | ---------------------- | -------- | -------------------------------------------------------------------------- |
| `model`            | string                 | Yes      | Ranking model to use (see supported models)                                |
| `query`            | string                 | Yes      | Query against which documents are ranked                                   |
| `documents`        | string\[] \| object\[] | Yes      | Documents to rank. Accepts strings or `{ text, title? }` objects (max 200) |
| `top_n`            | integer                | No       | Number of top results to return. Omit to return all                        |
| `return_documents` | boolean                | No       | Set to `false` to receive only IDs and scores (default `true`)             |

## Related Resources

<Card title="Google Vertex AI Ranking API" href="https://cloud.google.com/generative-ai-app-builder/docs/ranking">
  Official documentation for the Vertex AI Discovery Engine ranking API.
</Card>
