跳到主内容
@wquguru
精选88r/Rag(Reddit)技巧与观点

RAG检索失败根源:文档切分导致语义断裂与验证方案

Your RAG can't answer. It's probably not the model's fault

原文
发到 X
推荐理由

直击RAG落地痛点,提供了一套低成本、高可复用的文档切分验证工作流,工程师可直接参考其规则设计优化现有Pipeline。

I was debugging a contract Q&A RAG recently. One question kept failing: When can the Contractor terminate this Agreement? The retriever returned plausible-looking chunks. The model tried hard. The answer was still wrong

我最近在调试一个合同问答的 RAG(检索增强生成)系统。有一个问题一直失败:承包商何时可以终止本协议?检索器返回了看似合理的文本块。模型也尽力了,但答案仍然是错误的。

Then I opened the source document and found this -- the splitter had cut as single sentence into two chunks:

然后我打开了源文档,发现了这个问题——分割器将单个句子切分成了两个文本块:

Chunk 1: if the Client breaches any material obligation,

文本块 1:如果客户违反任何重大义务,

Chunk 2: the Contractor may terminate this Agreement.

文本块 2:承包商可以终止本协议。

Both chunks passed my chunk-size check. Both got embedded.Neither one, alone, can answer the question

这两个文本块都通过了我的文本块大小检查。两者都被嵌入。但单独任何一个都无法回答这个问题。

The failure wasn't in the model or the embeddings. It happened two steps earlier - when the document was cut into pieces

问题不出在模型或嵌入上。它发生在更早的两个步骤之前——当文档被切成碎片时。

I kept running into the same class of problem across different documents, so I built a library to catcch it, rag-verifier runs quality gates at two points in the pipeline

我在不同文档中反复遇到同一类问题,因此我构建了一个库来捕获这些问题。rag-verifier 在管道的两个关键点运行质量门控。

Before ingestion: is this chunk self-sufficient?

摄入前:这个文本块是否自足?

A rule layer(pure regex, zero LLM cost) scans every chunk for structural defects: a conditional sentence cut in half, a chunk that start with 'Therefore' or 'However' with its premise left behind, a template fragment like 'yyyy' left blank

规则层(纯正则表达式,零 LLM 成本)扫描每个文本块的结构缺陷:被切断一半的条件句、以“因此”或“然而”开头但其前提条件被留下的文本块、像 'yyyy' 这样留空的模板片段。

When the rule layer can't decide -- say the grammar looks fine but the meaning might still depen on context -- an LLM semantic layer takes over. If the LLM is down, it returns uncertain. It never fakes a pass

当规则层无法决定时——例如语法看起来没问题,但含义可能仍然依赖上下文——LLM 语义层接管。如果 LLM 不可用,它返回不确定。它从不伪造通过结果。

After generation: does the citation actually support the claim?This one is sneakier. THE AI quotes something that is verbatim from the source -- but it's only the result clause of a conditional.

生成后:引用是否真正支持该主张?这一点更隐蔽。AI 引用了源文档中的逐字内容——但它只是条件句的结果部分。

The trigger condition got cut away, The quote sounds right, but citing it alone misleads the reader

触发条件被切除了。引用听起来正确,但单独引用它会误导读者。

There's a deterministic check for this. if the citation sits at the result side of a conditional in the source, an the condition isn't inside the citation, it's flagged immediately -- no LLM call needed.

对此有一个确定性检查。如果引用位于源文档中条件句的结果侧,且条件不在引用内部,则立即标记——无需调用 LLM。

Tested on 1388 chunks across 20 real documents, with a rule-layer false-positive rate around 0.5%

在 20 个真实文档的 1388 个文本块上进行了测试,规则层的误报率约为 0.5%。

GitHub: github.com/hlc0000/rag-verifier

if you have a chunk that looks fine but you RAG can't answer from it -- drop it in the comments. I'II run it through and show you exactly what it catches

如果你有一个看起来没问题但你的 RAG 无法从中回答问题的文本块——请在评论中贴出来。我会将其放入系统中运行,并展示它具体捕获了什么。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件