AI & LLMs · Intermediate
RAG(检索增强生成)
Retrieval-Augmented Generation
让模型在回答前先翻一遍你的资料,搜出相关段落再照着这些内容作答。资料可以随时替换,不必重新训练模型,也是压制它胡编的常用手段。
Some fields on this page have no English version yet — they are shown in the original Chinese.
TL;DRIn 30 seconds
- 回答之前先翻一遍你给的资料,找到相关段落再落笔,相当于开卷答题。
- 它的好处是资料随时能换、模型不用重训,坏处是找不到就照样瞎编。
- 答得准不准,很大程度看它有没有把对的段落翻出来。
OverviewIn detail
RAG 的全称是检索增强生成。用户提问之后,系统先去你的资料库里搜出最相关的几段,把这几段和问题一起交给模型,让模型照着手头的材料来写答案。整个过程里,模型本身没有被动过一个字。
模型掌握的知识是训练时灌进去的,有截止时间,也不了解你公司的内部文档。问它上个月刚定的合同条款,它只能凭印象猜。要让它知道新东西,重新训练一次代价太高,RAG 就把这一步绕开了——资料留在模型外面,回答时临时递进去。
典型的落点是需要准确性的问答。把产品手册、规章制度、历史工单整理进资料库,员工提问时先检索、再作答,系统通常还会附上引用出处,方便人翻回原文核对。客服机器人、内部知识助手,走的都是这个路子。
RAG 和微调经常被放在一起比较。RAG 是临时给参考资料,换资料时不动模型;微调是把新本事练进模型内部,要重新训练、要花算力。要它“查到某份文件里写了什么”,选 RAG;要它“换一种固定口吻说话”,才轮到微调。上下文工程则是更上一层的东西,它决定每次递进去的全部信息怎么挑、怎么排,RAG 只是其中一种手段。
别把 RAG 当成聪明药。它只负责把资料找出来递过去,检索这一步找错了段落,模型照样会答错,而且还答得理直气壮。系统的上限,很大程度上取决于资料找得准不准。
MythsCommon misunderstandings
- ✕以为它是把知识装进了模型脑子里 ✓其实资料一直放在外面,每次回答才临时递进去,删掉资料它就不知道了
- ✕以为上了它就不会答错 ✓它只是把材料找出来,翻错页时照样错,引用出处仍要自己核
- ✕以为资料越全答得越好 ✓资料互相打架或过期时,它挑到哪段就照哪段答,全和准是两回事
In practiceWhere you will meet it
- 把公司规章和产品手册传进系统,员工提问时它先查这几份再回答
- 给机器人接上内部工单记录,客户一描述问题,它就翻出相似的旧单子
- 拿到答案时顺手点开后面附的出处,回到原文确认那一条
SummaryThe key points
- 先检索资料,再让模型照着这些内容回答
- 资料放在模型外面,更新时不用重新训练
- 常见于客服问答和内部知识查询
- 和微调的分界:它换资料,微调改的是模型本身
FAQ
What does RAG(检索增强生成) mean?
回答之前先翻一遍你给的资料,找到相关段落再落笔,相当于开卷答题。它的好处是资料随时能换、模型不用重训,坏处是找不到就照样瞎编。答得准不准,很大程度看它有没有把对的段落翻出来。
Where will I run into RAG(检索增强生成)?
把公司规章和产品手册传进系统,员工提问时它先查这几份再回答;给机器人接上内部工单记录,客户一描述问题,它就翻出相似的旧单子;拿到答案时顺手点开后面附的出处,回到原文确认那一条。
What do people most often get wrong about RAG(检索增强生成)?
以为它是把知识装进了模型脑子里 — but 其实资料一直放在外面,每次回答才临时递进去,删掉资料它就不知道了;以为上了它就不会答错 — but 它只是把材料找出来,翻错页时照样错,引用出处仍要自己核。
What are the key points about RAG(检索增强生成)?
先检索资料,再让模型照着这些内容回答;资料放在模型外面,更新时不用重新训练;常见于客服问答和内部知识查询;和微调的分界:它换资料,微调改的是模型本身。
Common pitfalls 检索不到或找错段落时模型照样会编,答案质量取决于资料找得准不准。
Entry 17 of 186 · All entries
Keep readingRelated reading
AI Agent
An AI program that sets its own goal, breaks it into steps and calls tools to get the job done. You hand it a task and it works out how to do it — instead of only answering one question at a time.
LLM
A very large program that learned to predict the next piece of text after reading an ocean of it. Whatever you type, it is guessing what is most likely to come next — writing, translating and answering questions are all the same thing used differently.
嵌入(Embedding)
把一段文字换算成一串数字,让电脑能比较哪两句话意思更接近。搜索和知识库能在换了说法时也找对答案,靠的就是它。
Claude
A large language model built by Anthropic, known for understanding long documents, writing well and writing code. It comes both as a chat assistant on the web and phone, and in a dedicated form for programming.
Prompt
The message you send to an AI — the instruction or question you give it. How well that passage is written decides whether the answer that comes back is on target.
MCP
A standard interface that lets AI connect to outside tools and data in one uniform way. Build a tool to it once and any AI assistant can call it, saving you from writing a separate integration for each tool.
Where to go nextExplore more
Back to the skills themselves
Most of the concepts covered here come from skills that install into your AI client with a single command.