{"record":{"id":"4f937f356f06dd8f","repo":"FoundationAgents/MetaGPT","slug":"llama-index-postprocessor-cohere-rerank-package","errorCode":null,"errorMessage":"`llama-index-postprocessor-cohere-rerank` package not found, please run `pip install llama-index-postprocessor-cohere-rerank`","messagePattern":"`llama-index-postprocessor-cohere-rerank` package not found, please run `pip install llama-index-postprocessor-cohere-rerank`","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"metagpt/rag/factories/ranker.py","lineNumber":57,"sourceCode":"    def _create_llm_ranker(self, config: LLMRankerConfig, **kwargs) -> LLMRerank:\n        config.llm = self._extract_llm(config, **kwargs)\n\n        return LLMRerank(**config.model_dump())\n\n    def _create_colbert_ranker(self, config: ColbertRerankConfig, **kwargs) -> LLMRerank:\n        try:\n            from llama_index.postprocessor.colbert_rerank import ColbertRerank\n        except ImportError:\n            raise ImportError(\n                \"`llama-index-postprocessor-colbert-rerank` package not found, please run `pip install llama-index-postprocessor-colbert-rerank`\"\n            )\n        return ColbertRerank(**config.model_dump())\n\n    def _create_cohere_rerank(self, config: CohereRerankConfig, **kwargs) -> LLMRerank:\n        try:\n            from llama_index.postprocessor.cohere_rerank import CohereRerank\n        except ImportError:\n            raise ImportError(\n                \"`llama-index-postprocessor-cohere-rerank` package not found, please run `pip install llama-index-postprocessor-cohere-rerank`\"\n            )\n        return CohereRerank(**config.model_dump())\n\n    def _create_bge_rerank(self, config: BGERerankConfig, **kwargs) -> LLMRerank:\n        try:\n            from llama_index.postprocessor.flag_embedding_reranker import (\n                FlagEmbeddingReranker,\n            )\n        except ImportError:\n            raise ImportError(\n                \"`llama-index-postprocessor-flag-embedding-reranker` package not found, please run `pip install llama-index-postprocessor-flag-embedding-reranker`\"\n            )\n        return FlagEmbeddingReranker(**config.model_dump())\n\n    def _create_object_ranker(self, config: ObjectRankerConfig, **kwargs) -> LLMRerank:\n        return ObjectSortPostprocessor(**config.model_dump())\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/rag/factories/ranker.py#L39-L75","documentation":"RankerFactory._create_cohere_rerank raises this ImportError when llama-index-postprocessor-cohere-rerank is missing. CohereRerank is imported lazily inside the factory method, so the error surfaces only at ranker construction time, not at metagpt import time.","triggerScenarios":"Building rankers with a CohereRerankConfig (e.g. via get_rankers or retriever config listing a cohere reranker) without the cohere rerank package installed.","commonSituations":"Switching a RAG pipeline to Cohere reranking without adding the extra dependency; environments where only metagpt[rag] core extras were installed; llama-index >= 0.10 where each postprocessor is its own distribution.","solutions":["pip install llama-index-postprocessor-cohere-rerank","Set the COHERE_API_KEY env var afterwards, since CohereRerank also needs an API key at runtime","Or pin the package in your dependency manifest to keep CI and prod in sync"],"exampleFix":"// before\nrankers = get_rankers(configs=[CohereRerankConfig(top_n=2)])  # ImportError\n\n// after\n// pip install llama-index-postprocessor-cohere-rerank\nrankers = get_rankers(configs=[CohereRerankConfig(top_n=2, api_key=os.environ[\"COHERE_API_KEY\"])])","handlingStrategy":"validation","validationCode":"import importlib.util\nif importlib.util.find_spec(\"llama_index.postprocessor.cohere_rerank\") is None:\n    raise SystemExit(\"Install first: pip install llama-index-postprocessor-cohere-rerank\")","typeGuard":null,"tryCatchPattern":"try:\n    ranker = get_rankers(configs=[cohere_cfg])\nexcept ImportError as e:\n    if \"cohere-rerank\" in str(e):\n        logger.warning(\"cohere rerank unavailable, falling back to no reranker\")\n        ranker = None\n    else:\n        raise","preventionTips":["Install llama-index-postprocessor-cohere-rerank wherever cohere reranking is configured","Set COHERE_API_KEY via environment, never hardcode it in ranker configs","Smoke-test ranker construction in CI to catch missing extras before deploy"],"tags":["rag","reranker","dependency","cohere","importerror"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}