Registry / llm-agents / llama-index-postprocessor-cohere-rerank

llama-index-postprocessor-cohere-rerank

JSON →
library0.9.0pypypi✓ verified 85d ago

The llama-index-postprocessor-cohere-rerank library provides an integration for using Cohere's Rerank API within LlamaIndex, a data framework for LLM applications. This postprocessor is designed to enhance the relevance of retrieved documents in Retrieval-Augmented Generation (RAG) pipelines by re-ranking them based on semantic relevance. It is part of the broader LlamaIndex ecosystem, which typically sees frequent updates to its integration packages.

pip install llama-index-postprocessor-cohere-rerank
INSTALL
IMPORT
SIG · LLAMA-INDEX-POSTPR
L
llama-index-postprocessor-cohere-rerank
llm-agentspythonv0.9.0
Install
21.4s avg
Import
5707ms
Disk
313MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 4.752s · 308.5MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 21.4s · import 4.379s · 290MB
313MB installed
● package 313MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CohereRerank
from llama_index.postprocessor.cohere_rerank import CohereRerank
from llama_index.core.postprocessor import CoherenceRank
CohereRerank is a dedicated integration. 'CoherenceRank' is a different module, and 'llama_index.core.postprocessor' is for core rerankers, not specific integrations.

This quickstart demonstrates how to set up and use the CohereRerank postprocessor with a LlamaIndex VectorStoreIndex. It involves installing the necessary packages, setting the COHERE_API_KEY, loading some example data, building an index, and then configuring the query engine to use CohereRerank to refine the retrieval results.

import os from llama_index.core import VectorStoreIndex, SimpleDirectoryReader from llama_index.postprocessor.cohere_rerank import CohereRerank from llama_index.readers.web import SimpleWebPageReader # Set your Cohere API key os.environ["COHERE_API_KEY"] = os.environ.get("COHERE_API_KEY", "your_cohere_api_key") # Load documents (using a dummy example for demonstration) documents = SimpleWebPageReader(html_to_text=True).load_data( ["https://docs.cohere.com/v2/docs/cohere-embed"] ) # Build a VectorStoreIndex index = VectorStoreIndex.from_documents(documents=documents) # Initialize the Cohere Rerank postprocessor cohere_rerank = CohereRerank( api_key=os.environ["COHERE_API_KEY"], model="rerank-english-v3.0", # Use an appropriate Cohere rerank model top_n=2 # Number of top results to return after reranking ) # Create a query engine with the reranker query_engine = index.as_query_engine( similarity_top_k=10, # Retrieve more nodes initially for reranking node_postprocessors=[cohere_rerank] ) # Query the index response = query_engine.query("What is Cohere's Embed Model?") print(response.response) # To see source nodes if needed # from llama_index.core.response.pprint_utils import pprint_response # pprint_response(response, show_source=True)
llama-index-postprocessor-cohere-rerank --version
Debug
Known issues
breakingLlamaIndex v0.10 introduced a major packaging refactor. All integrations, including 'llama-index-postprocessor-cohere-rerank', were split into separate PyPI packages. Direct imports from `llama_index.indices.postprocessor` or older paths will break.
fix
Ensure `llama-index-postprocessor-cohere-rerank` is installed explicitly and use the correct import path: `from llama_index.postprocessor.cohere_rerank import CohereRerank`.
affects: 0.1.0 - 0.9.x (prior to v0.10 of LlamaIndex core library)
gotchaPotential version compatibility issues between `llama-index-postprocessor-cohere-rerank` and `llama-index-embeddings-cohere` due to differing `cohere` package version requirements. This can lead to dependency resolution failures.
fix
Carefully manage `cohere` package versions, ensuring compatibility across all `llama-index` integrations using `cohere`. Consult `pyproject.toml` or `setup.py` files for exact `cohere` version pins for each integration. Upgrading all `llama-index` and `cohere` related packages to their latest compatible versions is often the best solution.
affects: All versions, depending on specific combinations of `llama-index` integration packages.
gotchaThe Cohere API key (`COHERE_API_KEY`) must be correctly provided, either as an environment variable or directly to the `CohereRerank` constructor. Failure to do so will result in authentication errors or runtime exceptions.
fix
Set `os.environ["COHERE_API_KEY"] = "your_key_here"` before initializing `CohereRerank`, or pass `api_key="your_key_here"` to the constructor.
affects: All versions
Errors
Common errors & fixes
Because no versions of llama-index-postprocessor-cohere-rerank match >0.1.2,<0.2.0 and llama-index-postprocessor-cohere-rerank (0.1.2) depends on cohere (>=4.45,<5.0), llama-index-postprocessor-cohere-rerank (>=0.1.2,<0.2.0) requires cohere (>=4.45,<5.0). And because llama-index-embeddings-cohere (0.1.5) depends on cohere (>=5.1.1,<6.0.0) and no versions of llama-index-embeddings-cohere match >0.1.5,<0.2.0, llama-index-postprocessor-cohere-rerank (>=0.1.2,<0.2.0) is incompatible with llama-index-embeddings-cohere (>=0.1.5,<0.2.0).
Conflicting version requirements for the `cohere` library between different LlamaIndex integration packages.
fix
Attempt to upgrade all `llama-index-*` packages and the `cohere` package to their latest compatible versions. If conflicts persist, try isolating the conflicting packages in separate environments or manually specifying `cohere` versions that satisfy both (if possible).
ModuleNotFoundError: No module named 'llama_index.postprocessor.cohere_rerank'
The `llama-index-postprocessor-cohere-rerank` package is not installed, or the import path is incorrect, possibly due to a pre-v0.10 LlamaIndex import pattern.
fix
Ensure the package is installed with `pip install llama-index-postprocessor-cohere-rerank` and use the correct import: `from llama_index.postprocessor.cohere_rerank import CohereRerank`.
Upgrade
Version history
0.9.0latest on PyPI · released May 20, 2026
Audit
Dependencies
llama-index-corerequiredThis package is a LlamaIndex integration and depends on the core LlamaIndex library for fundamental abstractions.
cohererequiredDirect dependency for interacting with the Cohere Rerank API.
Agent activity
45 hits · last 30 days
node
38
OpenAI (training)
1
Resources
llama-index-postprocessor-cohere-rerank — pip install llama-index-postprocessor-cohere-rerank · libregistry