milvus-io / milvus

A cloud-native vector database, storage for next generation AI applications
https://milvus.io
Apache License 2.0
30.32k stars 2.91k forks source link

[Bug]: [f16/bf16] Query failed with error "The length of fields data is inconsistent" when return "float16" and "bfloat16" vectors in output_fields #30437

Closed binbinlv closed 8 months ago

binbinlv commented 9 months ago

Is there an existing issue for this?

Environment

- Milvus version:master-20240129-74cfba02
- Deployment mode(standalone or cluster):both
- MQ type(rocksmq, pulsar or kafka):   all 
- SDK version(e.g. pymilvus v2.0.0rc2): 2.4.0rc26
- OS(Ubuntu or CentOS): 
- CPU/Memory: 
- GPU: 
- Others:

Current Behavior

Query failed with error "The length of fields data is inconsistent" when return "float16" and "bfloat16" vectors in output_fields

pymilvus.exceptions.MilvusException: <MilvusException: (code=1, message=The length of fields data is inconsistent)>

Expected Behavior

Return successfully

Steps To Reproduce

from pymilvus import CollectionSchema, FieldSchema
from pymilvus import Collection
from pymilvus import connections
from pymilvus import DataType
from pymilvus import Partition
from pymilvus import utility
import json

connections.connect()
dim = 128
int64_field = FieldSchema(name="int64", dtype=DataType.INT64, is_primary=True)
float_field = FieldSchema(name="float", dtype=DataType.FLOAT)
bool_field = FieldSchema(name="bool", dtype=DataType.BOOL)
float_vector = FieldSchema(name="float_vector", dtype=DataType.FLOAT_VECTOR, dim=dim)
float16_vector = FieldSchema(name="float16_vector", dtype=DataType.FLOAT16_VECTOR, dim=dim)
bfloat16_vector = FieldSchema(name="bfloat16_vector", dtype=DataType.BFLOAT16_VECTOR, dim=dim)

schema = CollectionSchema(fields=[int64_field, float_field, bool_field, float_vector, float16_vector, bfloat16_vector])
collection = Collection("test_search_collection_multiple_vector_type", schema=schema)

def gen_bf16_vectors(num, dim):
      raw_vectors = []
      bf16_vectors = []
      for _ in range(num):
            raw_vector = [random.random() for _ in range(dim)]
            raw_vectors.append(raw_vector)
            bf16_vector = tf.cast(raw_vector, dtype=tf.bfloat16).numpy().view(np.uint8).tolist()
            bf16_vectors.append(bytes(bf16_vector))
      return raw_vectors, bf16_vectors

def gen_fp16_vectors(num, dim):
       raw_vectors = []
       fp16_vectors = []
       for _ in range(num):
             raw_vector = [random.random() for _ in range(dim)]
             raw_vectors.append(raw_vector)
             fp16_vector = np.array(raw_vector, dtype=np.float16).view(np.uint8).tolist()
             fp16_vectors.append(bytes(fp16_vector))
       return raw_vectors, fp16_vectors

import random
nb=1000
vectors = [[random.random() for _ in range(dim)] for _ in range(nb)]

import numpy as np
import tensorflow as tf

vectors_16 = gen_fp16_vectors(nb, dim)[1]
bvectors_16 = gen_bf16_vectors(nb, dim)[1]
res = collection.insert([[i for i in range(nb)], [np.float32(i) for i in range(nb)], [np.bool_(i) for i in range(nb)], vectors, vectors_16, bvectors_16])
index_param = {"index_type": "IVF_FLAT", "metric_type": "L2", "params": {"nlist": 100}}
collection.create_index("float_vector", index_param, index_name="index_name_1")
collection.create_index("float16_vector", index_param, index_name="index_name_2")
collection.create_index("bfloat16_vector", index_param, index_name="index_name_3")
collection.load()
collection.query("int64 in [0,1]", output_fields=["float_vector"])
collection.query("int64 in [0,1]", output_fields=["float_vector", "float16_vector", "bfloat16_vector"])

Milvus Log

No response

Anything else?

No response

binbinlv commented 9 months ago

Not fixed with new issue:

Now it does not report error, but the field "float16_vector" and "bfloat16_vector" are not listed in the returned results: pymilvus: 2.4.0rc31 milvus: master-20240205-a68b3213

