Skip to content

Commit

Permalink
Fix some bugs: describe_collection return dict and query filter param…
Browse files Browse the repository at this point in the history
…eter (#1526)

Signed-off-by: zhenshan.cao <[email protected]>
  • Loading branch information
czs007 authored Jun 9, 2023
1 parent f380083 commit d3b98ca
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
28 changes: 23 additions & 5 deletions pymilvus/client/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 {}
Expand All @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions pymilvus/client/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
18 changes: 3 additions & 15 deletions pymilvus/milvus_client/milvus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions pymilvus/orm/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit d3b98ca

Please sign in to comment.