«

快来看,n8n更新了!评估RAG,即优化中的优化

qimuai 发布于 阅读:9 一手编译


快来看,n8n更新了!评估RAG,即优化中的优化

内容来源:https://blog.n8n.io/evaluating-rag-aka-optimizing-the-optimization/

内容总结:

尽管检索增强生成(RAG)技术被广泛视为优化大语言模型(LLM)的关键方案,但其在实际应用中仍存在生成内容与检索信息不符或缺乏依据的问题。例如,某物流企业分析师询问内部AI助手第二季度业绩时,系统虽正确检索到营收下降15%的数据,却擅自将原因归结为苏伊士运河堵塞——这一解释在原始报告中并不存在。

研究表明,RAG的幻觉问题可分为四类:明显矛盾(与检索内容直接冲突)、隐性矛盾(语义层面偏离)、明显虚构(添加无依据信息)和隐性虚构(引入主观推断)。为解决这些问题,需从两大维度评估RAG系统:一是文档相关性(确保检索信息准确完整),二是答案可信度(保证回答与检索内容一致)。

目前业界普遍采用Ragas评估框架,通过上下文召回率和精确度衡量检索质量,同时使用忠实性和响应相关性验证生成内容。值得注意的是,即使生成了正确答案,若其未基于检索内容而依赖模型先验知识,仍被视为幻觉。

自动化工作流平台n8n已内置RAG评估功能,无需调用外部库即可实现:通过"使用OpenAI评估RAG响应准确性"工作流模板检测生成内容与文档的契合度,利用上下文召回工作流量化检索效能。用户可通过测试数据集对比多轮运行结果,精准定位优化方向。

(注:苏伊士运河堵塞案例仅为技术演示,与实际事件无关)

中文翻译:

检索增强生成(RAG)常被视为优化大语言模型(LLM)的首选方案。但即便在智能代理系统中整合了RAG技术,LLM仍可能提出与检索内容相悖或缺乏依据的论断。

以某物流企业的商业分析师使用基于RAG的内部AI助手查询财务报告为例。当询问"我们第二季度业绩如何"时,助手回复:"受苏伊士运河堵塞事件导致的供应链中断影响,我们Q2营收较Q1下降15%。"虽然系统准确检索到财务报告中15%的营收降幅,却擅自将原因归结于苏伊士运河堵塞——这一解释在原始资料中并无记载。

文档检索并不保证信息准确性,因此RAG本身需要优化。这意味着需调整搜索机制以返回更精准的结果(减少干扰信息),并确保LLM响应与检索上下文保持一致。

本文将探讨RAG系统为何会产生幻觉现象,介绍基于Ragas框架的评估体系,最后演示如何在n8n平台实施RAG评估。

四大RAG幻觉类型

在RAG语境下,幻觉的定义略有不同:当LLM未基于检索到的文本数据生成内容,而是依赖预训练知识产出时,即被视为幻觉。Vectara团队(HHEM评估模型创建者)举例说明:若检索上下文显示"法国首都是柏林",而LLM输出"法国首都是巴黎",虽然后者事实正确,但仍属幻觉响应。

根据《RAGTruth》论文,RAG特异性幻觉可分为四类:

双支柱RAG评估框架

优质RAG实施方案应验证两个维度:

当前主流工具多采用Ragas库提供的专项评估功能。下文将基于该库展开说明:

RAG文档相关性:精准检索语境
上下文召回率评估衡量成功检索相关文档的比例,高召回率意味着遗漏相关文档更少。上下文精确度则评估检索结果中相关文本块的比例。计算召回率需始终依赖参照基准。

召回率与精确度可通过LLM裁判或确定性算法计算:

RAG答案可靠性:响应与上下文一致性
忠实度评估响应与检索上下文的事实一致性。若所有主张均能得到上下文支持,则视为可信响应。Vectara的HHEM-2.1-Open开源分类模型可检测LLM生成文本的幻觉,通过主张与上下文的交叉验证判断推断合理性。

响应相关度衡量应答与用户问题的关联程度。直接恰当回应原始问题的答案被视为相关,该指标专注答案与问题意图的匹配度(不涉及事实准确性),会对不完整或含冗余信息的答案扣分。

n8n平台的RAG评估
无需外部库或接口调用,n8n原生支持RAG性能评估:

"使用OpenAI评估RAG响应准确性"工作流模板通过LLM驱动的响应相关度评估,检测应答是否基于检索文档。高分表示LLM遵循上下文,低分可能提示指令缺陷或模型幻觉。

RAG文档相关性工作流采用LLM驱动的上下文召回率计算检索得分,判定工作流性能表现。

如需深入了解n8n评估功能,请参阅《AI工作流评估功能发布》技术博客及评估节点技术文档。

英文来源:

Retrieval augmented generation is often positioned as the go-to solution for optimizing LLMs. But despite the integration of RAG in agentic systems, LLMs may still present unsupported or contradictory claims to the retrieved contents.
Imagine a business analyst at a logistics company using an internal AI assistant powered by RAG to interact with financial reports. When the analyst asks, “What is our Q2 performance?”, the assistant responds: “Our Q2 revenue decreased by 15% compared to Q1 due to supply chain disruptions following the Suez Canal blockage.”
While the system correctly retrieved the financial report, noting a 15% revenue drop, it fabricated a justification by attributing the decline to the Suez Canal blockage—an explanation not present in the source material.
Retrieving documents doesn’t guarantee accuracy, so RAG itself must be optimized. This means tuning the search to return the right results, including less noise, and aligning the LLM response with the context retrieved.
That’s why in this article, we’ll discuss how RAG systems can still hallucinate, and provide a framework for evaluating RAG applications using the Ragas framework. Lastly, we’ll present how to implement RAG evaluations in n8n.
Four types of RAG hallucinations
Hallucinations have a slightly different definition in the context of RAG. We use the term to indicate a response is not supported by or aligned with the retrieved context. It is considered a hallucination when the LLM does not generate content based on the textual data provided to it as part of the RAG retrieval process, but rather generates content based on its pre-trained knowledge.
Vectara, the creators of the HHEM evaluation models, give the following example: if the retrieved context states "The capital of France is Berlin", and the LLM outputs "The capital of France is Paris", then the LLM response is hallucinated, despite it being correct.
We can categorize RAG-specific hallucinations into four categories, as described in the paper titled RAGTruth:

n8n

文章目录


    扫描二维码,在手机上阅读