AI Skills AI技能 4h ago Updated 2h ago 更新于 2小时前 49

Prompt Engineering Isn’t Enough: How Four Bricks of Context Engineering Stop RAG Hallucinations 提示工程还不够:上下文工程的四块基石如何阻止RAG幻觉

Naive RAG pipelines fail not due to prompt engineering issues, but because of upstream failures in document parsing, question parsing, retrieval, and generation. Flat text extraction destroys relational structures like tables, causing models to miss critical data alignments; relational parsing preserves line-level structure. Vocabulary mismatches between user queries and document terminology lead to retrieval failures; semantic expansion and synonym normalization are required. Keyword-based retr 指出传统RAG的幻觉往往源于上游环节(解析、检索)而非提示词工程,提出“上下文工程”概念。 对比了朴素RAG与升级管道在四个关键环节的表现,证明简单优化(如调整分块大小或嵌入模型)无法解决根本问题。 文档解析需从扁平文本转为关系型结构(如保留表格行列对应),以维持数据语义完整性。 问题解析需进行词汇扩展和同义词映射,解决用户查询词与文档术语不一致导致的检索失败。 检索策略应利用文档结构信息(如目录)进行路由,避免仅依赖关键词频率导致的定位偏差。

65
Hot 热度
75
Quality 质量
70
Impact 影响力

Analysis 深度分析

TL;DR

  • Naive RAG pipelines fail not due to prompt engineering issues, but because of upstream failures in document parsing, question parsing, retrieval, and generation.
  • Flat text extraction destroys relational structures like tables, causing models to miss critical data alignments; relational parsing preserves line-level structure.
  • Vocabulary mismatches between user queries and document terminology lead to retrieval failures; semantic expansion and synonym normalization are required.
  • Keyword-based retrieval often fails to distinguish between sections that merely mention a term and those that define it; routing via table of contents improves precision.
  • The concept of "context engineering" emphasizes fixing all four pipeline bricks rather than relying solely on prompt optimization or chunk size adjustments.

Why It Matters

This analysis challenges the common industry reflex of blaming LLM hallucinations on poor prompting or model quality, revealing instead that data preparation and retrieval logic are the primary bottlenecks. For AI practitioners, it underscores the necessity of moving beyond basic vector search and flat text chunking toward structured, semantic-aware pipelines to ensure reliable enterprise-grade RAG applications.

Technical Details

  • Parsing: Replaces flat get_text() extraction with relational line_df outputs that preserve bounding boxes and line integrity, ensuring tables remain readable as structured data rather than fragmented text streams.
  • Question Parsing: Implements a pre-retrieval step that normalizes and expands user queries using domain-specific synonyms (e.g., mapping "pillars" to "tenets") to align user intent with document vocabulary.
  • Retrieval: Shifts from simple keyword matching or cosine similarity on flat chunks to routing mechanisms that leverage document structure, such as table of contents, to locate precise definitions rather than frequent mentions.
  • Generation: Enforces typed answers with confidence scores, allowing the system to detect when context is missing or misaligned, thereby reducing confident hallucinations.

Industry Insight

  • Organizations should audit their RAG pipelines for structural integrity in parsing and retrieval logic before attempting to optimize prompts or switch embedding models.
  • Investing in semantic query expansion and structured document parsing (especially for tables and complex layouts) yields higher accuracy gains than increasing top-k retrieval counts.
  • The industry must adopt a holistic "context engineering" mindset, treating the entire pipeline as a chain where the weakest link determines overall reliability, rather than focusing exclusively on the LLM component.

TL;DR

  • 指出传统RAG的幻觉往往源于上游环节(解析、检索)而非提示词工程,提出“上下文工程”概念。
  • 对比了朴素RAG与升级管道在四个关键环节的表现,证明简单优化(如调整分块大小或嵌入模型)无法解决根本问题。
  • 文档解析需从扁平文本转为关系型结构(如保留表格行列对应),以维持数据语义完整性。
  • 问题解析需进行词汇扩展和同义词映射,解决用户查询词与文档术语不一致导致的检索失败。
  • 检索策略应利用文档结构信息(如目录)进行路由,避免仅依赖关键词频率导致的定位偏差。

为什么值得看

本文通过实证分析揭示了RAG系统失败的深层原因,纠正了从业者过度关注Prompt优化的误区。它提供了具体的“上下文工程”方法论,帮助开发者构建更鲁棒、可复现的企业级RAG管道。

技术解析

  • 解析层(Parsing):朴素方法使用get_text()将PDF转为扁平文本并按固定字符数切分,导致表格数据断裂。升级方案采用关系型解析,返回包含边界框信息的line_df,确保标签与数值在同一行被读取。
  • 问题解析层(Question Parsing):朴素方法直接使用用户原词检索,若文档使用不同术语(如“tenets”而非“pillars”)则无法匹配。升级方案在检索前对查询进行标准化和同义词扩展,桥接词汇差异。
  • 检索层(Retrieval):朴素方法基于关键词频率或余弦相似度排名,容易将高频出现但非定义性的页面排在前面。升级方案利用文档目录结构进行路由,精准定位到包含定义的特定章节。
  • 生成层(Generation):强调模型应忠实于提供的上下文。当上游环节提供正确且完整的上下文时,模型能给出高置信度的准确答案;反之,即使模型诚实,也会因错误上下文而给出错误答案。

行业启示

  • 重视数据预处理与结构化:企业应投入资源改进文档解析能力,特别是针对表格、图表等非纯文本内容的结构化提取,这是保证RAG质量的基础。
  • 构建领域知识图谱或词汇表:在检索前引入语义对齐机制,建立用户自然语言与文档专业术语之间的映射关系,提升检索召回率。
  • 系统化调试RAG管道:不应仅通过调整Prompt来排查问题,而应逐层检查解析、查询扩展、检索和生成四个模块,定位具体的失效环节并进行针对性修复。

Disclaimer: The above content is generated by AI and is for reference only. 免责声明:以上内容由 AI 生成,仅供参考。

RAG 检索增强生成 LLM 大模型 Embedding Model 嵌入模型