milvus icon indicating copy to clipboard operation
milvus copied to clipboard

[Bug]: Create collection will fail using number for int8 field instead of numpy.int8

Open NicoYuan1986 opened this issue 1 year ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Environment

- Milvus version: master-20230530-b09e7aea
- Deployment mode(standalone or cluster): standalone
- MQ type(rocksmq, pulsar or kafka): rocksmq
- SDK version(e.g. pymilvus v2.0.0rc2): 2.4.0.dev56

Current Behavior

Create collection will fail using number for int8 field instead of numpy.int8. (int16, int32, float too)

RPC error: [create_collection], <MilvusException: (code=1, message=default value type mismatches field schema type: expected=DataType_Int64, actual=not match: invalid parameter)>, <Time:{'RPC start': '2023-05-30 15:31:40.255728', 'RPC error': '2023-05-30 15:31:40.271251'}>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/zilliz/virtual-environment/milvus2/lib/python3.10/site-packages/pymilvus/orm/collection.py", line 123, in __init__
    conn.create_collection(self._name, schema, **kwargs)
  File "/Users/zilliz/virtual-environment/milvus2/lib/python3.10/site-packages/pymilvus/decorators.py", line 109, in handler
    raise e
  File "/Users/zilliz/virtual-environment/milvus2/lib/python3.10/site-packages/pymilvus/decorators.py", line 105, in handler
    return func(*args, **kwargs)
  File "/Users/zilliz/virtual-environment/milvus2/lib/python3.10/site-packages/pymilvus/decorators.py", line 136, in handler
    ret = func(self, *args, **kwargs)
  File "/Users/zilliz/virtual-environment/milvus2/lib/python3.10/site-packages/pymilvus/decorators.py", line 85, in handler
    raise e
  File "/Users/zilliz/virtual-environment/milvus2/lib/python3.10/site-packages/pymilvus/decorators.py", line 50, in handler
    return func(self, *args, **kwargs)
  File "/Users/zilliz/virtual-environment/milvus2/lib/python3.10/site-packages/pymilvus/client/grpc_handler.py", line 252, in create_collection
    raise MilvusException(status.error_code, status.reason)
pymilvus.exceptions.MilvusException: <MilvusException: (code=1, message=default value type mismatches field schema type: expected=DataType_Int64, actual=not match: invalid parameter)>

Expected Behavior

create successfully

Steps To Reproduce

from pymilvus import CollectionSchema, FieldSchema, Collection, connections, DataType, Partition, utility
import numpy as np
import pandas as pd
import random
connections.connect()

# create collection
dim = 128
nb = 300
fields = [
    FieldSchema(name="pk", dtype=DataType.INT64, is_primary=True, description='pk'),
    FieldSchema(name="int8", dtype=DataType.INT8, default_value=8),
    # succeed: FieldSchema(name="int8", dtype=DataType.INT8, default_value=np.int8(8)),
    FieldSchema(name="float_vector", dtype=DataType.FLOAT_VECTOR, dim=dim),
]
schema = CollectionSchema(fields=fields)

collection = Collection("test_default_value", schema=schema)

Milvus Log

No response

Anything else?

No response

NicoYuan1986 avatar May 30 '23 07:05 NicoYuan1986

FieldSchema(name="float", dtype=DataType.FLOAT, default_value=float(3.1415)) -> report error FieldSchema(name="float", dtype=DataType.FLOAT, default_value=np.float32(3.1415)) -> ✅

NicoYuan1986 avatar May 30 '23 08:05 NicoYuan1986

Yes, this is as expected, when using float(), the type is float64, which is parsed as double when using milvus. The only thing we can do is to check is if we pass in more than the maximum value of this type, whether to report an error. @NicoYuan1986

smellthemoon avatar May 31 '23 08:05 smellthemoon

It's not an error.

NicoYuan1986 avatar Jun 08 '23 08:06 NicoYuan1986