The difference between Manhattan distance and Cosine Distance

news2024/10/6 14:36:40

题意:为什么即使返回了相同的文本块,曼哈顿距离(Manhattan Distance)和余弦距离(Cosine Distance)之间还是存在差异?

问题背景:

I am using the qdrant DB and client for embedding a document as part of a PoC that I am working on in building a RAG.

I see that when I use a Manhattan distance to build the vector collection I get a high score than when I use the Cosine distance. However, the text chunk returned is the same. I am not able to understand why and how? I am learning my ropes here at RAG still. Thanks in advance.

我注意到,当我使用曼哈顿距离来构建向量集合时,得到的分数比使用余弦距离时要高。然而,返回的文本块是相同的。我无法理解为什么会这样以及是如何发生的。我还在RAG这里学习相关知识。提前感谢。

USER QUERY        使用查询

What is DoS?

COSINE DISTANCE        余弦距离

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)
]

MANHATTAN DISTANCE                曼哈顿距离

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)
]

问题解决:

There are many different math functions that can be used to calculate similarity between two embedding vectors:

  • Cosine distance,                                余弦距离
  • Manhattan distance (L1 norm),         曼哈顿距离(Manhattan Distance,也称为L1范数)
  • Euclidean distance (L2 norm),          欧氏距离(Euclidean Distance,也称为L2范数)
  • Dot product,                                       点积(Dot Product)
  • etc.

Each calculates similarity in a different way, where:

每种方法都以不同的方式计算相似度,其中:

余弦距离测量两个非零向量之间夹角的余弦值。余弦距离对向量的方向敏感,而对向量的大小(模长)不那么敏感。

  • The Cosine distance measures the cosine of the angle between two non-zero vectors. The Cosine distance is sensitive to the direction of the vectors and is less sensitive to the magnitude.
  • The Manhattan distance measures the absolute difference between the corresponding elements of two vectors. The Manhattan distance is sensitive to the magnitude of the vectors.

曼哈顿距离测量两个向量对应元素之间的绝对差值。曼哈顿距离对向量的大小(模长)敏感。

  • The Euclidean distance measures the straight-line distance between two vectors.

欧氏距离测量两个向量之间的直线距离。

  • The Dot product measures the angle between two vectors multiplied by the product of their magnitudes.

点积测量两个向量之间的角度,并乘以这两个向量模长的乘积。

Consequently, the results of similarity calculations are different, where:

因此,相似度计算的结果是不同的,其中:

  • The Cosine distance is always in the range [0, 2]. 

余弦距离(实际上是1减去余弦相似度得到的值)总是在[0, 2]的范围内。

  • The Manhattan distance is always in the range [0, ∞).

曼哈顿距离总是在[0, ∞)的范围内。

  • The Euclidean distance is always in the range [0, ∞).

欧氏距离总是在[0, ∞)的范围内。

  • The Dot product is always in the range (-∞, ∞).

See the table below.

Measure 试题Range 范围Interpretation  解释

Cosine distance

余弦距离

[0, 2]

0 if vectors are the same, 2 if they are diametrically opposite.

如果向量相同则为0,如果它们完全相反则为2。

Manhattan distance

曼哈顿距离

[0, ∞)

0 if vectors are the same, increases with the sum of absolute differences.

如果向量相同则为0,随着绝对差值的和的增加而增加。

Euclidean distance

欧氏距离

[0, ∞)

0 if vectors are the same, increases with the sum of squared differences.

如果向量相同则为0,随着平方差的和的增加而增加。

Dot product

点积

(-∞, ∞)

Measures alignment, can be positive, negative, or zero based on vector direction.

测量对齐性,可以根据向量的方向为正、负或零。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1876466.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

探索LangChain-Chatchat 0.3:一体化Agent与强大RAG模型的全面入门指南

介绍 LangChain-Chatchat 支持RAG和Agent0.3版本跟大模型解耦,支持Xinference、Ollama、LocalAI、FastChat、One API,可以非常方便的切换各个模型,本文只是介绍XinferenceXorbits Inference (Xinference) 是一个开源平台,用于简化各种 AI 模型的运行和集成。借助 X…

论文辅导 | 基于贝叶斯优化-卷积神经网络-双向长短期记忆神经网络的锂电池健康状态评估

辅导文章 模型描述 准确估计电池健康状态是设备稳定运行的关键。针对当前健康状态研究中容量难以直接测量、估计模型调参费时等问题,提出基于多健康特征的贝叶斯优化(BO)算法优化卷积神经网络(CNN)与双向长短期记忆&a…

气膜仓库的优势与应用—轻空间

随着现代物流和存储需求的不断增长,传统仓库的建设和运营成本日益增加,企业需要寻找更加灵活、高效和经济的解决方案。在这种背景下,气膜仓库作为一种新型仓储形式,以其独特的优势和广泛的应用前景,逐渐受到市场的青睐…

视频号视频怎么保存到手机,视频号视频怎么保存到手机相册里,苹果手机电脑都可以用

随着数字媒体的蓬勃发展,视频已成为我们日常生活中不可或缺的一部分。视频号作为众多视频分享平台中的一员,吸引了大量用户上传和分享各类精彩视频。然而,有时我们可能希望将视频号上的视频下载下来,以下将详细介绍如何将视频号的视频。 方法…

自养号测评助力:亚马逊、沃尔玛电商高效测评补单技巧,轻松实现销量与补单双赢

