技術指南

檢索增強生成 (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.