RAG 与智能体 — 用 LangGraph 给聊天机器人接上记忆、知识和双手¶
这一章讲一个机器人如何长成全副武装的客服: 先会聊天(单节点图),再记住之前的对话(checkpointer),然后只谈正事(system 提示词), 接着能查自家知识库(RAG),最后能替用户查订单、取消订单(ReAct 智能体)。 每一步都是上一句需求的直接后果。读完你掌握了 2025 年代 AI 应用的三大标准件—— 记忆、检索、工具——以及把它们编排起来的通用骨架:一张状态图。
1. 这一章讲什么¶
场景:Note n' Nib 客服被打爆,CEO 点你做 Nibby——能聊、懂自家产品、 能查单取消单、不行的转人工1。和第 09 章的问答游戏不同,这次的需求单上 没有一行能靠「喂一个提示词」解决:知识是私有的、对话是多轮的、动作是真实的。
设计图(书中 figure 10.2)一句话:用户消息进来 → 从私有知识库(向量数据库) 捞出相关片段塞给 LLM → LLM 要么直接回答、要么调用一个「工具」(查订单、取消订单)2。 本章就是沿着这条流水线逐段施工。
2. 核心原理(一):LangGraph 的图、节点、边与状态¶
直接调 OpenAI API 写复杂 AI 应用,你会自己撞上三堵墙:多步流程(先检索再回答)、 外部工具集成、多轮上下文记忆3。LangChain 提供积木(提示词管理、记忆、工具集成、 多厂商模型抽象),LangGraph 在同一家公司手里把「AI 工作流」组织成图—— 这正是本章的主框架4。
三个术语,照书里的社会网络类比5:
- 图(graph) = 节点 + 边。社交网络里节点是人、边是好友关系; LangGraph 里节点是应用的一个步骤(函数),边是步骤之间的流向(带方向)。
- 状态(state) = 一袋子命名的值,类似 Streamlit 的 session_state。 每个节点吃进去当前状态、返回要改的那几键,LangGraph 负责合并6。
- START / END:每张图自带的两个虚拟节点,标记执行的开始和结束。
书中那个非 AI 的玩具图是最好的标本:输入 numbers: [3, 4] → squaring_node
(平方,得 [9,16],写进 squares)→ summing_node(求和,得 25,写进 answer)→ END。
状态在节点间接力,一次执行就是状态的一串改写7。
代码骨架(listing 10.1,非 Streamlit,纯 Python 就能跑):
from langgraph.graph import START, END, StateGraph, MessagesState
from langchain_core.messages import HumanMessage
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model_name="gpt-5.1", openai_api_key="sk-proj-...")
def assistant_node(state): # 节点 = 普通函数,参数是状态
ai_msg = llm.invoke(state["messages"]) # LangChain 的调用方式
return {"messages": [ai_msg]} # 只返回要更新的键
builder = StateGraph(MessagesState)
builder.add_node("assistant", assistant_node)
builder.add_edge(START, "assistant")
builder.add_edge("assistant", END)
graph = builder.compile()
final_state = graph.invoke({"messages": [HumanMessage(content="你好")]})
print(final_state["messages"][-1].content)
两个细节决定成败:
- 消息的角色在 LangChain 里是类:HumanMessage(=user)、AIMessage(=assistant)、 SystemMessage(=system),都是 AnyMessage 的子类(继承,第 09 章的 BaseModel 同款机制)8。
- MessagesState 的 append 语义。普通 TypedDict 里节点返回
{"messages": [x]}是整体替换;MessagesState 内部给 messages 挂了 add_messages 注解, 返回的会被追加——所以 assistant_node 只返回新那一条,旧消息不丢9。 这个「替换 vs 追加」的区分,是读一切 LangGraph 代码的钥匙。
3. 核心原理(二):多轮记忆——checkpointer 与 thread_id¶
单节点图每调一次都是全新状态:告诉它「我叫 Bob」,下一句「我叫什么」就露馅。 解法:checkpointer(检查点器)——图每步都把状态存起来; 再给它一个 thread_id,同一 ID 的调用自动从上次的存档接着跑10:
memory = MemorySaver() # 存内存的 checkpointer(也可换 PostgreSQL/SQLite)
graph = builder.compile(checkpointer=memory)
config = {"configurable": {"thread_id": "1"}} # 看上去啰嗦,是 LangGraph 预留的多配置位
graph.invoke(state, config)
graph.get_state(config) 能随时取回存档——前端显示历史就靠它11。
两个书中自问自答的细节值得记住:thread_id 为什么恒为 1——Streamlit 会话
一刷新 Bot 实例就重建,一个图实例一生只见一场对话;config 为什么套两层——
LangGraph 的调用配置不止线程 ID 一个,结构为未来预留12。
前端三个新部件,12 行成一个聊天应用:st.chat_input(钉在底部的输入框,
按发送才返回值)、st.chat_message("human"/"ai")(带头像的消息气泡)、
:= 海象运算符(赋值塞进 if 条件里,省一行)13。
4. 核心原理(三):收窄话题——base_context 节点¶
通用聊天机器人有个业务问题:让它唱歌它也唱,每一句都在烧公司的 token14。
书里用了一个示范性的图改动:新增一个 base_context 节点,把「你是 Note n' Nib
客服,无关请求一律拒绝」的系统提示词写进状态(sys_msg_text 字段,自定义状态类
AgentState(MessagesState) 加一列即可),assistant 节点发送前把它包在消息列表最前15。
START → base_context → (RAG 两节点,见下) → assistant → END
│ 发送时:[SystemMessage(拒答指令+知识)]
└─ 往状态里写 sys_msg_text = BASE_SYS_MSG
图说:系统提示词也成了图状态的一部分,由专门的节点写入——
「流程」和「内容」在图里是同一个层面的东西。
这个设计值得注意:它把「给模型立规矩」从 API 调用参数升格成了图上的一个步骤, 和检索、回答平起平坐——后面往系统消息里继续塞内容(检索结果)时,结构 already 就绪。
5. 核心原理(四):RAG——检索增强生成¶
问题。 Nibby 被问「你们卖什么钢笔」,答得斩钉截铁——但 InkStream、RoyalQuill 是虚构品牌,模型在幻觉(编得像真的、实则无中生有的回答)16。 治幻觉的正路是给它私有知识。为什么不直接把全部资料塞进提示词?两个硬理由: 超大提示词会让模型表现下降(信息过载);token 按量计费,每句都背一遍全库, 账单爆炸——尽管 gpt-5.1 的上下文窗口有 40 万 token,Gemini 2.0 Pro 有 200 万 (够装下全套哈利·波特外加大半部魔戒)17。
RAG 四步:读用户问题 → 从知识库检索相关片段 → 把片段和问题拼一起 → 交给模型生成18。难的是第二步「检索」——答案是 embeddings + 向量数据库:
- embedding(嵌入) = 把一段文本变成一串数。 这让「意思相近」可以变成「几何距离相近」:书里的电影推荐例子是最佳直觉—— 给每部电影打「喜剧值、每小时爆炸次数」两个分,The Dark Knight = [1.2, 6], 在图上离它最近的是 [1.1, 5.9] 的谍影重重,推荐成立。 这一串数就叫向量;真用的嵌入模型有上千个维度,维度本身不再有人类可懂的名字。 两段文本像不像,用余弦相似度衡量——把每个向量想成一支箭头,看两支箭岔开的角度19。
- 向量数据库 = 专门存向量、快速算近邻的软件;本章用 Pinecone(云服务,免费档够用)。
数据管道(VectorStore 类,listing 10.8):
articles/ 文件夹(客服文章 .txt)
│ DirectoryLoader(**/*.txt, TextLoader) 逐文件读成 Document
▼
RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
│ 整篇塞进去会撑爆提示词,切成 ~1000 字符的块;块间重叠 200 字符保住上下文
▼
store.add_documents(texts) 每块算嵌入,连同原文一起进 Pinecone
(嵌入维度 1536,来自 text-embedding-3-small;在 Pinecone 网页上能看到每个 chunk
和它来自哪个文件20。离线跑一次即可,之后库里一直在。)查询端
similarity_search(query) 返回最相近的几块21。
接回图里,就是在 base_context 和 assistant 之间再插两个节点——这正是 「系统提示词是图状态的一部分」那个设计的红利时刻:
- retrieve 节点:把整轮对话的文本拼成查询串,取向量库检索,结果写进状态的
retrieved_docs字段; - augment 节点:把块文本拼进 SYS_MSG_AUGMENTATION 模板(「以下是客服手册节选: {docs_content};答不上来就让用户打 1-800-NOTENIB」),和 BASE 拼成完整系统消息22。
依赖方向也顺手示范了依赖注入:VectorStore 在 Bot 里建好、作为参数传给图, 图文件里不出现任何连接细节——「对写自动化测试友好」23。
6. 核心原理(五):智能体——ReAct、工具与条件边¶
最后一跃:客户要查订单状态。会聊天、有知识都不够——得替用户在系统里做事。 能感知、能推理、能对真实系统行动的 AI 应用叫 agent(智能体); 让它们动起来的经典框架是 ReAct(Reasoning + Acting,推理+行动):想 → 做 → 再想 → 循环,直到能说最终答复24。(书里特意注明:此 ReAct 非彼 React—— 那个是 JavaScript 界面库25。)
工具(tool) 在 AI 语境里就是一个文档写得很好的函数。本章四个:
retrieve_user_id(邮箱, 生日) → user_id、get_order_id(user_id, 下单日期) → order_id、
get_order_status(order_id) → 状态/单号/预计送达、cancel_order(order_id)。
模型凭什么会用它们?靠类型注解 + docstring——签名和文档就是工具的说明书,
bind_tools 把它们装订进模型26。
主线例子,Alice 查订单,走完看 ReAct 如何自己规划依赖链:
用户:「我 2 月 10 日下的单,帮我看看进度」
模型(内心):get_order_status 需要 order_id → 我没有;get_order_id 需要 user_id
和日期 → 我有日期;retrieve_user_id 需要邮箱和生日 → 问用户要。
Nibby:「请提供邮箱和出生日期」
用户:「alice.johnson@example.com,1990-05-14」
[工具调用] retrieve_user_id(...) → 1
[工具调用] get_order_id(1, "2025-02-10") → 101
[工具调用] get_order_status(101) → {Shipped, TRK123456789, 2025-02-18}
Nibby:「已发货,预计 2 月 18 日送达,单号 TRK123456789」
图说:三次工具调用,前两次的产物是后一次的输入——这个链是模型自己规划的,
代码里没有一行写死这个顺序。
图上的实现,只有三行新增(listing 10.12):
builder.add_node("tools", ToolNode(tools)) # ToolNode:内置节点,执行消息里的工具调用
builder.add_conditional_edges("assistant", tools_condition) # 条件边:有 tool_calls → tools,否则 → END
builder.add_edge("tools", "assistant") # 工具结果回喂模型,形成循环
机制:模型想调工具时,它的 AIMessage 会带 tool_calls 属性(要调哪个、参数是什么);
tools_condition 据此把流引到 ToolNode;ToolNode 执行后把返回值包成 ToolMessage
追加进状态,流沿 tools → assistant 回到模型,它拿着结果继续推理——或者不再调工具,
于是 tools_condition 放行到 END,最终答复送达用户27。「循环」在图里就是一个
回边;ReAct 的「想-做循环」成了图的拓扑。
收尾一个工程细节:get_history 要滤掉内部消息(type=="tool" 的 ToolMessage、 带 tool_calls 的 AIMessage)再显示——用户只该看到人话28。
7. 作者的判断与证据¶
判断:LangGraph 的图抽象是现在该学的编排方式,线性脚本应付不了真应用。 依据是三堵墙(多步、工具、记忆)的陈列29。证据强度中等:2025 年代这类框架 更迭很快,LangGraph 是当时的胜者之一,但「图 vs 工作流 vs 纯代码」之争没有终局。
判断:工具的自描述(类型注解 + docstring)足够模型正确使用。 本章的证据是 Alice 订单链路的成功演示30——但注意规模:四个工具、玩具数据。 工具一多、参数一复杂,docstring 就会漏;生产级做法有 JSON 格式契约(JSON Schema)校验、 参数确认回显等加固手段,本章未涉。
判断:把整个对话当检索查询「保持简单,长对话会出问题」。 书里自己标注了局限并给了方向(只用最近五六条)31——诚实的边界标注,值得赞赏。
8. 边界与局限¶
- MemorySaver 的记忆在进程内存里:服务器一重启,所有对话清零; 生产要用数据库型 checkpointer(PostgreSQL/SQLite),书里提了名字没给实现。
- thread_id 恒为 1 的前提是「一个 Bot 实例一生一场对话」——真实多用户部署 必须按用户分线程,否则 A 用户会看到 B 用户的对话史。
- RAG 的召回质量本章没有度量:检索回来的块对不对、漏检怎么办, 没有任何评估手段;向量库的免费档性能和数据驻留(合规)也是真实部署的议题。
- ReAct 循环没有刹车:模型理论上可以无限调工具(死循环),LangGraph 有 recursion_limit 之类的外部护栏,本章没装。
- 工具调用直接执行、无人工确认:cancel_order 这种破坏性操作, 让模型直接调是危险的;生产系统应在执行前向用户确认,本章从简。
- 全部云服务(Pinecone、OpenAI)的界面与定价为时点快照。
判断(我们的,不是书里的): 本章是全书的「当代性」之巅——记忆、检索、 工具三件套正是这个时代 AI 应用的默认解剖,而 LangGraph 的「状态图」把它们 统一在一个优雅的形式里:AI 应用 = 数据(状态)在步骤(节点)间的受控流动, 流向可以取决于模型的即时决定(条件边)。这个抽象和数据库的事务、 和操作系统的进程图是同一族思想,学一遍不亏。更难得的是本章的坡度设计: 每个新概念(append 语义、checkpointer、条件边)都在「上一个不够用了」的时刻出现, 和书本库推崇的「先现象后原理」完全一致。 如果错,会错在: 框架依赖本身——本章的行文几乎把 LangChain/LangGraph 当 基础设施写,但 2024–2026 年这个生态的重构速度快得反常(import 路径都改过几轮); 概念(状态、工具、检索)必然长寿,具体 API 可能三年就换脸。 读者该带走的是图和 ReAct 的心智模型,不是 memorizing 哪个类从哪个包 import。
9. 可带走的¶
- 复杂 AI 应用的三堵墙:多步流程、外部工具、多轮记忆——撞上任何一堵,就该上图框架。
- LangGraph 四要素:状态(一袋子值)、节点(函数,吃状态返回要改的键)、边(流向)、START/END。
- MessagesState 的 messages 是追加语义,其他字段是替换语义——返回什么取决于键挂在哪个状态类上。
- 多轮记忆 = checkpointer + thread_id;MemorySaver 存内存,重启即失。
- 聊天前端三件套:st.chat_input、st.chat_message("human"/"ai")、海象运算符。
- 系统提示词可以是图状态的一部分:base_context 节点写入,assistant 发送前拼到消息列首。
- 塞全库进提示词不可行(过载 + 账单)——RAG:检索相关片段再生成。
- embedding = 文本 → 向量,意思相近 = 几何相近;余弦相似度看夹角;Pinecone 存取向量。
- 知识入库三步:加载(DirectoryLoader)→ 分块(1000 字符、重叠 200)→ 入库(add_documents)。
- 依赖注入:VectorStore/LLM 在 Bot 层建好传进图,图文件保持纯粹。
- 工具 = 类型注解 + docstring 写清楚的函数;bind_tools 装订给模型。
- 智能体三行:ToolNode 执行调用、tools_condition 决定走工具还是结束、tools → assistant 回边成循环。
- 对外显示前滤掉内部消息(ToolMessage、带 tool_calls 的 AIMessage)。
10. 原文地图¶
| 主题 | 原书章 | 原文位置 |
|---|---|---|
| Nibby 需求与范围外 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:53搜「customer support chatbot」) |
| 总体设计图(知识库 + 工具) | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:100搜「overall design」) |
| LangChain/LangGraph 定位 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:168搜「ecosystem of libraries」) |
| 图/节点/边/状态定义 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:199搜「Graphs, nodes, edges」) |
| 平方和玩具图 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:262搜「sum of squares」) |
| 单节点 LLM 图代码(listing 10.1) | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:289搜「one-node」) |
| MessagesState 的 append 语义 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:557搜「tacked」) |
| 闭包模式(get_assistant_node) | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:528搜「closure」) |
| Bot 类与 max_tokens | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:570搜「Bot class」) |
| st.chat_input / chat_message / 海象符 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:650搜「walrus」) |
| checkpointer 与 thread_id | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:727搜「checkpointers」) |
| thread_id 为何恒为 1 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:792搜「Why is the thread ID always 1」) |
| 历史显示(get_conversation/get_history) | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:824搜「conversation history」) |
| 拒答的系统提示词 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:905搜「strictly business」) |
| base_context 节点与 AgentState | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:978搜「base_context_node」) |
| 上下文窗口与为何不塞全库 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1120搜「context window」) |
| RAG 四步定义 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1139搜「essential steps」) |
| 电影嵌入类比与余弦相似度 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1152搜「movie buff」) |
| VectorStore 与分块入库 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1289搜「ingest_folder」) |
| retrieve/augment 节点接入图 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1424搜「Adding RAG to the graph」) |
| 依赖注入说明 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1515搜「dependency injection」) |
| 检索查询用全对话的局限注记 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1554搜「last, say, five」) |
| 智能体与 ReAct 框架 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1654搜「Reasoning + Acting」) |
| 工具定义与 docstring | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1743搜「retrieve_user_id」) |
| Alice 订单的 ReAct 链路 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1788搜「Alice Johnson」) |
| 三行智能体(ToolNode/条件边/回边) | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1829搜「bind_tools」) |
| 滤掉内部消息 | 10 RAG and agentic apps with LangGraph | text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1937搜「internal messages」) |
-
出处:「10 RAG and agentic apps with LangGraph」第 35–72 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:53,搜「customer support chatbot」)。范围外四条(不存历史对话、只有两种动作、动作是玩具逻辑)见第 73–87 段。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 97–154 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:100,搜「overall design」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 172–191 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:177,搜「multi-step workflows」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 181–197 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:187,搜「extends LangChain」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 199–247 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:204,搜「graph theory」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 226–247 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:228,搜「named attributes with values」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 248–287 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:262,搜「sum of squares」)。[3,4] → 25 的推演见第 264–282 段。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 365–382 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:375,搜「AnyMessage superclass」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 536–566 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:557,搜「appended to the existing list」)。Annotated[…, add_messages] 的说明见第 560–566 段。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 715–731 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:727,搜「checkpointers」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 824–845 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:834,搜「get_conversation」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 790–812 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:792,搜「Why is the thread ID always 1」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 612–683 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:650,搜「walrus operator」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 887–905 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:904,搜「quarterly earnings」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 907–1087 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:917,搜「BASE_SYS_MSG」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 1089–1109 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1107,搜「hallucinated」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 1111–1138 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1122,搜「400,000 tokens」)。哈利·波特与魔戒的对照见第 1124–1126 段。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 1139–1147 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1139,搜「essential steps」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 1148–1209 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1152,搜「movie buff」)。The Bourne Ultimatum [1.1, 5.9] 的结论见第 1186–1189 段;余弦相似度见第 1206–1208 段。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 1232–1423 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1233,搜「Pinecone」)。1536 维度见第 1420–1423 段。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 1357–1365 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1360,搜「similarity_search」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 1424–1613 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1424,搜「Adding RAG to the graph」)。SYS_MSG_AUGMENTATION 见第 1430–1439 段。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 1509–1515 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1515,搜「dependency injection」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 1625–1654 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1654,搜「Reasoning + Acting」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 1662–1663 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1662,搜「not to be confused」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 1696–1784 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1755,搜「type hints and docstrings」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 1820–1931 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1829,搜「bind_tools」)。ToolNode 的行为见第 1871–1878 段;tools_condition 见第 1907–1915 段。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 1932–1964 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1937,搜「internal messages」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 172–191 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:181,搜「Managing this complexity manually」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 1786–1818 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1788,搜「Alice Johnson」)。 ↩ -
出处:「10 RAG and agentic apps with LangGraph」第 1550–1555 段(
text/19-ch10-10-rag-and-agentic-apps-with-langgraph.txt:1552,搜「conversation gets longer and longer」)。 ↩