从Naive RAG到Agentic RAG:基于Milvus构建Agentic RAG

news2024/10/25 15:36:45

78918befa51d30bf37a1f3ec3ede020b.png

3544b4b972c9bf99969f8ec649aac375.png

检索增强生成(Retrieval-Augmented Generation, RAG)作为应用大模型落地的方案之一,通过让 LLM 获取上下文最新数据来解决 LLM 的局限性。典型的应用案例是基于公司特定的文档和知识库开发的聊天机器人,为公司内部人员快速检索内部文档提供便利。另外,也适用于特定领域的GenAI应用,如医疗保健、金融和法律服务。尽管Naive RAG在处理简单问题时表现良好,但在面对复杂任务时却显得力不从心。本文将探讨Naive RAG的局限性,并介绍如何通过引入代理(Agentic)方法来提升RAG系统的智能性和实用性。

01.

Naive RAG的局限性

Naive RAG方法在处理简单问题时表现良好,例如:

  • “特斯拉的主要风险因素是什么?”(基于特斯拉2021年10K报告)

  • “Milvus 2.4有哪些功能?”(基于Milvus 2.4 release note)

然而,当面对更复杂的问题时,Naive RAG的局限性就显现出来了。

  • 总结性问题:例如,“给我一个公司10K年度报告的总结”,Naive RAG难以在不丢失重要信息的情况下生成全面的总结。

  • 比较性问题:例如,“Milvus 2.4 与Milvus 2.3 区别有哪些”,Naive RAG难以有效地进行多文档比较。

  • 结构化分析和语义搜索:例如,“告诉我美国表现最好的网约车公司的风险因素”,Naive RAG难以在复杂的语义搜索和结构化分析中表现出色。

  • 一般性多部分问题:例如,“告诉我文章A中的支持X的论点,再告诉我文章B中支持Y的论点,按照我们的内部风格指南制作一个表格,然后基于这些事实生成你自己的结论”,Naive RAG难以处理多步骤、多部分的复杂任务。

02.

Naive RAG上述痛点的原因
  • 单次处理:Naive RAG通常是一次性处理查询,缺乏多步骤的推理能力。

  • 缺乏查询理解和规划:Naive RAG无法深入理解查询的复杂性,也无法进行任务规划。

  • 缺乏工具使用能力:Naive RAG无法调用外部工具或API来辅助完成任务。

  • 缺乏反思和错误纠正:Naive RAG无法根据反馈进行自我改进。

  • 无记忆(无状态):Naive RAG无法记住对话历史,无法在多轮对话中保持上下文一致性。

03.

从RAG到Agentic RAG

为了克服Naive RAG的局限性,我们可以引入代理方法(Agentic),使RAG系统更加智能和灵活。

  • 路由

    • 路由是最简单的代理推理形式。给定用户查询和一组选择,系统可以输出一个子集,将查询路由到合适的处理模块。

  • 工具

    • 调用外部工具或API来辅助完成任务。比如,使用查询天气接口来获取最新的天气信息。

  • 查询/任务规划

    • 将查询分解为可并行处理的子查询。每个子查询可以针对任何一组RAG管道执行,从而提高处理效率和准确性。

  • 反思

    • 使用反馈来改进代理的执行并减少错误,反馈可以来自LLM自身。

  • 记忆

    • 除了当前查询外,还可以将对话历史作为输入,纳入RAG管道中,从而在多轮对话中保持上下文一致性。

04.

实践

我们基于Milvus,LlamaIndex构建一个Agentic RAG案例。

首先,我们把Milvus 2.3 和 2.4 release note文档,通过LlamaIndex SentenceWindowNodeParser分段之后,导入到Milvus。

node_parser = SentenceWindowNodeParser.from_defaults(
    window_size=3,
    window_metadata_key="window",
    original_text_metadata_key="original_text",
)

# Extract nodes from documents
nodes = node_parser.get_nodes_from_documents(documents)

vector_store = MilvusVectorStore(dim=1536, 
                                 uri="http://localhost:19530",
                                 collection_name='agentic_rag',
                                 overwrite=True,
                                 enable_sparse=False,
                                 hybrid_ranker="RRFRanker",
                                 hybrid_ranker_params={"k": 60})

storage_context = StorageContext.from_defaults(vector_store=vector_store)

index = VectorStoreIndex(
    nodes, 
    storage_context=storage_context
)

然后,我们定义两个agent tool,他们分别是vector query tool 和summary tool。vector query tool利用了Milvus Hybrid search能力。summary tool采用了 LlamaIndex的 SummaryIndex 对于文档块提取summary。

