You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何使用曼哈顿距离与余弦距离返回相同文本块但得分不同?

Qdrant中曼哈顿/余弦距离得分差异但返回结果一致的原因分析

问题背景

我正在构建RAG的PoC,使用Qdrant数据库及客户端进行文档嵌入。发现用曼哈顿距离构建向量集合时,查询得分高于余弦距离,但返回的文本块完全相同,对此原因存在疑问。

查询与响应示例

用户查询

What is DoS?

余弦距离响应

response: [
ScoredPoint(id=0, 
version=10, 
score=0.17464592, 
payload={
'chunk': "It also includes overhead bytes for operations, 
administration, and maintenance (OAM) purposes.\nOptical Network Unit 
(ONU)\nONU is a device used in Passive Optical Networks (PONs). It converts 
optical signals transmitted via fiber optic cables into electrical signals that 
can be used by end-user devices, such as computers and telephones. The ONU is 
located at the end user's premises and serves as the interface between the optical 
network and the user's local network."
}, 
vector=None, shard_key=None)
]

曼哈顿距离响应

response: [
ScoredPoint(id=0, 
version=10, 
score=103.86209, 
payload={
'chunk': "It also includes overhead bytes for operations, administration, 
and maintenance (OAM) purposes.\nOptical Network Unit 
(ONU)\nONU is a device used in Passive Optical Networks (PONs). It converts 
optical signals transmitted via fiber optic cables into electrical signals that 
can be used by end-user devices, such as computers and telephones. The ONU is 
located at the end user's premises and serves as the interface between the optical 
network and the user's local network."
}, 
vector=None, shard_key=None)
]

原因解析

  1. 唯一匹配结果限制
    你的向量集合中仅存在这一个与查询向量最接近的文档块(id=0),无论采用哪种距离算法,它都是当前数据集中的最优匹配项,因此返回结果必然一致。另外注意:查询是关于DoS的问题,但返回的是ONU相关内容,说明集合中根本没有DoS相关文档,只能返回现有数据里最接近的条目。

  2. 两种距离的得分体系差异

  • 余弦距离:Qdrant中采用1 - 余弦相似度作为得分,范围通常在[0,2]之间,得分越低代表相似度越高。这里的0.1746说明该文档块与查询的相似度很高。
  • 曼哈顿距离(L1距离):得分是向量各维度差值的绝对值之和,没有固定范围,数值取决于向量维度和取值规模,得分越高代表向量差异越大。这里的103.86是该距离的直接计算值,反映的是向量间的绝对差异程度。

两者得分的含义完全不同,不能直接通过数值大小判断匹配度高低,需结合各自的规则解读。

内容的提问来源于stack exchange,提问作者raikumardipak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 01:05:02