---
title: "Locally Hosted Transformers Reranker Models with Weaviate"
description: "Enhance search results with the transformers reranker module in Weaviate."
url: https://docs.weaviate.io/weaviate/model-providers/transformers/reranker
---

# Locally Hosted Transformers Reranker Models with Weaviate

Weaviate's integration with the Hugging Face Transformers library allows you to access their models' capabilities directly from Weaviate.

[Configure a Weaviate collection](https://docs.weaviate.io/weaviate/model-providers/transformers/reranker#configure-the-reranker) to use Transformers integration, and [configure the Weaviate instance](https://docs.weaviate.io/weaviate/model-providers/transformers/reranker#weaviate-configuration) with a model image, and Weaviate will use the specified model in the Transformers inference container to rerank search results.

This two-step process involves Weaviate first performing a search and then reranking the results using the specified model.

![Reranker integration illustration](https://docs.weaviate.io/assets/images/integration_transformers_reranker-561b5715db271420c427585533366830.png)

## Requirements

### Weaviate configuration

Your Weaviate instance must be configured with the Transformers reranker integration (`reranker-transformers`) module.

**For Weaviate Cloud (WCD) users**

This integration is not available for Weaviate Cloud (WCD) instances, as it requires spinning up a container with the Hugging Face model.

#### Enable the integration module

- Check the [cluster metadata](https://docs.weaviate.io/deploy/configuration/status#cluster-metadata) to verify if the module is enabled.
- Follow the [how-to configure modules](https://docs.weaviate.io/weaviate/configuration/modules) guide to enable the module in Weaviate.

#### Configure the integration

To use this integration, configure the container image of the Hugging Face Transformers model and the inference endpoint of the containerized model.

The following example shows how to configure the Hugging Face Transformers integration in Weaviate:

#### Docker

#### Docker Option 1: Use a pre-configured `docker-compose.yml` file

Follow the instructions on the [Weaviate Docker installation configurator](https://docs.weaviate.io/deploy/installation-guides/docker-installation#configurator) to download a pre-configured `docker-compose.yml` file with a selected model



#### Docker Option 2: Add the configuration manually

Alternatively, add the configuration to the `docker-compose.yml` file manually as in the example below.

```yaml
services:
  weaviate:
    # Other Weaviate configuration
    environment:
      ENABLE_MODULES: reranker-transformers # Enable this module
      RERANKER_INFERENCE_API: http://reranker-transformers:8080  # Set the inference API endpoint
  reranker-transformers:  # Set the name of the inference container
    image: cr.weaviate.io/semitechnologies/reranker-transformers:cross-encoder-ms-marco-MiniLM-L-6-v2
    environment:
      ENABLE_CUDA: 0  # Set to 1 to enable
```

- `RERANKER_INFERENCE_API` environment variable sets the inference API endpoint
- `reranker-transformers` is the name of the inference container
- `image` is the container image
- `ENABLE_CUDA` environment variable enables GPU usage

Set `image` from a [list of available models](https://docs.weaviate.io/weaviate/model-providers/transformers/reranker#available-models) to specify a particular model to be used.

#### Kubernetes

Configure the Hugging Face Transformers integration in Weaviate by adding or updating the `reranker-transformers` module in the `modules` section of the Weaviate Helm chart values file. For example, modify the `values.yaml` file as follows:

```yaml
modules:

  reranker-transformers:

    enabled: true
    tag: cross-encoder-ms-marco-MiniLM-L-6-v2
    repo: semitechnologies/reranker-transformers
    registry: cr.weaviate.io
    envconfig:
      enable_cuda: true
```

See the [Weaviate Helm chart](https://github.com/weaviate/weaviate-helm/blob/master/weaviate/values.yaml) for an example of the `values.yaml` file including more configuration options.

Set `tag` from a [list of available models](https://docs.weaviate.io/weaviate/model-providers/transformers/reranker#available-models) to specify a particular model to be used.

### Credentials

As this integration runs a local container with the transformers model, no additional credentials (e.g. API key) are required. Connect to Weaviate as usual, such as in the examples below.

**Python**

```py
import weaviate
from weaviate.classes.init import Auth
import os

headers = {
}

client = weaviate.connect_to_weaviate_cloud(
    cluster_url=weaviate_url,                       # `weaviate_url`: your Weaviate URL
    auth_credentials=Auth.api_key(weaviate_key),      # `weaviate_key`: your Weaviate API key
    headers=headers
)

# Work with Weaviate

client.close()
```

**JavaScript/TypeScript**

```ts
import weaviate from '@weaviate/node'


const client = await weaviate.connectToWeaviateCloud(
  'WEAVIATE_INSTANCE_URL',  // Replace with your instance URL
  {
    authCredentials: new weaviate.ApiKey('WEAVIATE_INSTANCE_API_KEY'),
    headers: {
    }
  }
)

// Work with Weaviate

client.close()
```

## Configure the reranker

> [!NOTE]
>
> **Reranker model integration mutable from `v1.25.23`, `v1.26.8` and `v1.27.1`**
>
> A collection's `reranker` model integration configuration is mutable from `v1.25.23`, `v1.26.8` and `v1.27.1`. See [this section](https://docs.weaviate.io/weaviate/manage-collections/generative-reranker-models#update-the-reranker-model-integration) for details on how to update the collection configuration.

Configure a Weaviate collection to use a Transformer reranker model as follows:

**Python**

```py
from weaviate.classes.config import Configure

client.collections.create(
    "DemoCollection",
    reranker_config=Configure.Reranker.transformers()
    # Additional parameters not shown
)
```

**JavaScript/TypeScript**

```ts
await client.collections.create({
  name: 'DemoCollection',
  reranker: weaviate.configure.reranker.transformers(),
});
```

> [!NOTE]
>
> **Choose a container image to select a model**
>
> To choose a model, select the [container image](https://docs.weaviate.io/weaviate/model-providers/transformers/reranker#configure-the-integration) that hosts it.

## Reranking query

Once the reranker is configured, Weaviate performs [reranking operations](https://docs.weaviate.io/weaviate/search/rerank) using the specified reranker model.

More specifically, Weaviate performs an initial search, then reranks the results using the specified model.

Any search in Weaviate can be combined with a reranker to perform reranking operations.

![Reranker integration illustration](https://docs.weaviate.io/assets/images/integration_transformers_reranker-561b5715db271420c427585533366830.png)

**Python**

```py
from weaviate.classes.query import Rerank

collection = client.collections.use("DemoCollection")

response = collection.query.near_text(
    query="A holiday film",  # The model provider integration will automatically vectorize the query
    limit=2,
    rerank=Rerank(
        prop="title",                   # The property to rerank on
        query="A melodic holiday film"  # If not provided, the original query will be used
    )
)

for obj in response.objects:
    print(obj.properties["title"])
```

**JavaScript/TypeScript**

```ts
let myCollection = client.collections.use('DemoCollection');

const results = await myCollection.query.nearText(
  ['A holiday film'],
  {
    limit: 2,
    rerank: {
      property: 'title',                // The property to rerank on
      query: 'A melodic holiday film'   // If not provided, the original query will be used
    }
  }
);

for (const obj of results.objects) {
  console.log(obj.properties['title']);
}
```

## References

### Available models

- `cross-encoder/ms-marco-MiniLM-L-6-v2`
- `cross-encoder/ms-marco-MiniLM-L-2-v2`
- `cross-encoder/ms-marco-TinyBERT-L-2-v2`

These pre-trained models are open-sourced on Hugging Face. The `cross-encoder/ms-marco-MiniLM-L-6-v2` model, for example, provides approximately the same benchmark performance as the largest model (L-12) when evaluated on [MS-MARCO](https://microsoft.github.io/msmarco/) (39.01 vs. 39.02).

We add new model support over time. For the latest list of available models, see the Docker Hub tags for the [reranker-transformers](https://hub.docker.com/r/semitechnologies/reranker-transformers/tags) container.

## Further resources

### Other integrations

- [Transformers embedding models + Weaviate](https://docs.weaviate.io/weaviate/model-providers/transformers/embeddings).
- [Transformers multi-modal embedding models + Weaviate](https://docs.weaviate.io/weaviate/model-providers/transformers/embeddings-multimodal).

### Code examples

Once the integrations are configured at the collection, the data management and search operations in Weaviate work identically to any other collection. See the following model-agnostic examples:

- The [How-to: Manage collections](https://docs.weaviate.io/weaviate/manage-collections) and [How-to: Manage objects](https://docs.weaviate.io/weaviate/manage-objects) guides show how to perform data operations (i.e. create, read, update, delete collections and objects within them).
- The [How-to: Query & Search](https://docs.weaviate.io/weaviate/search) guides show how to perform search operations (i.e. vector, keyword, hybrid) as well as retrieval augmented generation.
