技术指南

检索增强生成 (RAG)

Retrieval-augmented generation, or RAG, supplies retrieved material to a generative model when answering a request.

阅读时间:2分钟最后更新

概述

It can give the system access to relevant documents without retraining the model for every document change. Retrieval does not guarantee that the final answer is supported or correct.

主要要点

  • Keep provenance and document context.
  • Enforce permissions before retrieval results reach the model.
  • Evaluate retrieval and generation independently.

深入探讨

A typical pipeline collects documents, preserves their provenance, creates searchable representations, retrieves candidates for a query, and passes selected evidence to a model. Some systems combine keyword and semantic search or rerank results before generation. Each stage can introduce omissions or errors. Document preparation determines what evidence can be found. Preserve headings, dates, tables, and source identifiers when dividing content into passages. A passage separated from an exception or footnote can convey the wrong meaning even when the words are copied correctly. Apply access controls before evidence reaches the model. A search result that is semantically relevant may still belong to a document the requesting user is not allowed to see. Treat instructions inside retrieved documents as untrusted content rather than authority to change the application’s behavior. Evaluate retrieval and answering separately. Check whether the needed evidence appears in the candidate set, whether the selected context retains it, and whether the answer uses it faithfully. Include questions with no answer in the collection and conflicting or outdated documents. The system needs an explicit way to say that evidence is insufficient.

技术洞察

Adding more context can introduce contradictory or irrelevant material. The objective is useful, authorized evidence, not the largest possible prompt.

Find where a grounded answer fails

  1. Construct two policies: an expired version allows returns for 30 days; the current version allows 14 days.
  2. If retrieval returns only the old policy, the failure is upstream of generation. If both are retrieved but the answer chooses 30 days, investigate context selection and evidence use.
  3. Add the effective-date conflict to both retrieval and answer evaluations.

The invented example separates two causes that would otherwise look like the same wrong answer.

战略影响

成本与预算

多年来,架构决策决定着性能和运营成本。

更清晰的判决

技术教育帮助团队选择正确的堆栈,而不仅仅是最新的堆栈。

质量控制

更好的工程选择可以减少生产中的可靠性事故。

现实世界的实施

Answer a support question using the current policy and its effective date.

Return source passages alongside an explanation so a reader can verify it.

风险与防护栏

优化一项基准测试可以隐藏更广泛的系统弱点。

基础设施和维护成本常常被低估。

随着系统变得更加复杂,安全性和可观察性差距可能会扩大。

实施路线图

1

在实施之前定义延迟、质量和成本目标。

2

在实际负载和数据条件下进行基准测试。

3

仪器监控错误、漂移和用户影响。

4

在扩展之前准备回滚和事件响应路径。

资料来源与延伸阅读

不断探索

Free newsletter

Get the daily AI briefing

Three verified AI stories every weekday morning, written in plain English. Free forever, no ads.

One email each weekday. Unsubscribe in one click. We never sell or share your address.

Test yourself

Take the Retrieval-Augmented Generation (RAG) quiz

Instant feedback on every answer, and a shareable certificate with a verifiable ID once you pass a course.

开始测验

Support free AI education. AI Understanding is a 501(c)(3) nonprofit — no ads, no paywall, ever. Make a donation

下一个指南

推测性 RAG 和检索增强起草

常见问题

Does RAG eliminate hallucinations?

No. Retrieval can miss evidence, return misleading material, or be used incorrectly by the generator. The final answer still needs evaluation.