AI Skills AI技能 11h ago Updated 8h ago 更新于 8小时前 35

Retrieve One Row from a Table, Not the Whole Table: Row-Level Chunks for RAG 从表格中检索单行,而非整个表格:用于RAG的行级分块

Naive RAG retrieval treats entire tables as single chunks, forcing generation models to filter irrelevant rows instead of retrieving only the relevant row The article introduces a row-level serialization approach where each table row becomes an independent retrievable chunk Tables are parsed using Docling or Azure Document Intelligence, which emit markdown-pipe formatted lines that can be detected without per-parser branching The `serialize_table_rows` function groups contiguous pipe rows, ident 企业RAG系统中表格检索的核心问题:将整张表格作为单一chunk会导致检索时引入大量无关行,增加生成模型的噪声 提出"按行检索"方案:将表格的每一行序列化为独立chunk,使检索单元与用户问题的粒度匹配 基于Docling/Azure Document Intelligence的markdown pipe格式解析表格结构,无需额外_type列即可识别表头和行数据 实现serialize_table_rows函数,输入pandas DataFrame,输出与Article 7B检索器兼容的格式,保持系统模块化 该方案是Enterprise Document Intelligence系列的检索组件

50
Hot 热度
50
Quality 质量
50
Impact 影响力

Analysis 深度分析

TL;DR

  • Naive RAG retrieval treats entire tables as single chunks, forcing generation models to filter irrelevant rows instead of retrieving only the relevant row
  • The article introduces a row-level serialization approach where each table row becomes an independent retrievable chunk
  • Tables are parsed using Docling or Azure Document Intelligence, which emit markdown-pipe formatted lines that can be detected without per-parser branching
  • The serialize_table_rows function groups contiguous pipe rows, identifies headers and separators, and emits one output chunk per body row with column headers and cell values
  • Both table-level and row-level retrieval scales are made available, letting the dispatcher choose the appropriate granularity based on the query

Why It Matters

This addresses a critical gap in enterprise RAG systems where structured data in tables is commonly mishandled by naive chunking strategies. For AI practitioners building document intelligence pipelines, this approach enables precise row-level retrieval without requiring complex table-aware embeddings or model modifications.

Technical Details

  • Parsing contract: Docling and Azure Document Intelligence emit tables as markdown-pipe lines inside line_df, with header rows, separator rows (dashes/colons), and body rows in reading order
  • Detection rules: Four simple rules identify table structure—pipe-delimited rows, separator rows marking header/body split, contiguous pipe rows belonging to the same table, and non-pipe lines resetting the group
  • Serialization function: serialize_table_rows takes a pandas.DataFrame input, groups pipe lines into tables, extracts headers from the row above the separator, handles multi-row headers via fold_multirow_header, and outputs one chunk per body row with fields: table_id, page_num, line_num, column_headers, row_cells, and row_serialized
  • Output format: Each serialized row contains key-value pairs like "column_name: cell_value" joined by pipes, maintaining the same DataFrame shape as the existing retriever brick for composability
  • Demo: Uses Table 1 from "Attention Is All You Need" (4 rows, 4 columns) with runnable code on GitHub at doc-intel/notebooks-vol1

Industry Insight

  • Enterprise RAG systems should implement dual-scale retrieval (table-level and row-level) rather than committing to a single chunking granularity, as different queries require different levels of aggregation
  • The lightweight pipe-format detection approach avoids parser-specific branching, making it portable across Document Intelligence providers and reducing maintenance overhead
  • This row-level serialization pattern is immediately applicable to insurance policies, financial reports, and any domain where structured tables contain answerable facts at the row level

TL;DR

  • 企业RAG系统中表格检索的核心问题:将整张表格作为单一chunk会导致检索时引入大量无关行,增加生成模型的噪声
  • 提出"按行检索"方案:将表格的每一行序列化为独立chunk,使检索单元与用户问题的粒度匹配
  • 基于Docling/Azure Document Intelligence的markdown pipe格式解析表格结构,无需额外_type列即可识别表头和行数据
  • 实现serialize_table_rows函数,输入pandas DataFrame,输出与Article 7B检索器兼容的格式,保持系统模块化
  • 该方案是Enterprise Document Intelligence系列的检索组件补充,解决长文档中表格场景的精准检索问题

为什么值得看

本文针对企业RAG系统中表格检索的痛点提供了实用的工程化解决方案,避免了传统向量检索将整表作为chunk导致的噪声问题。对于构建企业级文档智能系统的工程师而言,该方案可直接复用于保险单、技术论文等包含结构化表格的文档场景。

技术解析

  • 问题诊断:表格在纸面上是矩形区域(document单位),但用户问题通常针对单行(reader单位)。传统检索将整个表格作为chunk,导致匹配时返回39行无关数据,不匹配时则完全遗漏。
  • 解析协议:利用Docling和Azure Document Intelligence输出的markdown pipe格式(以|分隔的行),通过四个规则识别表格:首尾含|、分隔行含---、连续pipe行属同一表格、非pipe行重置分组。
  • 核心函数serialize_table_rows:对line_df按页码和行号排序,分组连续pipe行为表格,识别分隔行提取表头,折叠多行表头,为每个body行生成包含table_id、page_num、column_headers、row_cells、row_serialized的chunk。
  • 系统兼容性:输出格式与Article 7B检索器的pandas DataFrame结构一致,实现两个组件通过line_df无缝组合,保持RAG四组件架构的模块化设计。
  • 实验验证:使用Attention Is All You Need论文的Table 1(4行4列)作为测试用例,展示序列化后按关键词查询可返回单行而非整表。

行业启示

  • 企业RAG系统需区分"文档结构单元"与"问题粒度单元",表格类文档应支持多尺度检索(整表+单行),由调度器根据问题类型动态选择。
  • 基于规则的结构解析(如pipe格式识别)可与向量检索并行运行,LLM仲裁器最终排序,兼顾精确性与语义理解能力。
  • 开源工具链(Docling、OpenAI API)已具备企业级文档处理的基础能力,关键在于设计可组合的组件架构,而非重复造轮子。

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