docs/components/rerankers/models/cohere.mdx
Cohere provides enterprise-grade reranking models with excellent multilingual support and production-ready performance.
Cohere offers several reranking models:
rerank-english-v3.0: Latest English reranker with best performancererank-multilingual-v3.0: Multilingual support for global applicationsrerank-english-v2.0: Previous generation English rerankerpip install cohere
from mem0 import Memory
config = {
"vector_store": {
"provider": "chroma",
"config": {
"collection_name": "my_memories",
"path": "./chroma_db"
}
},
"llm": {
"provider": "openai",
"config": {
"model": "gpt-5-mini"
}
},
"reranker": {
"provider": "cohere",
"config": {
"model": "rerank-english-v3.0",
"api_key": "your-cohere-api-key", # or set COHERE_API_KEY
"top_k": 5,
"return_documents": False,
"max_chunks_per_doc": None
}
}
}
memory = Memory.from_config(config)
Set your API key as an environment variable:
export COHERE_API_KEY="your-api-key"
import os
from mem0 import Memory
# Set API key
os.environ["COHERE_API_KEY"] = "your-api-key"
# Initialize memory with Cohere reranker
config = {
"vector_store": {"provider": "chroma"},
"llm": {"provider": "openai", "config": {"model": "gpt-4o-mini"}},
"rerank": {
"provider": "cohere",
"config": {
"model": "rerank-english-v3.0",
"top_k": 3
}
}
}
memory = Memory.from_config(config)
# Add memories
messages = [
{"role": "user", "content": "I work as a data scientist at Microsoft"},
{"role": "user", "content": "I specialize in machine learning and NLP"},
{"role": "user", "content": "I enjoy playing tennis on weekends"}
]
memory.add(messages, user_id="bob")
# Search with reranking
results = memory.search("What is the user's profession?", filters={"user_id": "bob"})
for result in results['results']:
print(f"Memory: {result['memory']}")
print(f"Vector Score: {result['score']:.3f}")
print(f"Rerank Score: {result['rerank_score']:.3f}")
print()
For multilingual applications, use the multilingual model:
config = {
"rerank": {
"provider": "cohere",
"config": {
"model": "rerank-multilingual-v3.0",
"top_k": 5
}
}
}
| Parameter | Description | Type | Default |
|---|---|---|---|
model | Cohere rerank model to use | str | "rerank-english-v3.0" |
api_key | Cohere API key | str | None |
top_k | Maximum documents to return | int | None |
return_documents | Whether to return document texts | bool | False |
max_chunks_per_doc | Maximum chunks per document | int | None |
rerank-english-v3.0 for English, rerank-multilingual-v3.0 for other languages