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

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

client = weaviate.connect_to_wcs(

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

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

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.

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:

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:

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:

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"))
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 :slight_smile:

Thanks Duda!

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

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

Hi @tjh !

Sorry for the delay here :upside_down_face:

Unfortunately, this is not a mutable configuration

We even have a GH issue for this (please, leave your thumbs up there! also, while in GH, please, leave us a :star: 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 :grimacing:

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

Let me know if this helps :slight_smile:

Thanks again Duda,
Upvoted & starred :smile:

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?

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 :slight_smile:

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: