diff --git a/pymilvus/client/abstract.py b/pymilvus/client/abstract.py index 0acfb8cf8..d0e1e573b 100644 --- a/pymilvus/client/abstract.py +++ b/pymilvus/client/abstract.py @@ -122,12 +122,17 @@ def dict(self): "description": self.description, "type": self.type, "params": self.params or {}, - "is_primary": self.is_primary, - "auto_id": self.auto_id, - "is_partition_key": self.is_partition_key, "default_value": self.default_value, - "is_dynamic": self.is_dynamic, } + + if self.is_partition_key: + _dict["is_partition_key"] = True + if self.is_dynamic: + _dict["is_dynamic"] = True + if self.auto_id: + _dict["auto_id"] = True + if self.is_primary: + _dict["is_primary"] = self.is_primary return _dict @@ -187,6 +192,17 @@ def __pack(self, raw): self.properties = raw.properties + @classmethod + def _rewrite_schema_dict(cls, schema_dict): + fields = schema_dict.get("fields", []) + if not fields: + return + + for field_dict in fields: + if field_dict.get("auto_id", None) is not None: + schema_dict["auto_id"] = field_dict["auto_id"] + return + def dict(self): if not self._raw: return {} @@ -201,8 +217,10 @@ def dict(self): "consistency_level": self.consistency_level, "properties": self.properties, "num_partitions": self.num_partitions, - "enable_dynamic_field": self.enable_dynamic_field, } + if self.enable_dynamic_field: + _dict["enable_dynamic_field"] = self.enable_dynamic_field + self._rewrite_schema_dict(_dict) return _dict def __str__(self): diff --git a/pymilvus/client/prepare.py b/pymilvus/client/prepare.py index e8887bda3..c540c9f69 100644 --- a/pymilvus/client/prepare.py +++ b/pymilvus/client/prepare.py @@ -451,7 +451,6 @@ def search_requests_with_expr(cls, collection_name, data, anns_field, param, lim is_binary = False pl_type = PlaceholderType.FloatVector - use_default_consistency = ts_utils.construct_guarantee_ts(collection_name, kwargs) ignore_growing = param.get("ignore_growing", False) or kwargs.get("ignore_growing", False) @@ -460,13 +459,15 @@ def search_requests_with_expr(cls, collection_name, data, anns_field, param, lim raise ParamError(message=f"Search params must be a dict, got {type(params)}") search_params = { "topk": limit, - "metric_type": param.get("metric_type", ""), "params": params, "round_decimal": round_decimal, "offset": param.get("offset", 0), "ignore_growing": ignore_growing, } + if param.get("metric_type", None) is not None: + search_params["metric_type"] = param["metric_type"] + if anns_field: search_params["anns_field"] = anns_field diff --git a/pymilvus/milvus_client/milvus_client.py b/pymilvus/milvus_client/milvus_client.py index 98c5e8b82..f1fa387ab 100644 --- a/pymilvus/milvus_client/milvus_client.py +++ b/pymilvus/milvus_client/milvus_client.py @@ -193,7 +193,7 @@ def insert( def search(self, collection_name: str, data: Union[List[list], list], - filter: str = None, + filter: str = "", limit: int = 10, output_fields: List[str] = None, search_params: dict = None, @@ -252,7 +252,7 @@ def search(self, def query( self, collection_name: str, - filter: str = None, + filter: str, output_fields: List[str] = None, timeout: float = None, **kwargs @@ -431,16 +431,6 @@ def flush(self, collection_name, timeout=None, **kwargs): conn = self._get_connection() conn.flush([collection_name], timeout=timeout, **kwargs) - def _rewrite_schema_dict(self, schema_dict): - fields = schema_dict.get("fields", []) - if not fields: - return - - for field_dict in fields: - if field_dict.get("auto_id", None) is not None: - schema_dict["auto_id"] = field_dict["auto_id"] - return - def describe_collection(self, collection_name: str, **kwargs): conn = self._get_connection() try: @@ -449,9 +439,7 @@ def describe_collection(self, collection_name: str, **kwargs): except Exception as ex: logger.error("Failed to describe collection: %s", collection_name) raise ex - self._rewrite_schema_dict(schema_dict) - schema = CollectionSchema.construct_from_dict(schema_dict) - return schema.to_dict() + return schema_dict def list_collections(self, **kwargs): conn = self._get_connection() diff --git a/pymilvus/orm/collection.py b/pymilvus/orm/collection.py index 995848b03..c973bba11 100644 --- a/pymilvus/orm/collection.py +++ b/pymilvus/orm/collection.py @@ -117,6 +117,7 @@ def __init__(self, name: str, schema: CollectionSchema = None, using: str = "def if schema is None: raise SchemaNotReadyException(message=ExceptionsMessage.CollectionNotExistNoSchema % name) if isinstance(schema, CollectionSchema): + schema.verify() check_schema(schema) consistency_level = get_consistency_level(kwargs.get("consistency_level", DEFAULT_CONSISTENCY_LEVEL))