Skip to content

Commit

Permalink
enhance: Make load parameter naming normal (#2243)
Browse files Browse the repository at this point in the history
Previously added parameters for `load` API have leading underscore,
which is misused and copied from `_async` parameter. The leading "_" is
to avoid use python keyword `async` and other parameters do not have to
follow this pattern.

This PR make `load` API support parameter with or without leading
underscore and update related comment. Note that the ones without
leading "_" have higher priority than the ones with it.

Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia authored Aug 30, 2024
1 parent 6d36396 commit 560adde
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
50 changes: 31 additions & 19 deletions pymilvus/client/grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,25 +1142,31 @@ def load_collection(
check_pass_param(
collection_name=collection_name, replica_number=replica_number, timeout=timeout
)
_refresh = kwargs.get("_refresh", False)
_resource_groups = kwargs.get("_resource_groups")
_load_fields = kwargs.get("_load_fields")
_skip_load_dynamic_field = kwargs.get("_skip_load_dynamic_field", False)
# leading _ is misused for keywork escape for `async`
# other params now support prefix _ or not
# params without leading "_" have higher priority
refresh = kwargs.get("refresh", kwargs.get("_refresh", False))
resource_groups = kwargs.get("resource_groups", kwargs.get("_resource_groups"))
load_fields = kwargs.get("load_fields", kwargs.get("_load_fields"))
skip_load_dynamic_field = kwargs.get(
"skip_load_dynamic_field", kwargs.get("_skip_load_dynamic_field", False)
)

request = Prepare.load_collection(
"",
collection_name,
replica_number,
_refresh,
_resource_groups,
_load_fields,
_skip_load_dynamic_field,
refresh,
resource_groups,
load_fields,
skip_load_dynamic_field,
)
rf = self._stub.LoadCollection.future(request, timeout=timeout)
response = rf.result()
check_status(response)
_async = kwargs.get("_async", False)
if not _async:
self.wait_for_loading_collection(collection_name, timeout, is_refresh=_refresh)
self.wait_for_loading_collection(collection_name, timeout, is_refresh=refresh)

@retry_on_rpc_failure()
def load_collection_progress(self, collection_name: str, timeout: Optional[float] = None):
Expand Down Expand Up @@ -1213,19 +1219,25 @@ def load_partitions(
replica_number=replica_number,
timeout=timeout,
)
_refresh = kwargs.get("_refresh", False)
_resource_groups = kwargs.get("_resource_groups")
_load_fields = kwargs.get("_load_fields")
_skip_load_dynamic_field = kwargs.get("_skip_load_dynamic_field", False)
# leading _ is misused for keywork escape for `async`
# other params now support prefix _ or not
# params without leading "_" have higher priority
refresh = kwargs.get("refresh", kwargs.get("_refresh", False))
resource_groups = kwargs.get("resource_groups", kwargs.get("_resource_groups"))
load_fields = kwargs.get("load_fields", kwargs.get("_load_fields"))
skip_load_dynamic_field = kwargs.get(
"skip_load_dynamic_field", kwargs.get("_skip_load_dynamic_field", False)
)

request = Prepare.load_partitions(
"",
collection_name,
partition_names,
replica_number,
_refresh,
_resource_groups,
_load_fields,
_skip_load_dynamic_field,
refresh,
resource_groups,
load_fields,
skip_load_dynamic_field,
)
future = self._stub.LoadPartitions.future(request, timeout=timeout)

Expand All @@ -1234,7 +1246,7 @@ def load_partitions(
def _check():
if kwargs.get("sync", True):
self.wait_for_loading_partitions(
collection_name, partition_names, is_refresh=_refresh
collection_name, partition_names, is_refresh=refresh
)

load_partitions_future = LoadPartitionsFuture(future)
Expand All @@ -1250,7 +1262,7 @@ def _check():
check_status(response)
sync = kwargs.get("sync", True)
if sync:
self.wait_for_loading_partitions(collection_name, partition_names, is_refresh=_refresh)
self.wait_for_loading_partitions(collection_name, partition_names, is_refresh=refresh)
return None
return None

Expand Down
8 changes: 6 additions & 2 deletions pymilvus/orm/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,14 @@ def load(
* *_async*(``bool``)
Indicate if invoke asynchronously.
* *_refresh*(``bool``)
* *refresh*(``bool``)
Whether to renew the segment list of this collection before loading
* *_resource_groups(``List[str]``)
* *resource_groups(``List[str]``)
Specify resource groups which can be used during loading.
* *load_fields(``List[str]``)
Specify load fields list needed during this load
* *_skip_load_dynamic_field(``bool``)
Specify whether this load shall skip dynamic schmea field
Raises:
MilvusException: If anything goes wrong.
Expand Down

0 comments on commit 560adde

Please sign in to comment.