稀疏向量的格式
你好,我正在用bge-m3生成的稀疏向量想对接qdrant数据库(我了解官方已有两个其他数据库的对接教程) 生成的稀疏向量格式类似这样
{
'\u8fd9': 0.1641845703125,
'\u4ef6': 0.246826171875,
'\u7684\u65f6\u5019': 0.0863037109375,
'\u90a3\u4e48': 0.08343505859375,
'\u4e5f\u5c31': 0.099853515625,
'\u2581\u5f53': 0.084716796875,
'\u60a8': 0.158203125,
'\u770b\u5230': 0.1983642578125,
'\u7684': 0.0579833984375,
'\u800c': 0.033172607421875,
'\u4e5f': 0.108154296875,
'\u8131': 0.255126953125,
'\u4e16\u754c': 0.1624755859375,
'\u4fe1': 0.1903076171875,
'\u8bf4\u660e': 0.1806640625,
'\u5df2\u7ecf': 0.1983642578125,
'\u83b7\u5f97\u4e86': 0.1982421875,
'\u6811': 0.261474609375,
'\u8ba1\u5212': 0.2431640625,
'\u5706\u6ee1': 0.22802734375,
'\u7684\u6210\u529f': 0.224609375,
'\u5c01': 0.1810302734375,
'\u6700\u540e': 0.213134765625,
'\u8d85': 0.14404296875,
}
qdrant官方文档说明的稀疏向量传参是这样的: https://qdrant.tech/documentation/concepts/points/
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 0.0, 0.0] can be represented as a sparse vector:
[(6, 1.0), (7, 2.0)] Qdrant uses the following JSON representation throughout its APIs.
{
"indices": [6, 7],
"values": [1.0, 2.0]
}
The indices and values arrays must have the same length. And the indices must be unique.
但是注意到bge-m3生成的稀疏向量的键值对的key是字符串格式的,即原本文本的分词作为key 上面的indices是key的数组吧?它是number[]格式的
请问怎样把bge-m3生成的稀疏向量,变成qdrant要求的格式呢(为什么key是字符串的)
谢谢!
好像有点了解了 output_1 = model.encode(sentences_1, return_dense=True, return_sparse=True, return_colbert_vecs=False) output_1['lexical_weights'])是我需要的数据 model.convert_id_to_token(output_1['lexical_weights'])是类似上面的id转token的格式对吗~
好像有点了解了 output_1 = model.encode(sentences_1, return_dense=True, return_sparse=True, return_colbert_vecs=False) output_1['lexical_weights'])是我需要的数据 model.convert_id_to_token(output_1['lexical_weights'])是类似上面的id转token的格式对吗~
Yes