> ## 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.

## 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

```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);
```

## 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] [Google Vertex AI Ranking API](https://cloud.google.com/generative-ai-app-builder/docs/ranking)
>
> Official documentation for the Vertex AI Discovery Engine ranking API.

***

> [card] [Portkey is now PRISMA AIRS AI Gateway. See it in action.](https://www.paloaltonetworks.in/ai-security/ai-gateway?utm_source=portkey\&utm_medium=referral\&utm_campaign=prisma_airs\&utm_content=docs_nav#contact)
>
> Contact Us


## Related topics

- [Rerank](https://docs.portkey.ai/docs/api-reference/inference-api/rerank.md)
- [Azure AI Foundry](https://docs.portkey.ai/docs/integrations/llms/azure-foundry.md)
- [Jina AI](https://docs.portkey.ai/docs/integrations/llms/jina-ai.md)
- [Voyage AI](https://docs.portkey.ai/docs/integrations/llms/voyage-ai.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.