# Python client v4, is Cohere reranker still enabled by default?

**URL:** <https://forum.weaviate.io/t/python-client-v4-is-cohere-reranker-still-enabled-by-default/1678>\
**Category:** Support\
**Tags:** python\
**Created:** [March 11, 2024, 5:34pm UTC](https://forum.weaviate.io/t/python-client-v4-is-cohere-reranker-still-enabled-by-default/1678 "2024-03-11T17:34:16Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![tjh](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/tjh/32/133_2.png) [@tjh](https://forum.weaviate.io/u/tjh)\
**Post date:** [March 11, 2024, 5:34pm UTC](https://forum.weaviate.io/t/python-client-v4-is-cohere-reranker-still-enabled-by-default/1678/1 "2024-03-11T17:34:16Z")

</div>

### Description

according to section below,

> This module uses a third-party API and may incur costs  
> but also  
> This module is enabled by default on the WCS.

but when I initialize the cloud client, I don’t pass in Cohere creds

```auto
client = weaviate.connect_to_wcs(

```

What’s the way to use Cohere’s english v3 reranker with weaviate?

> **[Reranker | Weaviate Documentation](https://docs.weaviate.io/weaviate/model-providers/cohere/reranker)**
>
> Cohere Reranker Model Provider

### Server Setup Information

- Weaviate Server Version:
- Deployment Method: cloud
- Multi Node? Number of Running Nodes: 1
- Client Language and Version: Python v4

### Any additional Information

---

<div class="post-metadata">

**Author:** ![tjh](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/tjh/32/133_2.png) [@tjh](https://forum.weaviate.io/u/tjh)\
**Post date:** [March 11, 2024, 5:35pm UTC](https://forum.weaviate.io/t/python-client-v4-is-cohere-reranker-still-enabled-by-default/1678/2 "2024-03-11T17:35:11Z")

</div>

is there also a way to get visibility into:

- num docs before & after reranker

to observe how much of a difference it’s making?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [March 12, 2024, 12:50pm UTC](https://forum.weaviate.io/t/python-client-v4-is-cohere-reranker-still-enabled-by-default/1678/3 "2024-03-12T12:50:40Z")

</div>

hi!

In order to get cohere rerank working, you need to first enable it in your ENABLE\_MODULES (already enabled in WCS).

With that module enabled, you will need to initiate your client specifying the cohere API KEY:

```auto
import weaviate
import os
  
# Set these environment variables
URL = os.getenv("YOUR_WCS_URL")
APIKEY = os.getenv("YOUR_WCS_API_KEY")
COHERE_APIKEY = os.environ["COHERE_APIKEY"]
  
# Connect to a WCS instance
client = weaviate.connect_to_wcs(
    cluster_url=URL,
    auth_credentials=weaviate.auth.AuthApiKey(APIKEY),
    headers={
        "X-Cohere-Api-Key": COHERE_APIKEY # Replace with your inference API key
    }
)

```

Now you can create a collection and specify that you want to use that module, like so:

```auto
import weaviate.classes as wvc

collection = client.collections.create(
    name="MyCollection",
    vectorizer_config=wvc.config.Configure.Vectorizer.text2vec_openai(),
    reranker_config=wvc.config.Configure.Reranker.cohere(),
)

```

After applying the reranker, you can access the rerank\_score, like so:

```auto
query = collection.query.bm25(
    query="Animals", 
    rerank=wvc.query.Rerank(
        prop="question",
        query="big"
    ),
    return_metadata=wvc.query.MetadataQuery(certainty=True, score=True)
)

for i in query.objects:
    print(i.metadata.rerank_score, i.properties.get("question"))

```

```auto
0.01665704 The gavial looks very much like a crocodile except for this bodily feature
0.01395571 Weighing around a ton, the eland is the largest species of this animal in Africa
0.005099818 Heaviest of all poisonous snakes is this North American rattlesnake
0.0005442133 It's the only living mammal in the order Proboseidea

```

Let me know if this helps 🙂

---

<div class="post-metadata">

**Author:** ![tjh](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/tjh/32/133_2.png) [@tjh](https://forum.weaviate.io/u/tjh)\
**Post date:** [March 12, 2024, 2:07pm UTC](https://forum.weaviate.io/t/python-client-v4-is-cohere-reranker-still-enabled-by-default/1678/4 "2024-03-12T14:07:01Z")

</div>

Thanks Duda!

If I already have a collection in prod, how would I add it?

---

<div class="post-metadata">

**Author:** ![tjh](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/tjh/32/133_2.png) [@tjh](https://forum.weaviate.io/u/tjh)\
**Post date:** [March 13, 2024, 2:58pm UTC](https://forum.weaviate.io/t/python-client-v4-is-cohere-reranker-still-enabled-by-default/1678/6 "2024-03-13T14:58:05Z")

</div>

@DudaNogueira wanted to bump,  
If I already have a collection in prod, how would I add it?

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [March 13, 2024, 9:24pm UTC](https://forum.weaviate.io/t/python-client-v4-is-cohere-reranker-still-enabled-by-default/1678/7 "2024-03-13T21:24:39Z")

</div>

Hi @tjh !

Sorry for the delay here 🙃

Unfortunately, this is not a [mutable configuration](https://weaviate.io/developers/weaviate/config-refs/schema#mutability)

We even have a [GH issue](https://github.com/weaviate/weaviate/issues/3364) for this (please, leave your thumbs up there! also, while in GH, please, leave us a ⭐ too)

So, in order to enable it for your collection, you will need to create a new one, with all the modules you want, and then migrate your data 😬

It’s fairly easy process, and we have a guide for that here:

> **[Migrate data | Weaviate - Vector Database](https://weaviate.io/developers/weaviate/manage-data/migrate)**
>
> Overview

Let me know if this helps 🙂

---

<div class="post-metadata">

**Author:** ![tjh](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/tjh/32/133_2.png) [@tjh](https://forum.weaviate.io/u/tjh)\
**Post date:** [March 13, 2024, 10:24pm UTC](https://forum.weaviate.io/t/python-client-v4-is-cohere-reranker-still-enabled-by-default/1678/8 "2024-03-13T22:24:51Z")

</div>

Thanks again Duda,  
Upvoted & starred 😄

one quick followup,  
the reranker model eg `rerank-english-v2.0`  
need this be linked to our embedder or `embed-english-v3.0` or is that completely separate?

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [March 14, 2024, 6:48pm UTC](https://forum.weaviate.io/t/python-client-v4-is-cohere-reranker-still-enabled-by-default/1678/9 "2024-03-14T18:48:53Z")

</div>

They are separated.

You can use any model for the embeddings/vectorizer, and a totally different generative model or rerank model.

For example, you can rerank using cohere, search your data vectorized using openai, and generate using other model 🙂

But be aware, for now, in order to change any of those modules in a collection, a new collection is needed, as those are no mutable:

> **[Collection schema | Weaviate - Vector Database](https://weaviate.io/developers/weaviate/config-refs/schema#mutability)**
>
> Introduction

---

<div class="post-metadata">

**Author:** ![suprateembanerjee](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/suprateembanerjee/32/1617_2.png) [@suprateembanerjee](https://forum.weaviate.io/u/suprateembanerjee)\
**Post date:** [May 31, 2024, 6:40pm UTC](https://forum.weaviate.io/t/python-client-v4-is-cohere-reranker-still-enabled-by-default/1678/10 "2024-05-31T18:40:35Z")

</div>

> [@DudaNogueira](#):
>
> ```auto
> prop="question",
> query="big"
> 
> ```

What is `prop` and `query` in this case?

If I want to retrieve 10 documents using vector/hybrid/keyword search (using `limit = 10`), how do I specify I want to rerank these documents in cross-encoder (reranker), and retrieve the top 5?

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [May 31, 2024, 6:47pm UTC](https://forum.weaviate.io/t/python-client-v4-is-cohere-reranker-still-enabled-by-default/1678/11 "2024-05-31T18:47:29Z")

</div>

hi! `prop` is the property where the `query` will act as reranker.

Described here:

> **[Reranking | Weaviate - Vector Database](https://weaviate.io/developers/weaviate/concepts/reranking)**
>
> Reranking seeks to improve search relevance by reordering the result set returned by a retriever with a different model.

If you want to post limit your rerank to 5, you need to do that after the process, something like:

```auto
query = collection.query.bm25(
    query="Animals", 
    rerank=wvc.query.Rerank(
        prop="question",
        query="big"
    ),
    return_metadata=wvc.query.MetadataQuery(certainty=True, score=True)
)
top_5_objects = query.objects[0:5]

```

Let me know if this helps!

Thanks!

---

<div class="post-metadata">

**Author:** ![suprateembanerjee](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/suprateembanerjee/32/1617_2.png) [@suprateembanerjee](https://forum.weaviate.io/u/suprateembanerjee)\
**Post date:** [May 31, 2024, 7:05pm UTC](https://forum.weaviate.io/t/python-client-v4-is-cohere-reranker-still-enabled-by-default/1678/12 "2024-05-31T19:05:47Z")

</div>

Yes, that helps clear it up. So the reranking takes place after the entire BM25 run is completed in your example, right?

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [June 1, 2024, 1:38am UTC](https://forum.weaviate.io/t/python-client-v4-is-cohere-reranker-still-enabled-by-default/1678/13 "2024-06-01T01:38:28Z")

</div>

That’s right!

It will perform the search (bm25, vector, hybrid), and then all those results are passed to the reranker.

If you want to somehow “bias” those results instead of doing a reranking, you can also experiment with move\_to and move\_away:

> **[Search operators | Weaviate - Vector Database](https://weaviate.io/developers/weaviate/api/graphql/search-operators#neartext)**
>
> Overview

This will give you some “post” retrieval tweaking.

---

<div class="post-metadata">

**Author:** ![suprateembanerjee](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/suprateembanerjee/32/1617_2.png) [@suprateembanerjee](https://forum.weaviate.io/u/suprateembanerjee)\
**Post date:** [June 1, 2024, 1:56am UTC](https://forum.weaviate.io/t/python-client-v4-is-cohere-reranker-still-enabled-by-default/1678/14 "2024-06-01T01:56:38Z")

</div>

From my understanding, you can still do post-retrieval tweaking using the `vector` parameter, even with reranking present. This applies to post-retrieval, pre-rerank stage, yes?

I was not able to find an option to use a generator with this chain, however, since we can’t specify the number of most relevant documents to pick after re-ranking. Is there a way to do that?  
Eg. Search → Pick 25 → Rerank → Pick Top 10 → Generate based on top 10?

Currently, I have to move out of the weaviate framework and query my language model independently with the reranked context even though I am using the language model as a generator in my weaviate pipeline.
