|
|
@@ -24,13 +24,36 @@ class MilvusStore:
|
|
|
"""
|
|
|
# 启动内嵌服务器
|
|
|
default_server.set_base_dir(data_dir)
|
|
|
- default_server.start()
|
|
|
|
|
|
- # 连接
|
|
|
- connections.connect(
|
|
|
- host='127.0.0.1',
|
|
|
- port=default_server.listen_port
|
|
|
- )
|
|
|
+ # 检查是否已经有 Milvus 实例在运行
|
|
|
+ try:
|
|
|
+ # 尝试连接到可能已存在的实例
|
|
|
+ connections.connect(
|
|
|
+ alias="default",
|
|
|
+ host='127.0.0.1',
|
|
|
+ port=default_server.listen_port,
|
|
|
+ timeout=5
|
|
|
+ )
|
|
|
+ print(f"[Milvus] 连接到已存在的 Milvus 实例 (端口 {default_server.listen_port})")
|
|
|
+ except Exception:
|
|
|
+ # 没有运行的实例,启动新的
|
|
|
+ print(f"[Milvus] 启动新的 Milvus Lite 实例...")
|
|
|
+ try:
|
|
|
+ default_server.start()
|
|
|
+ print(f"[Milvus] Milvus Lite 启动成功 (端口 {default_server.listen_port})")
|
|
|
+ except Exception as e:
|
|
|
+ print(f"[Milvus] 启动失败: {e}")
|
|
|
+ # 尝试连接到可能已经在运行的实例
|
|
|
+ try:
|
|
|
+ connections.connect(
|
|
|
+ alias="default",
|
|
|
+ host='127.0.0.1',
|
|
|
+ port=default_server.listen_port,
|
|
|
+ timeout=5
|
|
|
+ )
|
|
|
+ print(f"[Milvus] 连接到已存在的实例")
|
|
|
+ except Exception as e2:
|
|
|
+ raise RuntimeError(f"无法启动或连接到 Milvus: {e}, {e2}")
|
|
|
|
|
|
self._init_collection()
|
|
|
|