{"record":{"id":"0cebbfd447e58ac2","repo":"FoundationAgents/MetaGPT","slug":"please-check-milvusconnection-uri-must-be-set","errorCode":null,"errorMessage":"please check MilvusConnection, uri must be set.","messagePattern":"please check MilvusConnection, uri must be set\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"metagpt/document_store/milvus_store.py","lineNumber":26,"sourceCode":"class 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()\n        index_params.add_index(field_name=\"vector\", index_type=\"AUTOINDEX\", metric_type=\"COSINE\")\n","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/document_store/milvus_store.py#L8-L44","documentation":"MilvusStore.__init__ validates the MilvusConnection config before creating MilvusClient: if connect.uri is None/empty it raises 'please check MilvusConnection, uri must be set.'. The uri is mandatory because it is the only way the client locates your Milvus instance (token is optional and defaults to None).","triggerScenarios":"MilvusStore(MilvusConnection()) with no arguments, or MilvusConnection(token=...) with only a token set; also uri=\"\" from an empty config value or an unset environment variable read as empty string.","commonSituations":"Loading connection settings from a config file where the milvus.uri key is missing; passing Zilliz cloud credentials but forgetting the cloud endpoint; building MilvusConnection from os.environ.get('MILVUS_URI') when the variable is not exported.","solutions":["Set the uri explicitly: MilvusStore(MilvusConnection(uri=\"http://localhost:19530\", token=None)).","For Zilliz cloud use uri=\"https://<cluster-endpoint>\" together with token=\"<user>:<password>\".","Fix the config source: ensure the milvus uri key exists and is non-empty before constructing the connection, and fail fast with your own error message if not."],"exampleFix":"# before\nstore = MilvusStore(MilvusConnection(token=\"root:Milvus\"))  # Exception: uri must be set.\n\n# after\nuri = os.environ[\"MILVUS_URI\"]  # KeyError early if unset\nstore = MilvusStore(MilvusConnection(uri=uri, token=os.environ.get(\"MILVUS_TOKEN\")))","handlingStrategy":"validation","validationCode":"def make_milvus_connection(uri, token=None) -> \"MilvusConnection\":\n    if not uri:\n        raise ValueError(\"MILVUS_URI is not set; export it or add it to the config before starting\")\n    return MilvusConnection(uri=uri, token=token)","typeGuard":null,"tryCatchPattern":"try:\n    store = MilvusStore(conn)\nexcept Exception as e:\n    if \"uri must be set\" in str(e):\n        raise ValueError(\"Milvus config incomplete: provide milvus.uri (e.g. http://localhost:19530)\") from e\n    raise","preventionTips":["Validate the connection object at config-load time, not at first use — fail fast on empty uri.","Use os.environ[\"MILVUS_URI\"] (KeyError on missing) instead of .get() so an unset variable cannot become an empty uri.","Include a uri example in your config template (http://localhost:19530 or a Zilliz https endpoint) to prevent blank fields."],"tags":["python","milvus","configuration","validation"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}