>>> collection.query("int64 in [0,1]", output_fields=["float_vector", "float16_vector", "bfloat16_vector"])
[{'float_vector': [0.067898646, 0.6537751, 0.1064326, 0.72655666, 0.90312254, 0.21895026, 0.8578442, 0.51587164, 0.92922384, 0.25443023, 0.055516567, 0.6918055, 0.8587836, 0.96352327, 0.6939025, 0.6917636, 0.31061912, 0.24955317, 0.07936109, 0.018123161, 0.33986127, 0.69696075, 0.58616644, 0.5603103, 0.7641, 0.40567777, 0.79543716, 0.68717325, 0.1278862, 0.40005356, 0.14040266, 0.3397046, 0.7384311, 0.4693918, 0.35419953, 0.26658964, 0.3137765, 0.91844386, 0.3561669, 0.6149103, 0.37238944, 0.7213047, 0.6123277, 0.4835878, 0.99284095, 0.12174162, 0.5885069, 0.29437768, 0.41805962, 0.6987165, 0.66241205, 0.50641924, 0.49187332, 0.11959157, 0.9463436, 0.3286032, 0.83258265, 0.928838, 0.23596363, 0.97590053, 0.80588615, 0.7822062, 0.99774593, 0.40287793, 0.67145616, 0.39697382, 0.6701566, 0.085967615, 0.82306266, 0.85071164, 0.06554007, 0.19037373, 0.20826711, 0.9203939, 0.760796, 0.22927848, 0.015402393, 0.9186892, 0.5572358, 0.1398247, 0.87400496, 0.26720607, 0.526786, 0.095469385, 0.11757149, 0.8905606, 0.46015397, 0.46012962, 0.36964417, 0.47440007, 0.034292575, 0.7252997, 0.92846215, 0.5584824, 0.1287122, 0.6330579, 0.18517299, 0.8423884, 0.62286484, 0.36662492, 0.79326487, 0.48027435, 0.42602724, 0.5056525, 0.06634856, 0.059910327, 0.22045736, 0.026341971, 0.5766262, 0.77045214, 0.34012783, 0.5378949, 0.40277374, 0.78138024, 0.91426134, 0.18295768, 0.048850108, 0.5610853, 0.6526337, 0.09511219, 0.38401738, 0.26999652, 0.44713914, 0.9834784, 0.072613336, 0.6303608, 0.0903195, 0.18936299], 'int64': 0}, {'float_vector': [0.48792458, 0.69131386, 0.83710384, 0.23612449, 0.087719604, 0.22933434, 0.59817564, 0.54737437, 0.29492277, 0.013977917, 0.6137499, 0.90370977, 0.059339885, 0.45219854, 0.69665784, 0.5922436, 0.3423792, 0.117825, 0.06947828, 0.76821184, 0.6032559, 0.77329075, 0.57619226, 0.7135675, 0.37365782, 0.9294166, 0.4914588, 0.22214462, 0.016423471, 0.8154335, 0.610812, 0.21616563, 0.43840626, 0.24783607, 0.81799006, 0.97883266, 0.5341333, 0.619588, 0.625051, 0.15276071, 0.9326382, 0.8070602, 0.47696865, 0.8819027, 0.18288748, 0.13088037, 0.43782133, 0.3241536, 0.2781209, 0.8585607, 0.63141304, 0.92108613, 0.16168986, 0.7621797, 0.37731218, 0.3468001, 0.21162875, 0.953326, 0.47670677, 0.090804026, 0.3186396, 0.69535774, 0.6853732, 0.0887579, 0.08690755, 0.92053634, 0.7579937, 0.2732637, 0.75233847, 0.36522672, 0.5347057, 0.9863599, 0.8603367, 0.91593426, 0.19804318, 0.4905036, 0.74302435, 0.56248456, 0.047452416, 0.037693843, 0.6359557, 0.6066885, 0.5017992, 0.9909501, 0.81459713, 0.49541813, 0.42644045, 0.17452863, 0.07182872, 0.073015735, 0.7105994, 0.51683074, 0.44058195, 0.25199112, 0.84951067, 0.20637806, 0.8001773, 0.4566286, 0.1914586, 0.87307626, 0.7631963, 0.7814723, 0.69139713, 0.5612664, 0.08980811, 0.21810031, 0.69327444, 0.85832304, 0.8643383, 0.5365127, 0.28677347, 0.44349408, 0.58875304, 0.4038952, 0.74423283, 0.8550544, 0.4565313, 0.09042108, 0.51059586, 0.4653071, 0.69438946, 0.7946394, 0.21072781, 0.7453167, 0.8372118, 0.24216166, 0.15109701, 0.8049329], 'int64': 1}]
binbinlv commented 8 months ago

It is verified and fixed.

milvus: master-20240218-99297ab8 pymilvus: 2.4.0rc35


