多阶段与智能体式 RAG 模式
了解涉及多次检索步骤,或与 LLM 智能体集成以完成复杂任务的高级 RAG 架构。
多阶段与智能体式 RAG 模式 是 CoddyKit 上的免费 LLM Apps in Production (RAG + Vector DB + Caching) 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 LLM Apps in Production (RAG + Vector DB + Caching) 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 LLM Apps in Production (RAG + Vector DB + Caching) 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Complex Queries & Advanced RAG
Welcome to Advanced RAG! So far, we've explored basic Retrieval Augmented Generation (RAG) where an LLM answers a query using a single set of retrieved documents.
However, real-world questions can be complex. They might involve multiple parts, require reasoning, or need to interact with different systems.
Simple RAG struggles with these challenges. That's why we need more sophisticated approaches like Multi-stage RAG and Agentic RAG.
Deconstructing Multi-stage RAG
Multi-stage RAG is an advanced pattern designed to handle complex queries by breaking them down into smaller, manageable parts. Instead of one big retrieval, it performs several targeted retrievals.
Think of it like a detective solving a case: they don't just look for one clue; they follow leads, gather more information, and piece it all together step-by-step.
The Query Decomposition Step
The first step in Multi-stage RAG often involves query decomposition. Here, an LLM analyzes your original complex question and reformulates it into multiple, simpler sub-queries or specific search terms.
This allows the system to retrieve documents that are highly relevant to each distinct part of your overall question, improving accuracy.
Iterative Retrieval in Action
Once the original query is decomposed, the RAG system performs iterative retrieval. This means:
- Each sub-query is sent to the retriever.
- Relevant documents are fetched for each sub-query.
- The results from one retrieval step might even inform or refine subsequent sub-queries.
Finally, all retrieved information is combined and sent to the LLM for a comprehensive answer.
Multi-stage RAG Example
Imagine you ask: "What are the main causes of climate change, and what are some recent technological solutions being developed to combat it?"
A Multi-stage RAG system might:
- Decompose: "Main causes of climate change" and "Recent tech solutions for climate change."
- Retrieve 1: Find documents on causes.
- Retrieve 2: Find documents on solutions.
- Synthesize: Combine info to answer both parts fully.
Introducing Agentic RAG
While Multi-stage RAG improves retrieval, Agentic RAG takes it a step further. An LLM agent is a system where an LLM acts as a 'brain' to reason, plan, and execute actions using a variety of tools.
Instead of just retrieving, an agent can decide what to do next based on the user's query and the available tools. RAG becomes one of its powerful tools!
Agentic Architecture & Tools
The core of an agentic system is an LLM that can:
- Understand: Interpret the user's goal.
- Plan: Break down the goal into steps.
- Act: Choose and use appropriate tools for each step.
- Observe: Evaluate tool outputs and decide next steps.
Tools can include web search, calculators, external APIs, and, crucially, a RAG retriever for your knowledge base.
RAG is a Powerful Tool
In an Agentic RAG system, the RAG component isn't the whole pipeline; it's a specialized tool the agent can invoke. The agent decides when to use RAG.
For example, if a user asks a question that requires factual information from your specific document store, the agent will 'decide' to use its RAG tool to fetch that context.
Agentic RAG in Practice
Consider the query: "What was our company's Q3 revenue last year, and how does it compare to the industry average for that period?"
An LLM agent might:
- Use RAG Tool: Retrieve internal Q3 revenue report.
- Use Web Search Tool: Find industry average Q3 revenue.
- Use Calculator Tool: Compare the two figures.
- Synthesize: Provide a comprehensive answer.
Choosing the Right RAG Pattern
When should you use Multi-stage vs. Agentic RAG?
- Multi-stage RAG: Best for queries that can be clearly broken into distinct sub-questions, where the primary challenge is retrieving comprehensive information.
- Agentic RAG: Ideal for highly dynamic, multi-step problems that might require various types of reasoning, external interactions, and tool usage beyond just retrieval.
Both enhance RAG, but for different kinds of complexity.
Advanced RAG Check
Let's check your understanding of these advanced RAG patterns.
Recap: Advanced RAG Patterns
Great job! In this lesson, we explored advanced RAG patterns for handling complex scenarios:
- Multi-stage RAG: Decomposes complex queries into sub-queries, performing iterative retrieval to gather comprehensive context.
- Agentic RAG: Uses an LLM as an intelligent agent that can reason, plan, and use various tools (including RAG) to achieve a goal.
These techniques are crucial for building robust and intelligent LLM applications that go beyond simple question-answering.
常见问题解答
「多阶段与智能体式 RAG 模式」课时是免费的吗?
是的 — 「多阶段与智能体式 RAG 模式」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 LLM Apps in Production (RAG + Vector DB + Caching) 课程的其余内容,请升级到 CoddyKit PRO。 LLM Apps in Production (RAG + Vector DB + Caching) 课程共包含 4 节课。
「多阶段与智能体式 RAG 模式」这节课中我会学到什么?
了解涉及多次检索步骤,或与 LLM 智能体集成以完成复杂任务的高级 RAG 架构。 你通过在浏览器中直接运行的动手代码来练习 LLM Apps in Production (RAG + Vector DB + Caching),全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 LLM Apps in Production (RAG + Vector DB + Caching) 需要有经验吗?
无需任何先前经验。CoddyKit 上的 LLM Apps in Production (RAG + Vector DB + Caching) 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。
「多阶段与智能体式 RAG 模式」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 LLM Apps in Production (RAG + Vector DB + Caching) 课中编写并运行代码吗?
能。每节 LLM Apps in Production (RAG + Vector DB + Caching) 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。