FoundationAgents/MetaGPT · error · Exception
please check MilvusConnection, uri must be set.
Error message
please check MilvusConnection, uri must be set.
What it means
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).
Source
Thrown at metagpt/document_store/milvus_store.py:26
class MilvusConnection:
"""
Args:
uri: milvus url
token: milvus token
"""
uri: str = None
token: str = None
class MilvusStore(BaseStore):
def __init__(self, connect: MilvusConnection):
try:
from pymilvus import MilvusClient
except ImportError:
raise Exception("Please install pymilvus first.")
if not connect.uri:
raise Exception("please check MilvusConnection, uri must be set.")
self.client = MilvusClient(uri=connect.uri, token=connect.token)
def create_collection(self, collection_name: str, dim: int, enable_dynamic_schema: bool = True):
from pymilvus import DataType
if self.client.has_collection(collection_name=collection_name):
self.client.drop_collection(collection_name=collection_name)
schema = self.client.create_schema(
auto_id=False,
enable_dynamic_field=False,
)
schema.add_field(field_name="id", datatype=DataType.VARCHAR, is_primary=True, max_length=36)
schema.add_field(field_name="vector", datatype=DataType.FLOAT_VECTOR, dim=dim)
index_params = self.client.prepare_index_params()
index_params.add_index(field_name="vector", index_type="AUTOINDEX", metric_type="COSINE")
View on GitHub (pinned to 11cdf466d0)
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.
Example fix
# before
store = MilvusStore(MilvusConnection(token="root:Milvus")) # Exception: uri must be set.
# after
uri = os.environ["MILVUS_URI"] # KeyError early if unset
store = MilvusStore(MilvusConnection(uri=uri, token=os.environ.get("MILVUS_TOKEN"))) Defensive patterns
Strategy: validation
Validate before calling
def make_milvus_connection(uri, token=None) -> "MilvusConnection":
if not uri:
raise ValueError("MILVUS_URI is not set; export it or add it to the config before starting")
return MilvusConnection(uri=uri, token=token) Try / catch
try:
store = MilvusStore(conn)
except Exception as e:
if "uri must be set" in str(e):
raise ValueError("Milvus config incomplete: provide milvus.uri (e.g. http://localhost:19530)") from e
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- use `review` after `fill`
- Please install pymilvus first.
- please check QdrantConnection.
- Unsupported dataset: {dataset}
- Rollouts must be greater than 2 if there is no tree to load
AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14).
Data as JSON: /api/errors/0cebbfd447e58ac2.
Report an issue: GitHub.