赞
踩
//创建集合 ... //设置向量字段 FieldType fieldType = FieldType.newBuilder() .withName("feature") .withDataType(DataType.BinaryVector) .withDimension(8256) .build(); ... // 获取数据 byte[] featureData= ...; // 转换数据 ByteBuffer byteBuffer = ByteBuffer.wrap(featureData); // 注意这里修改position,不然会报错 byteBuffer.position(byteBuffer.capacity()); // 插入准备 List<ByteBuffer> vector = new ArrayList<>(); vector.add(byteBuffer); List<InsertParam.Field> fields = new ArrayList<>(); fields.add(new InsertParam.Field("feature",vector)); // 插入数据 InsertParam insertParam = InsertParam.newBuilder() .withCollectionName(collection_name) .withFields(fields) .build(); R<MutationResult> mutationResultR = milvusClient.insert(insertParam);
ByteBuffer byteBuffer = ByteBuffer.wrap(featureData);
这段代码转换时,position被默认设置为0,因此加入byteBuffer.position(byteBuffer.capacity());
修改position值Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。