链载Ai

标题: 通过两个案例,看RAG如何解决大模型的“知识短板” [打印本页]

作者: 链载Ai    时间: 昨天 22:16
标题: 通过两个案例,看RAG如何解决大模型的“知识短板”

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.75px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">大模型和RAG一样,都是针对用户的问题,给出答复,那么,为什么有问题不直接问DeepSeek,还要跑一遍RAG?

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.75px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">RAG的出现,从根本上解决了大模型在处理知识时的一个核心痛点:如何高效、准确且低成本地利用那些未训练过的、私有的或最新的知识来回答问题。

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.75px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">如果我们希望大模型根据某些特定的知识内容生成答案,就必须将这些知识提供给模型。

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.75px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">似乎我们可以把这些知识全部发送给模型,但实际上并不可行

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.75px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">一方面,大模型本身的上下文长度有限,无法一次性处理大量内容

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.75px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">另一方面,即使上下文窗口未来不断扩大,每次提问都传入海量文档也会导致计算成本高昂、响应速度慢,并且可能引入无关信息干扰模型判断。

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.75px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">RAG通过“检索-增强-生成”的方式,针对用户的问题,系统首先在专用知识库中检索最相关的信息片段,仅将这些精选出的上下文传递给大模型。这样既克服了长度限制、降低了成本,也确保了模型作答的依据始终聚焦在我们提供的权威知识内。

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.75px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">同时,借助RAG的工作流设计,我们还可以控制大模型的思考路径,使其按照预设流程推理,而非随意发挥,进一步提升了回答的准确性与可靠性。

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.75px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">接下来,我们通过两个例子,详细介绍下如何用RAG实现信息聚焦和流程控制

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: 0.75px;orphans: 2;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">信息聚焦

举一个沟通问题的例子。

比如我和我的室友沟通不太顺畅,希望AI可以给我一些建议。我希望AI使用《非暴力沟通》这本书的知识来指导我的沟通。

于是我问deepseek

我的室友经常不收拾屋子,让我很烦躁,所以我跟他说:“你总是不收拾屋子,让我很烦躁”,室友听了后显得很生气并且没有什么改变,我应该怎么跟他沟通才能解决这个问题

很明显,AI虽然给出了回答,但是不是我想要的,因为我希望使用到《非暴力沟通》的知识

当然,如果在提示词中,直接说明需要使用《非暴力沟通》的知识回答,deepseep也可以给我们想要的答案,这是因为DeepSeek在训练过程中很可能学习过这本书的相关内容,所以它能理解并执行这个指令

但是实际业务中,可能AI的最初训练资料中没有相关知识,所以你即使指定所用知识,AI也是无法回答的

此时,我们引入了RAG,来看看AI的回答

我们使用coze搭建一个简单的RAG

在COZE中,创建知识库并上传知识内容时,COZE按照一定的规则,做出知识分块、向量化等操作,我们不需要太复杂的工序即可搭建一个RAG

这里是使用《非暴力沟通》的PDF版本上传后作为一个知识库,然后在Agent中调用这个知识库,让我们看看引入RAG后的回答

可以看到,我们使用了和给到deepseek相同的提示词,但是在这个回答中,AI给出的第一个回答正是按照书中观察、感受、需要、请求的四个要素给出沟通建议

当然,如果我们给deepseek的问题中,指定需要用非暴力沟通的方式作答,也是可以满足需求的

这是因为,当我没有指定用什么知识回答时,deepseek的知识范围是所有的训练内容,那就势必会让知识太过繁杂,导致无法按照我的预想回答。但是当我指定用非暴力沟通的知识回答时,deepseek也可以在他的训练知识中,提取这一块知识来回答

由此可以看出,当我们想要聚焦知识,或者有些知识不在大模型的初始训练知识内时,使用RAG,是一种实现目的的途径,将需要的信息整理到知识库内,通过知识库内的检索,让AI生成我们需要的答案

流程控制

仅仅让AI“知道”知识还不够,我们更需要它按照我们设定的专业流程来思考和工作,从而保证输出结果的高度一致性和专业性。这就是使用RAG的另一个强大能力——流程控制。

我们以一个非常实际的场景为例:一个自主研发的WMS(仓库管理系统)需要出海,所有界面、菜单、提示的文本都需要翻译成英文。

如果单纯靠人或直接让大模型翻译,会面临很多问题:

直接提问大模型:“请将‘入库订单’翻译成英文”,你可能会得到各种答案,因为它没有上下文。

而通过RAG,我们可以构建一个专业的翻译工作流,让AI像一支训练有素的本地化团队一样工作。

整体思路如下

  1. 构建知识库:我们创建三个核心知识库。






欢迎光临 链载Ai (https://www.lianzai.com/) Powered by Discuz! X3.5