Skip to content

Commit 56ff408

Browse files
authored
Revert "Enhance MilvusClient Initialization and Connection Management… (#2880)
… (#2863)" This reverts commit 795db9d. --------- Signed-off-by: yangxuan <[email protected]>
1 parent 0195a28 commit 56ff408

File tree

5 files changed

+10
-145
lines changed

5 files changed

+10
-145
lines changed

examples/loop_create_milvus_client.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

examples/with_usage.py

Lines changed: 0 additions & 75 deletions
This file was deleted.

pymilvus/milvus_client/async_milvus_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22
from typing import Dict, List, Optional, Union
3-
from uuid import uuid4
43

54
from pymilvus.client.abstract import AnnSearchRequest, BaseRanker
65
from pymilvus.client.constants import DEFAULT_CONSISTENCY_LEVEL
@@ -826,8 +825,9 @@ def _create_connection(
826825
**kwargs,
827826
) -> str:
828827
"""Create the connection to the Milvus server."""
829-
# TODO: Implement reuse with new uri style
830-
using = uuid4().hex
828+
using = kwargs.pop("alias", None)
829+
if not using or using == "":
830+
using = f"async-{uri}{user}"
831831
try:
832832
connections.connect(
833833
using, user, password, db_name, token, uri=uri, _async=True, **kwargs

pymilvus/milvus_client/milvus_client.py

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import contextlib
21
import logging
3-
from types import TracebackType
4-
from typing import Dict, List, Optional, Type, Union
2+
from typing import Dict, List, Optional, Union
53

64
from pymilvus.client.abstract import AnnSearchRequest, BaseRanker
75
from pymilvus.client.constants import DEFAULT_CONSISTENCY_LEVEL
@@ -63,30 +61,10 @@ def __init__(
6361
to None.
6462
Unit: second
6563
"""
66-
self._uri = uri
67-
self._user = user
68-
self._password = password
69-
self._db_name = db_name
70-
self._token = token
71-
self._timeout = timeout
72-
self._kwargs = kwargs
73-
self._using = None
74-
self._inited = False
75-
self._init()
76-
77-
def _init(self):
78-
if not self._inited:
79-
self._using = self._create_connection(
80-
self._uri,
81-
self._user,
82-
self._password,
83-
self._db_name,
84-
self._token,
85-
timeout=self._timeout,
86-
**self._kwargs,
87-
)
88-
self.is_self_hosted = bool(utility.get_server_type(using=self._using) == "milvus")
89-
self._inited = True
64+
self._using = self._create_connection(
65+
uri, user, password, db_name, token, timeout=timeout, **kwargs
66+
)
67+
self.is_self_hosted = bool(utility.get_server_type(using=self._using) == "milvus")
9068

9169
def create_collection(
9270
self,
@@ -934,26 +912,8 @@ def _create_collection_with_schema(
934912
self.create_index(collection_name, index_params, timeout=timeout)
935913
self.load_collection(collection_name, timeout=timeout)
936914

937-
def __enter__(self) -> "MilvusClient":
938-
self._init()
939-
return self
940-
941-
def __exit__(
942-
self,
943-
exc_type: Optional[Type[BaseException]],
944-
exc: Optional[BaseException],
945-
traceback: Optional[TracebackType],
946-
) -> Optional[bool]:
947-
self.close()
948-
949-
def __del__(self):
950-
self.close()
951-
952915
def close(self):
953-
if self._using is not None:
954-
with contextlib.suppress(MilvusException):
955-
connections.remove_connection(self._using)
956-
self._using = None
916+
connections.remove_connection(self._using)
957917

958918
def _get_connection(self):
959919
return connections._fetch_handler(self._using)
@@ -969,7 +929,7 @@ def _create_connection(
969929
) -> str:
970930
"""Create the connection to the Milvus server."""
971931
using = kwargs.pop("alias", None)
972-
if using is None or using == "":
932+
if not using or using == "":
973933
using = f"{uri}{user}"
974934
try:
975935
connections.connect(using, user, password, db_name, token, uri=uri, **kwargs)

pymilvus/orm/connections.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,6 @@ def _fetch_handler(
555555
self, alias: str = Config.MILVUS_CONN_ALIAS
556556
) -> Union[GrpcHandler, AsyncGrpcHandler]:
557557
"""Retrieves a GrpcHandler by alias."""
558-
if alias is None:
559-
raise ConnectionNotExistException(message=ExceptionsMessage.ConnectFirst)
560-
561558
if not isinstance(alias, str):
562559
raise ConnectionConfigException(message=ExceptionsMessage.AliasType % type(alias))
563560

0 commit comments

Comments
 (0)