>>> collection.query("int64 in [0,1]", output_fields=["float_vector", "float16_vector", "bfloat16_vector"])
[{'bfloat16_vector': [b'\x9d>\x0e?\xff=\xc7>\xaa>\x8b>=>q?\x04?J?(?\xea=\n?\x12?\xf2>M?\x1a?!>R?h>\x15?\xc3=\x96>\x0c?\x1c?\x8a>\x04>\x83>\xf3>\xdd>\xe3>\x17?\xfe>\r?@>\x01?\x8b=`???b?\x99>\xf6>p?\xb0>O>\x84>#?"? >0?\x8a>\xb8<7?2?\xe5>Z<h?>>\x86=\xf8>\x01>]>\xf7=\x8b>@>\xe6>$?\x03?\xe3>0?Z?\xfd>\xa2<D>x?\x0c?\xed>{?F?\x13?\xcf>\x0e>\n?o?p?9?\xb3>X?`?\xab=x?v<\xcf>\xd4=)?\xdb>\x1b?\x92>4>\xfd>G=\xa5<(>,?\x02?d?@>G?\xf4>\xa8>2?\xa6>\xae>M?5?j?9>t?G?\xb7>D?\xd8>\xf7>:>e?\xc8>3?\xdc>'], 'int64': 0, 'float_vector': [0.44343174, 0.79380274, 0.1629869, 0.3920443, 0.7609636, 0.22192374, 0.34577814, 0.44494075, 0.88796735, 0.4630435, 0.99171257, 0.8862286, 0.8126276, 0.44481534, 0.80804825, 0.01445279, 0.9641701, 0.22610068, 0.18214811, 0.49905726, 0.7360243, 0.6172675, 0.040557817, 0.3027805, 0.7888812, 0.16854872, 0.31218636, 0.043072704, 0.13917524, 0.79219234, 0.6509075, 0.63264453, 0.7385547, 0.41377145, 0.06309626, 0.65371174, 0.5733129, 0.15740393, 0.7749455, 0.44500658, 0.50671667, 0.04189888, 0.2612539, 0.022963097, 0.26418224, 0.80062586, 0.4082608, 0.16719107, 0.37961102, 0.6037835, 0.71595883, 0.8239435, 0.922075, 0.9439676, 0.17824246, 0.2204338, 0.44685742, 0.19982582, 0.86611015, 0.6579371, 0.91039425, 0.42385203, 0.15427531, 0.03833631, 0.19056758, 0.9331448, 0.9322096, 0.7237609, 0.8255441, 0.76605934, 0.78799427, 0.1272202, 0.571052, 0.8171005, 0.23173083, 0.08045048, 0.75969136, 0.5558589, 0.62861174, 0.42169678, 0.110966556, 0.564489, 0.029369222, 0.46244863, 0.12505972, 0.9436635, 0.3228835, 0.58745885, 0.008464835, 0.8418447, 0.13418628, 0.35261226, 0.76341355, 0.72483045, 0.7048148, 0.77527654, 0.7217443, 0.58537686, 0.44651663, 0.49732083, 0.9150854, 0.187922, 0.17393002, 0.76718825, 0.6995905, 0.6342701, 0.41647282, 0.4668389, 0.3234608, 0.13452987, 0.96444225, 0.9097989, 0.419171, 0.5620413, 0.87607664, 0.974655, 0.7485133, 0.42435667, 0.15616238, 0.953476, 0.6312298, 0.69644684, 0.75163525, 0.47547162, 0.8272304, 0.236214, 0.39212728, 0.59745425], 'float16_vector': [b'\x056\xd91j5-8K4\x7f9\x94:\x998M5\xd33\xbd3\x9b7,9\x85:\x833u7`4\xa4&\xf0:\xf8842\x824<4\x986X8\xb88\x12963\xdf:09E1\xc4:\x995\xf77d9/9R9\xef;\xfd+\xcc-\xe28t8\xab7p2m;\x89.&9}0\x069\xf6:\x985\x9b7y9\x11\x1f/:\x969\x9f8@6\x06:#6Y:\xe1:\xf54\x0e1\t;\xbd:I8\xc58\x7f9\xc87\xba,74k9\x028\xd06\x1e5.:\x16+<;\xe39\x928\xd26\x83;\xf5:\xaa769\xc25\xed4E:\x908\x8f/\x081\xc38\xca:\x0c9\x9e8\xe07\xe7;\xcf9m:O8\xd16\x185J215S7\x88.\x052I;\xe5%\xe14d8\x7f908\x1a5\xf41w;\xe31\xeb7\x992y,\xbf3\x8f6\x9c2\xba-\x8b9\x19\x13\xf94']}, {'bfloat16_vector': [b'?>\xe9=\xe1=\xc3>\x19?\xd9>\x02?J?a>U?s>\x04?\x00?6>\xbf>X?\r?\xc1>\x19>\xe2>M>W?\x8a=\x82=u?\x9d>\xfa>]?7?\xaa=\x81=\xe6=\x16?\xfe>\xdd;"?\x11?l?K?a?\x8d>\\?m?\xe8>\x1c?\x19?Q?\xbd>\x1a>n>\x1b?\xd1>I?A?Q?g?n?\x16?E;v;\xbb>e?;?n=\x15?B>\xf6>\x86={?\xad=r?\xfb<\xbc>P>\x80?U?\t?e?\xf1>{?\xdb="?\xf9=\xb5>\xe2:??]?6>\xfe>*?\xe7>\x04>}?\xb2<X?\x98> ?J?C>\xa5>e?g?[?\xb1=~?a?\x00?v?F?\xf5>y?_>G?o?\xb9>\xc6=\x10?\x11?(?\xb2>\xe5>\x0f>8?\x81>M?\xf8=V?8?'], 'int64': 1, 'float_vector': [0.5692847, 0.14553894, 0.10624101, 0.13219242, 0.23991731, 0.39581582, 0.793669, 0.8147318, 0.70285565, 0.7397233, 0.5667285, 0.8376893, 0.8081674, 0.57216346, 0.84590673, 0.67722374, 0.5474151, 0.13414901, 0.59306514, 0.65803677, 0.2896337, 0.9439134, 0.6054357, 0.16910304, 0.42830247, 0.12594663, 0.8308799, 0.26798934, 0.65855414, 0.7944002, 0.082321316, 0.3272942, 0.7457523, 0.88181704, 0.26998714, 0.91196907, 0.049529847, 0.041348603, 0.5709126, 0.28972155, 0.41989958, 0.29205662, 0.9451237, 0.34365666, 0.05570994, 0.56789625, 0.9394114, 0.94425696, 0.39289147, 0.8484996, 0.09169376, 0.0067429207, 0.74734277, 0.36365896, 0.86663413, 0.5464858, 0.4382591, 0.22660446, 0.63089156, 0.0861705, 0.09644979, 0.030965304, 0.5427153, 0.891653, 0.74792534, 0.38503438, 0.6493104, 0.6669306, 0.6269973, 0.34837, 0.73803043, 0.22676857, 0.904756, 0.38085786, 0.08664769, 0.38761893, 0.7373208, 0.4367795, 0.77300334, 0.9798679, 0.13416405, 0.8020676, 0.1666721, 0.7128197, 0.25171912, 0.620195, 0.6833917, 0.38335925, 0.91502416, 0.16938873, 0.41757533, 0.7769525, 0.6005946, 0.51989836, 0.85822105, 0.73013234, 0.43268475, 0.43078882, 0.24693882, 0.6670627, 0.12727979, 0.08787325, 0.9039376, 0.5451602, 0.62086093, 0.4376059, 0.4356106, 0.8742243, 0.19866416, 0.6612316, 0.17940927, 0.7166654, 0.6264155, 0.43759245, 0.2789872, 0.5432897, 0.139281, 0.2978051, 0.31638008, 0.24126859, 0.92057306, 0.47509462, 0.7091966, 0.7984668, 0.374018, 0.71963805, 0.46926066, 0.2610914], 'float16_vector': [b'46\xa9;w;64y;\xfd5\\1\xd2;--\xea9o7g;\x851x9\xbf"_2\x91:s9\xc79[7k;\xa71\xf88|5w1b8\x1c;\x97:X6 :P7\xc16).]5\xa66\xda2\xfd4\x17;\x1d6\x906\xf1:\x05:u78;\xc9;\x121p7b8\x03:v;\xe74\xb36~:\x0f;\xe74\xd4:\x163"9\x9c;\xe1.\xc81w9\xcc4\xa2:\xdf4\xcb.87k6\xbb4E3I8\xd2:(;a5\x8f7\x02:\x1c9\x071$1\x875\xa29,&\xec:\xb32\xa8:\x91/55D(\xa4,\xcb7\x108\xe8\'\xb47g.\xcd7\xf16~:m;23\xc28\x919\xc87d9\x1d2i4\x810%7\xd0;\xab:\x154\xca190y8\x9b8#;\xd09\xa32\xf61_4\xa4*\xb68X7P9H6n9@2\xd75`%']}]
``