def vector_query(
    query: str,
    page_numbers: Optional[List[int]] = None
) -> str:
    # The target key defaults to `window` to match the node_parser's default
    postproc = MetadataReplacementPostProcessor(
                target_metadata_key="window"
            )
    # BAAI/bge-reranker-base is a cross-encoder model
    # link: https://huggingface.co/BAAI/bge-reranker-base
    rerank = BGERerankFunction(
                top_n = 3, 
                model_name = "BAAI/bge-reranker-base",
                device="cpu"
                )

    # The QueryEngine class is equipped with the generator and facilitates the retrieval and generation steps
    query_engine = vector_index.as_query_engine(
                        similarity_top_k = 3, 
                        vector_store_query_mode="hybrid",  # Milvus starts supporting from version 2.4, use 'Default' for versions before 2.4
                        node_postprocessors = [postproc, rerank],
                    )

    response = query_engine.query(query)
    return response


vector_query_tool = FunctionTool.from_defaults(
    name=f"vector_tool_{name}",
    fn=vector_query
)
summary_index = SummaryIndex(nodes)
summary_query_engine = summary_index.as_query_engine(
    response_mode="tree_summarize",
    use_async=True,
)
summary_tool = QueryEngineTool.from_defaults(
    name=f"summary_tool_{name}",
    query_engine=summary_query_engine,
    description=(
        f"Useful for summarization questions related to {name}"
    ),
)

最后,通过LlamaIndex的ReActAgentWorker整合vector query tool 和summary tool,以及React的特性,反思,路由以及使用工具能力,实现Agentic RAG。

response = agent.query(
    "Tell me about the difference between milvus 2.3 and milvus 2.4?"
)

这是对于上述问题的思考过程,包括React的观察,思考,行动具体步骤。

Thought: The user is asking about the differences between Milvus 2.3 and Milvus 2.4. I need to gather information about both versions to provide a comprehensive comparison.
Action: vector_tool_milvus_2_3
Action Input: {'query': "What's new in Milvus 2.3?"}
Thought: It appears there is a persistent issue with the tool input. I will try using a different tool to gather the necessary information.
Action: summary_tool_milvus_2_3
Action Input: {'input': "What's new in Milvus 2.3?"}
Observation: Milvus 2.3 introduces several new features and enhancements, including GPU support, Arm64 support, a refactored QueryNode, and a merged IndexCoord and DataCoord for simplified deployment. It also includes a new NATS-based message queue, upsert API, range search, count statement, cosine metrics, raw vectors in search returns, ScaNN index support, iterator functionality, JSON_CONTAINS expressions, and CDC support. Additionally, there are performance improvements such as MMap for capacity increase, optimized data filtering, growing index, and increased resource usage in multi-core environments. The release also features a new load balancer, dynamic configuration support, tracing support, reorganized error codes, and upgraded tools like Birdwatcher and Attu.
Thought: I have gathered information about the new features and enhancements in Milvus 2.3. Now, I need to gather similar information for Milvus 2.4 to compare the two versions.
Action: summary_tool_milvus_2_4
Action Input: {'input': "What's new in Milvus 2.4?"}
Observation: Milvus 2.4 introduces several new features and improvements. Key highlights include:
...
These updates aim to enhance system performance, improve observability, and streamline the codebase for increased simplicity.
Thought: I now have detailed information about the new features and enhancements in both Milvus 2.3 and Milvus 2.4. I can compare the two versions based on these details.

输出的答案,从答案来看,不仅详细列举了Milvus 2.3 和Milvus 2.4各种功能特性,还有功能总结与对比。

Answer: Milvus 2.3 and Milvus 2.4 both introduce significant new features and improvements, but they focus on different aspects of the system. Here are the key differences:

### Milvus 2.3:
1. **GPU and Arm64 Support**: Introduces GPU support and Arm64 support.
2. **Refactored QueryNode**: Simplifies deployment by merging IndexCoord and DataCoord.
3. **New Message Queue**: Implements a NATS-based message queue.
4. **New APIs and Features**: Includes upsert API, range search, count statement, cosine metrics, raw vectors in search returns, ScaNN index support, iterator functionality, JSON_CONTAINS expressions, and CDC support.
5. **Performance Improvements**: Features MMap for capacity increase, optimized data filtering, growing index, and increased resource usage in multi-core environments.
6. **Load Balancer and Dynamic Configuration**: Introduces a new load balancer and dynamic configuration support.
7. **Tool Upgrades**: Upgrades tools like Birdwatcher and Attu.

