Skip to content

Commit

Permalink
[REFACTOR] Add _async parameter in connections.py
Browse files Browse the repository at this point in the history
- Add `_async` parameter in `connections.py` to determine whether to establish a synchronous or asynchronous connection
- Fix `__all__` is not sorted in `__init__.py` which failed in code lint check

Signed-off-by: Ruichen Bao <ruichen.bao@zju.edu.cn>
  • Loading branch information
brcarry committed Dec 13, 2024
1 parent 2df9f02 commit 37e1c51
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 570 deletions.
2 changes: 1 addition & 1 deletion pymilvus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@

__all__ = [
"AnnSearchRequest",
"AsyncMilvusClient",
"BulkInsertState",
"Collection",
"CollectionSchema",
Expand All @@ -90,7 +91,6 @@
"IndexType",
"Milvus",
"MilvusClient",
"AsyncMilvusClient",
"MilvusException",
"MilvusUnavailableException",
"MutationFuture",
Expand Down
2 changes: 1 addition & 1 deletion pymilvus/milvus_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from .index import IndexParams
from .milvus_client import MilvusClient

__all__ = ["IndexParams", "MilvusClient", "AsyncMilvusClient"]
__all__ = ["AsyncMilvusClient", "IndexParams", "MilvusClient"]
10 changes: 6 additions & 4 deletions pymilvus/milvus_client/async_milvus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
ParamError,
PrimaryKeyException,
)
from pymilvus.orm import async_utility
from pymilvus.orm.async_connections import connections
from pymilvus.orm import utility
from pymilvus.orm.collection import CollectionSchema
from pymilvus.orm.connections import connections
from pymilvus.orm.types import DataType

from .index import IndexParams
Expand All @@ -41,7 +41,7 @@ def __init__(
self._using = self._create_connection(
uri, user, password, db_name, token, timeout=timeout, **kwargs
)
self.is_self_hosted = bool(async_utility.get_server_type(using=self._using) == "milvus")
self.is_self_hosted = bool(utility.get_server_type(using=self._using) == "milvus")

async def create_collection(
self,
Expand Down Expand Up @@ -535,7 +535,9 @@ def _create_connection(
# TODO: Implement reuse with new uri style
using = uuid4().hex
try:
connections.connect(using, user, password, db_name, token, uri=uri, **kwargs)
connections.connect(
using, user, password, db_name, token, uri=uri, _async=True, **kwargs
)
except Exception as ex:
logger.error("Failed to create new connection using: %s", using)
raise ex from ex
Expand Down
Loading

0 comments on commit 37e1c51

Please sign in to comment.