milvus插入数据时,明明不超长,但总是报长度错误?

在处理插入milvus数据时,设置了字段长度为512. 明明考虑了预留,插入的数据中没有这么长的,但还是会有报错 类似:MilvusException: (code=0, message=the length (564) of 78th string exceeds max length (512)

查找max(len(x) for x in temp_list)之类 都没有超过512过,也没超过256过,不知道哪里的数据有问题..

反复截段文本等测试后发现,例如用len(x)看到的字符串长度是10,但保存进milus的长度,并不是..

举例,把数据库长度设为一个小值16:

FieldSchema(name="question", dtype=DataType.VARCHAR, auto_id=False, max_length=16)

再把数据缩到只有一行 测试结果插入成功:

line contents is : 你好呀你好 and length is 5

Batches: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:01<00:00, 1.02s/it]

index handle result: Status(code=0, message=)

insert result: (insert count: 1, delete count: 0, upsert count: 0, timestamp: 449735609509740549, success count: 1, err count: 0)

再增加一点文字长度 就报错了:

line contents is : 你好呀你好呀 and length is 6

Batches: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 1.03it/s]

index handle result: Status(code=0, message=)

2024-05-13 20:59:27,915 decorators.py:134 ERROR\] RPC error: \[batch_insert\], \, \ Traceback (most recent call last): File "/root/temp_dir/run_task.py", line 55, in \ XXX().create_insert_vector_db() File "/root/temp_dir/app/service/vector_db/xx_pre_handle.py", line 63, in create_insert_vector_db ).get_or_create_db(fields, description, "possible_question_embeddings", entities) File "/root/temp_dir/app/service/vector_db/milvus_db.py", line 23, in get_or_create_db return self.create_and_insert(fields, description, index_field_name, entities) File "/root/temp_dir/app/service/vector_db/milvus_db.py", line 28, in create_and_insert self.insert_db(entities) File "/root/temp_dir/app/service/vector_db/milvus_db.py", line 40, in insert_db insert_result = self.collection.insert(entities) File "/root/tmp/venv_dir/1_text_simi/lib/python3.10/site-packages/pymilvus/orm/collection.py", line 497, in insert res = conn.batch_insert( File "/root/tmp/venv_dir/1_text_simi/lib/python3.10/site-packages/pymilvus/decorators.py", line 135, in handler raise e from e File "/root/tmp/venv_dir/1_text_simi/lib/python3.10/site-packages/pymilvus/decorators.py", line 131, in handler return func(\*args, \*\*kwargs) File "/root/tmp/venv_dir/1_text_simi/lib/python3.10/site-packages/pymilvus/decorators.py", line 170, in handler return func(self, \*args, \*\*kwargs) File "/root/tmp/venv_dir/1_text_simi/lib/python3.10/site-packages/pymilvus/decorators.py", line 110, in handler raise e from e File "/root/tmp/venv_dir/1_text_simi/lib/python3.10/site-packages/pymilvus/decorators.py", line 74, in handler return func(\*args, \*\*kwargs) File "/root/tmp/venv_dir/1_text_simi/lib/python3.10/site-packages/pymilvus/client/grpc_handler.py", line 566, in batch_insert raise err from err File "/root/tmp/venv_dir/1_text_simi/lib/python3.10/site-packages/pymilvus/client/grpc_handler.py", line 560, in batch_insert check_status(response.status) File "/root/tmp/venv_dir/1_text_simi/lib/python3.10/site-packages/pymilvus/client/utils.py", line 54, in check_status raise MilvusException(status.code, status.reason, status.error_code) pymilvus.exceptions.MilvusException: \ 所以,可能是因为UTF-8或其他编码的原因,一些非ASCII字符可能被编码成多个字节 以保存进milvus。 所以,解决方案是 建表时FieldSchema中把max_length 设置为4倍或其他倍数于预期的最大长度。

相关推荐
兴科Sinco14 小时前
[leetcode 1]给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出和为目标值 target 的那两个整数[力扣]
python·算法·leetcode
程序员奈斯14 小时前
Python深度学习:NumPy数组库
python·深度学习·numpy
yongche_shi14 小时前
第二篇:Python“装包”与“拆包”的艺术:可迭代对象、迭代器、生成器
开发语言·python·面试·面试宝典·生成器·拆包·装包
深度学习lover14 小时前
<数据集>yolo梨幼果识别数据集<目标检测>
python·yolo·目标检测·计算机视觉·数据集
刀客12314 小时前
测试之道:从新手到专家实战(四)
python·功能测试·程序人生·测试用例·集成测试·学习方法·安全性测试
mit6.82414 小时前
[rStar] 解决方案节点 | `BaseNode` | `MCTSNode`
人工智能·python·算法
这里有鱼汤14 小时前
低价股的春天来了?花姐用Python带你扒一扒
后端·python
Elastic 中国社区官方博客14 小时前
介绍 Python Elasticsearch Client 的 ES|QL 查询构建器
大数据·开发语言·数据库·python·elasticsearch·搜索引擎·全文检索
独行soc15 小时前
2025年渗透测试面试题总结-60(题目+回答)
java·python·安全·web安全·adb·面试·渗透测试
haveyb15 小时前
python版本管理和依赖管理的最佳实践,pyenv + uv
python·virtualenv·pip·uv·pyenv