### Milvus 2.4:
1. **New GPU Index - CAGRA**: Introduces a state-of-the-art GPU-based graph index for significant performance boosts.
2. **Multi-vector and Hybrid Search**: Supports storing vector embeddings from multiple models and conducting hybrid searches.
3. **Sparse Vectors**: Supports efficient approximate semantic nearest neighbor search for keyword interpretation and analysis.
4. **Grouping Search**: Allows aggregation of search results by specific scalar fields.
5. **Inverted Index and Fuzzy Match**: Improves scalar query performance and supports fuzzy matches.
6. **New Data Types**: Supports Float16 and BFloat16 vector data types.
7. **L0 Segment**: Enhances performance of delete and upsert operations by recording deleted data.
8. **Refactored BulkInsert**: Improves logic for importing multiple files in a single request.
9. **Memory-mapped Storage**: Optimizes memory usage by mapping file content into memory.
10. **Milvus-CDC**: Improves stability for capturing and synchronizing incremental data.

### Summary:
- **Milvus 2.3** focuses on broadening hardware support, enhancing deployment simplicity, and introducing various new APIs and performance improvements.
- **Milvus 2.4** emphasizes advanced search capabilities, new data types, improved memory management, and further performance optimizations.

Both versions aim to enhance system performance and usability, but Milvus 2.4 introduces more advanced search features and optimizations compared to Milvus 2.3.

05.

结论

从Naive RAG到Agentic RAG的转变,标志着检索增强生成技术的一个重要进步。通过引入代理(Agentic)方法,我们可以显著提升RAG系统在处理复杂任务时的能力。这不仅使得RAG系统更加智能和灵活,也为其在实际应用中提供了更广阔的前景。未来,我们可以期待更多基于Agentic RAG的创新应用,推动大模型技术的发展。

Ref: https://docs.google.com/presentation/d/1IWjo8bhoatWccCfGLYw_QhUI4zfF-MujN3ORIDCBIbc/edit#slide=id.g2c00d03c26e_0_64

作者介绍

fe89bb0ac80a3e2a30c531bcbeaf162e.jpeg

Milvus 北辰使者:臧伟

推荐阅读

a0a226cbffd16c41d254c6a78aff9ddc.png

456622b259ee5979c1748886af539c40.png

f53039d62b2027b7468b75f44fd4bdb9.png

879c143ce16de31a8e62a2ccaa6a93be.png

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

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

相关文章

如何在数仓中处理缓慢变化维度(SCD)

在数据仓库中,处理缓慢变化维度(SCD,Slowly Changing Dimension)是一个非常常见且重要的问题。为了保证数据的完整性和准确性,我们通常会采取不同的策略来处理维度表中的数据变化。SCD的核心解决方案是通过不同类型的历…

Run the FPGA VI 选项的作用

Run the FPGA VI 选项的作用是决定当主机 VI 运行时,FPGA VI 是否会自动运行。 具体作用: 勾选 “Run the FPGA VI”: 当主机 VI 执行时,如果 FPGA VI 没有正在运行,系统将自动启动并运行该 FPGA VI。 这可以确保 FPG…

使用Hugging Face中的BERT进行标题分类

使用Hugging Face中的BERT进行标题分类 前言相关介绍出处基本原理优点缺点 前提条件实验环境BERT进行标题分类准备数据集读取数据集划分数据集设置相关参数创建自己DataSet对象计算准确率定义预训练模型定义优化器训练模型保存模型测试模型 参考文献 前言 由于本人水平有限&…

视频文案提取

视频文案提取 通义听悟 🏆优点 自动提取音视频关键词、总结、提炼视频大纲、中英双字幕可以识别不同声音进行文案区分,还支持直接AI改写提取的文案旁边还有AI助手帮助你回答问题和对知识举一反三相关视频介绍👉原地封神!录音、…

拆解学习【反激-PD-氮化镓】(一)

小米67W桌面快充插座: 反激基本拓扑: 商用场景下,这个拓扑进行了如下优化: 1.Q22换成了氮化镓开关管,当然需要适配的能驱动氮化镓的控制芯片 2.D21二极管换成了MOS管。 3.由于是AC220V输入,设计了整流桥…

在Centos中安装、配置与使用atop监控工具

目录 前言1. atop工具的安装1.1 atop简介1.2 atop的安装步骤 2. 安装并配置netatop模块2.1 安装内核开发包2.2 安装所需依赖2.3 下载netatop2.4 解压并安装netatop2.5 启动netatop 3. atop的配置与使用3.1 配置监控周期与日志保留时间3.2 设置定时任务生成日志3.3 启动与查看at…

鸿蒙开发之ArkUI 界面篇 三十四 容器组件Tabs 自定义TabBar