要在竞争激烈的市场中通过测评补单的方式提升产品权重和销售,构建一个稳定且高效的测评补单系统至关重要。通过精心培养一批高质量的买家账号,并深入了解真实买家的行为数据,结合对风控数据的精准把控,我们能够自主推动推广进程&a…

shell:处理命令行参数 获取用户输入

1. 命令行参数 1.1 位置参数 bash shell会将一些称为位置参数(positional parameter)的特殊变量分配给输入到命令行中的 所有参数。这也包括shell所执行的脚本名称。位置参数变量是标准的数字:$0是程序名,$1是第 一个参数,$2是第二个参数,依…

【LLM 评估】MMLU benchmark:用于衡量 LM 的多任务语言理解能力

论文:Measuring Massive Multitask Language Understanding ⭐⭐⭐⭐ ICLR 2021, arXiv:2009.03300 Code: GitHub 论文速读 本文提出了一个 benchmark:MMLU,一个覆盖了 57 个 subjects 的多项选择题的数据集。 数据集的 question 数量&…

SpringBoot-SpringBoot中文文档

简介 Spring Boot是由Pivotal团队提供的一套开源框架,可以简化spring应用的创建及部署。它提供了丰富的Spring模块化支持,可以帮助开发者更轻松快捷地构建出企业级应用。Spring Boot通过自动配置功能,降低了复杂性,同时支持基于J…

设计模式 - Observer Pattern 观察者模式

文章目录 定义观察者模式的实现构成构成UML图 观察者模式的代码实现场景代码实现 总结优点缺点应用场景 其他设计模式文章: 定义 观察者模式是行为型模式的一种,它定义对象间的一种一对多的依赖关系,使得每当一个对象改变状态,它…

Apache HBase概述(图文并茂~)

HBase概述 1. Why we need HBase ? 在大数据时代来临之前,我们通常依赖传统的关系型数据库(如RDBMS)来处理数据存储和管理。然而,随着数据量的急剧增长和数据结构的多样化,传统数据库系统开始显露出其局限性…

手写一个基于SpringBoot的MVC架构,默认实现CRUD和导入导出功能

文章目录 前言正文一、项目结构二、技术点三、部分核心代码3.1 core-tool 中的核心代码3.1.1 所有实体的通用父类 SuperEntity3.1.2 所有枚举的父接口 BaseEnum3.1.3 所有业务异常的父接口 BaseException 3.2 mvc-tool 中的核心代码3.2.1 CrudController 接口定义3.2.2 默认的C…

文心一言 VS 讯飞星火 VS chatgpt (290)-- 算法导论21.3 3题

三、给出一个包含 m 个 MAKE-SET 、UNION 和 FINDSET 操作的序列(其中有 n 个是 MAKE-SET 操作),当仅使用按秩合并时,需要 Ω(mlgn) 的时间。如果要写代码,请用go语言。 文心一言: 在并查集(Union-Find)数…

STM32使用PWM驱动WS2812_RGB灯珠

项目场景: 使用STM32标准库产生PWM实现RGB灯珠控制。 芯片型号:stm32f405rgt6 设计优点:不需要使用定时器中断资源,可以使得STM32在驱动RGB灯珠的同时能够执行其他任务。 RGB灯珠简介 项目所使用的RGB灯珠如下所示,封装…

76. UE5 RPG 实现场景阻挡剔除功能

在俯视角游戏中,我们总会碰到一个问题就是,建筑会遮挡住角色的问题。遇到这种问题有多种解决方案,厂商经常使用的一种方案是,如果角色被遮挡,则使用一种纯色或者增加一些菲涅尔的效果来实现 这种效果我之前在unity内实…

免费使用文心一言会员教程

领取&安装链接:Baidu Comate 领取季卡 有图有真相 原理:百度comate使用文心一言最新的4.0模型。百度comate目前免费使用,可以借助comate达到免费使用4.0模型目的。 如何获得 点击「Baidu Comate 领取季卡 -> 领取权益」&#xff0…

Cesium Model 中的剪裁平面 (ClippingPlane)

Cesium Model 中的剪裁平面 (ClippingPlane) 参考: https://www.cnblogs.com/webgl-angela/p/9197672.html Cesium Model 中的剪裁平面 (ClippingPlane) // 相关类: class ClippingPlaneCollection {} class ClippingPlane {}// 剪裁的整体流程: Model.prototype.update () …

Mathematica训练课(45)-- 一些常用的函数Abs[],Max[]等函数用法

①绝对值函数:Abs[]函数 ②最大值和最小值函数 ③反函数

SAP ATP可用性检查简介

Availability Check,就是可用性检查,指的是要检查一下此物料是否能满足我的需求。 接到一张销售订单(SALES ORDER),客户要求数量为100PC,并且客户要求的出货日期是2024-07-01,此时我们的销售人员肯定会想到底能否出货给客人呢?系统中建立此单时,SAP就会做一个所谓的检…

实验八 T_SQL编程

题目 以电子商务系统数据库ecommerce为例 1、在ecommerce数据库,针对会员表member首先创建一个“呼和浩特地区”会员的视图view_hohhot,然后通过该视图查询来自“呼和浩特”地区的会员信息,用批处理命令语句将问题进行分割,并分…

17859划分准则小结

17859《划分准则》 发布时间:1999.9.13 实施时间:2001.1.1 计算机信息系统安全保护能力的五个等级: 第一级:用户自主保护级 第二级…