{"record":{"id":"af8bd4fada9ca141","repo":"FoundationAgents/MetaGPT","slug":"please-install-pymilvus-first","errorCode":null,"errorMessage":"Please install pymilvus first.","messagePattern":"Please install pymilvus first\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"metagpt/document_store/milvus_store.py","lineNumber":24,"sourceCode":"\n@dataclass\nclass MilvusConnection:\n    \"\"\"\n    Args:\n        uri: milvus url\n        token: milvus token\n    \"\"\"\n\n    uri: str = None\n    token: str = None\n\n\nclass MilvusStore(BaseStore):\n    def __init__(self, connect: MilvusConnection):\n        try:\n            from pymilvus import MilvusClient\n        except ImportError:\n            raise Exception(\"Please install pymilvus first.\")\n        if not connect.uri:\n            raise Exception(\"please check MilvusConnection, uri must be set.\")\n        self.client = MilvusClient(uri=connect.uri, token=connect.token)\n\n    def create_collection(self, collection_name: str, dim: int, enable_dynamic_schema: bool = True):\n        from pymilvus import DataType\n\n        if self.client.has_collection(collection_name=collection_name):\n            self.client.drop_collection(collection_name=collection_name)\n\n        schema = self.client.create_schema(\n            auto_id=False,\n            enable_dynamic_field=False,\n        )\n        schema.add_field(field_name=\"id\", datatype=DataType.VARCHAR, is_primary=True, max_length=36)\n        schema.add_field(field_name=\"vector\", datatype=DataType.FLOAT_VECTOR, dim=dim)\n\n        index_params = self.client.prepare_index_params()","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/document_store/milvus_store.py#L6-L42","documentation":"MilvusStore.__init__ tries to import pymilvus.MilvusClient inside a try/except and raises 'Please install pymilvus first.' on ImportError. The dependency is optional: it is only declared in MetaGPT's rag/milvus extras, not the base install, so MilvusStore is unusable without it.","triggerScenarios":"Constructing MilvusStore(MilvusConnection(uri=..., token=...)) in an environment where the pymilvus package is not installed (no metagpt[milvus] extra).","commonSituations":"pip install metagpt without extras then using the Milvus document store; CI images trimmed of optional deps; a new team member following the base README; upgrading Python versions and losing the previously installed pymilvus.","solutions":["Install the dependency: pip install pymilvus (or pip install 'metagpt[milvus]' if you installed MetaGPT from PyPI with extras).","Pin a compatible version, e.g. pip install 'pymilvus>=2.4' — MilvusClient and create_schema require the 2.x client API.","For deployments, add pymilvus to requirements.txt / Dockerfile so the image is self-contained."],"exampleFix":"# before\nstore = MilvusStore(MilvusConnection(uri=\"http://localhost:19530\"))  # Exception: Please install pymilvus first.\n\n# after\n# shell: pip install pymilvus\nstore = MilvusStore(MilvusConnection(uri=\"http://localhost:19530\"))","handlingStrategy":"validation","validationCode":"def milvus_available() -> bool:\n    try:\n        import pymilvus  # noqa: F401\n        return True\n    except ImportError:\n        return False\n\nif not milvus_available():\n    raise SystemExit(\"Install with: pip install 'metagpt[milvus]' (or pip install pymilvus)\")","typeGuard":null,"tryCatchPattern":"try:\n    store = MilvusStore(conn)\nexcept Exception as e:\n    if \"install pymilvus\" in str(e):\n        raise SystemExit(\"missing dependency; run: pip install pymilvus\") from e\n    raise","preventionTips":["Install MetaGPT with the milvus extra from day one when the Milvus store is part of your design.","Add pymilvus to requirements/Dockerfile so images are self-contained.","Add a startup dependency check (import pymilvus) that reports the install command instead of failing at first store construction."],"tags":["python","milvus","missing-dependency","installation"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}