如果需要修改Tabs的图标和文字之间的距离我们该怎么办呢?好在tabBar是联合类型,提供了自定义tabBar,这里就可以显示特殊图标或者是文字图片,如下图: 这里定义了myBuilder的函数,用了 来修饰,没有…

联合查询(详细篇)

实际开发中往往数据来自不同的表 所以需要多表联合查询 多表查询是对多张表的数据取笛卡尔积 笛卡尔积 什么是笛卡尔积呢? 简单来说 笛卡尔积是两个表的乘积 结果集中的每一行都是第一个表的每一行与第二个表的每一行的组合 简单理解: 假设有两个表…

复位电路的亚稳态

复位导致亚稳态的概念: 同步电路中,输入数据需要与时钟满足setup time和hold time才能进行数据的正常传输(数据在这个时间段内必须保持不变:1不能变为0,0也不能变为1),防止亚稳态; …

FPGA实现PCIE采集电脑端视频缩放后转千兆UDP网络输出,基于XDMA+PHY芯片架构,提供3套工程源码和技术支持

目录 1、前言工程概述免责声明 2、相关方案推荐我已有的PCIE方案我这里已有的以太网方案本博已有的FPGA图像缩放方案 3、PCIE基础知识扫描4、工程详细设计方案工程设计原理框图电脑端视频PCIE视频采集QT上位机XDMA配置及使用XDMA中断模块FDMA图像缓存纯Verilog图像缩放模块详解…

前端接口报500如何解决 | 发生的原因以及处理步骤

接口500,通常指的是服务器内部错误(Internal Server Error),是HTTP协议中的一个标准状态码。当服务器遇到无法处理的错误时,会返回这个状态码。这种错误可能涉及到服务器配置、服务器上的应用程序、服务器资源、数据库…

【畅捷通-注册安全分析报告】

前言 由于网站注册入口容易被黑客攻击,存在如下安全问题: 暴力破解密码,造成用户信息泄露短信盗刷的安全问题,影响业务及导致用户投诉带来经济损失,尤其是后付费客户,风险巨大,造成亏损无底洞…

图说谭教授的“Δy=dy”是误人子弟的概念性错误。

黄小宁 可建立如图所示的局部坐标系。图中曲线Δydy余项不是关于dx的一次函数,而切线dyydx是关于dx的一次函数。草图形象直观地显示曲线Δy不切线dy。 所以谭教授书中的“Δydy余项dy”是误人子弟的概念性错误。数学家王元说:搞错概念脑子会变成一团浆糊…

离岗睡岗预警系统 值班室离岗识别系统Python 结合 OpenCV 库

在众多工作场景中,存在着一些特殊岗位,这些岗位对于人员的专注度和警觉性有着极高的要求。然而,离岗睡岗现象却时有发生,给工作的正常开展和安全保障带来了严重的威胁。本文将深入探讨特殊岗位离岗睡岗的危害,以及如何…

解决方案:AttributeError: Can only use .str accessor with string values!

文章目录 一、现象二、解决方案 一、现象 最近在用Pandas库处理日期数据的时候,有时候想截取后两个数字,却截取不了,时间久了,会有些遗忘,去找大模型提问找答案,于是做个笔记记录,帮助后面遇见…

docker,docker-desktop,docker-compose download

docker docker-compose download 百度网盘获取离线包链接release-notes 参考dockerdocker-composewlspowershell

程序猿成长之路之设计模式篇——创建型设计模式——抽象工厂模式

设计模式开篇之作,简单介绍一下抽象工厂设计模式 前言 试想一下,国内有两个工厂,工厂1和工厂2,这两个不同牌子的工厂生产同样类型的商品,但是商品的价格和数量不一致,这时候我们要对其进行设计&#xff0c…

Centos基线自动化检查脚本

此脚本是一个用于检查Linux系统安全配置的Bash脚本。它通过多项安全标准对系统进行评估,主要检查以下内容: IP地址获取:脚本首先获取主机的IP地址,确保其以10.115开头。 密码策略检查: 检查最小密码长度(P…

解析 wxPython 和 Pandas 实现的 XLSX 分析器和网页打开器

在本文中,我们将分析一个使用 wxPython 和 Pandas 库编写的 Python 应用程序,名为 “XLSX Analyzer and Web Opener”。该应用程序的核心功能是:从 Excel 文件中读取数据并显示在网格中,此外,还允许用户使用 Google Ch…

力扣面试150 汇总区间 双指针 StringBuilder

Problem: 228. 汇总区间 &#x1f468;‍&#x1f3eb; 参考题解 import java.util.ArrayList; import java.util.List;class Solution {public List<String> summaryRanges(int[] nums) {List<String> ret new ArrayList<String>(); // 存储结果的列表in…