milvus-io / pymilvus

Python SDK for Milvus.
Apache License 2.0
989 stars 315 forks source link

[Bug]: FieldSchema.construct_from_dict() not support params max_length and dim #2046

Open james-gone opened 5 months ago

james-gone commented 5 months ago

Is there an existing issue for this?

Describe the bug

When dict hasmax_length or dim {'name': 'error_message', 'type': <DataType.VARCHAR: 21>, 'max_length': 1024} a_dict={'name': 'error_msg_vector', 'type': <DataType.FLOAT_VECTOR: 101>, 'dim': 768} When I new FieldSchema.construct_from_dict(a_dict), got

TypeError: pymilvus.orm.schema.FieldSchema() got multiple values for keyword argument 'max_length'

and

pymilvus.exceptions.MilvusException: <MilvusException: (code=65535, message=dimension is not defined in field type params, check type paramdimfor vector field)>

Expected Behavior

When I new FieldSchema.construct_from_dict(a_dict) no error.

Steps/Code To Reproduce behavior

fields_dict = [
    {'name': 'error_message', 'type': <DataType.VARCHAR: 21>, 'max_length': 1024},
    {'name': 'error_msg_vector', 'type': <DataType.FLOAT_VECTOR: 101>, 'dim': 768}
]
fields = []
for f_dict in fields_dict:
    fields.append(FieldSchema.construct_from_dict(f_dict))

Environment details

pymilvus==2.4.0

Anything else?

add below code at pymilvus/orm/schema.py can fix it. within def construct_from_dict(cls, raw: Dict):

371         if raw.get("max_length") is not None:
372             kwargs["max_length"] = raw.get("max_length")
373         if raw.get("dim") is not None:
374             kwargs["dim"] = raw.get("dim")
pymilvus orm schema py-construct_from_dict
sharathts14 commented 1 month ago

+1 I can confirm the same issue for "dim" parameter

here is the dict: image

and here is the converted FieldSchema using the FieldSchema.convert_from_dict(): image

this is with pymilvus==2.4.3