Skip to content

Commit

Permalink
support delete with consistency level (#1829)
Browse files Browse the repository at this point in the history
Signed-off-by: aoiasd <[email protected]>
  • Loading branch information
aoiasd authored Jan 2, 2024
1 parent b86e002 commit 11963c8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
7 changes: 6 additions & 1 deletion pymilvus/client/grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,12 @@ def delete(
):
check_pass_param(collection_name=collection_name)
try:
req = Prepare.delete_request(collection_name, partition_name, expression)
req = Prepare.delete_request(
collection_name,
partition_name,
expression,
consistency_level=kwargs.get("consistency_level", 0),
)
future = self._stub.Delete.future(req, timeout=timeout)

if kwargs.get("_async", False):
Expand Down
19 changes: 16 additions & 3 deletions pymilvus/client/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@

from . import blob, entity_helper, ts_utils
from .check import check_pass_param, is_legal_collection_properties
from .constants import DEFAULT_CONSISTENCY_LEVEL, GROUP_BY_FIELD, REDUCE_STOP_FOR_BEST
from .constants import (
DEFAULT_CONSISTENCY_LEVEL,
GROUP_BY_FIELD,
REDUCE_STOP_FOR_BEST,
)
from .types import DataType, PlaceholderType, get_consistency_level
from .utils import traverse_info, traverse_rows_info

Expand Down Expand Up @@ -535,7 +539,13 @@ def batch_upsert_param(
return cls._parse_batch_request(request, entities, fields_info, location)

@classmethod
def delete_request(cls, collection_name: str, partition_name: str, expr: str):
def delete_request(
cls,
collection_name: str,
partition_name: str,
expr: str,
consistency_level: Optional[Union[int, str]],
):
def check_str(instr: str, prefix: str):
if instr is None:
raise ParamError(message=f"{prefix} cannot be None")
Expand All @@ -550,7 +560,10 @@ def check_str(instr: str, prefix: str):
check_str(expr, "expr")

return milvus_types.DeleteRequest(
collection_name=collection_name, partition_name=partition_name, expr=expr
collection_name=collection_name,
partition_name=partition_name,
expr=expr,
consistency_level=get_consistency_level(consistency_level),
)

@classmethod
Expand Down
10 changes: 10 additions & 0 deletions pymilvus/orm/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,16 @@ def delete(
timeout (float, optional): an optional duration of time in seconds to allow
for the RPCs. If timeout is not set, the client keeps waiting until the
server responds or an error occurs.
**kwargs (``dict``): Optional search params
* *consistency_level* (``str/int``, optional)
Which consistency level to use when searching in the collection.
Options of consistency level: Strong, Bounded, Eventually, Session, Customized.
Note: this parameter overwrites the same one specified when creating collection,
if no consistency level was specified, search will use the
consistency level when you create the collection.
Returns:
MutationResult:
Expand Down

0 comments on commit 11963c8

Please sign in to comment.