From b59469256cd41f2ae89d00a79093ab28faf3e6ea Mon Sep 17 00:00:00 2001 From: "zhenshan.cao" Date: Tue, 5 Mar 2024 10:30:52 +0800 Subject: [PATCH] Fix several bugs reated to MilvusClient (#1948) Signed-off-by: zhenshan.cao --- pymilvus/milvus_client/milvus_client.py | 20 ++++++++++++-------- pymilvus/orm/schema.py | 7 ++++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/pymilvus/milvus_client/milvus_client.py b/pymilvus/milvus_client/milvus_client.py index 4f1f034e3..145c33c7d 100644 --- a/pymilvus/milvus_client/milvus_client.py +++ b/pymilvus/milvus_client/milvus_client.py @@ -62,7 +62,7 @@ def create_collection( primary_field_name: str = "id", # default is "id" id_type: str = "int", # or "string", vector_field_name: str = "vector", # default is "vector" - metric_type: str = "IP", + metric_type: str = "COSINE", auto_id: bool = False, timeout: Optional[float] = None, schema: Optional[CollectionSchema] = None, @@ -91,9 +91,9 @@ def _fast_create_collection( collection_name: str, dimension: int, primary_field_name: str = "id", # default is "id" - id_type: str = "int", # or "string", + id_type: Union[DataType, str] = DataType.INT64, # or "string", vector_field_name: str = "vector", # default is "vector" - metric_type: str = "IP", + metric_type: str = "COSINE", auto_id: bool = False, timeout: Optional[float] = None, **kwargs, @@ -106,9 +106,9 @@ def _fast_create_collection( schema = self.create_schema(auto_id=auto_id, **kwargs) - if id_type == "int": + if id_type in ("int", DataType.INT64): pk_data_type = DataType.INT64 - elif id_type in ("string", "str"): + elif id_type in ("string", "str", DataType.VARCHAR): pk_data_type = DataType.VARCHAR else: raise PrimaryKeyException(message=ExceptionsMessage.PrimaryFieldType) @@ -607,10 +607,11 @@ def _create_collection_with_schema( schema.verify() if kwargs.get("auto_id", False): schema.auto_id = True - if kwargs.get("enable_dynamic_field", False): - schema.enable_dynamic_field = True schema.verify() + if schema.enable_dynamic_field is None: + schema.enable_dynamic_field = kwargs.get("enable_dynamic_field", False) + conn = self._get_connection() if "consistency_level" not in kwargs: kwargs["consistency_level"] = DEFAULT_CONSISTENCY_LEVEL @@ -895,7 +896,10 @@ def describe_role( res = conn.select_grant_for_one_role(role_name, db_name, timeout=timeout, **kwargs) except Exception as ex: raise ex from ex - return [dict(i) for i in res.groups] + ret = {} + ret["role"] = role_name + ret["privileges"] = [dict(i) for i in res.groups] + return ret def list_roles(self, timeout: Optional[float] = None, **kwargs): conn = self._get_connection() diff --git a/pymilvus/orm/schema.py b/pymilvus/orm/schema.py index 5b0902047..6ae6a568f 100644 --- a/pymilvus/orm/schema.py +++ b/pymilvus/orm/schema.py @@ -67,7 +67,8 @@ def __init__(self, fields: List, description: str = "", **kwargs): self._kwargs = copy.deepcopy(kwargs) self._fields = [] self._description = description - self._enable_dynamic_field = self._kwargs.get("enable_dynamic_field", False) + # if "enable_dynamic_field" is not in kwargs, we keep None here + self._enable_dynamic_field = self._kwargs.get("enable_dynamic_field", None) self._primary_field = None self._partition_key_field = None @@ -225,6 +226,10 @@ def enable_dynamic_field(self): @enable_dynamic_field.setter def enable_dynamic_field(self, value: bool): + if value is None: + # we keep None here + self._enable_dynamic_field = value + return self._enable_dynamic_field = bool(value) def to_dict(self):