Often, no. 对于合同、报告或电子邮件的文件夹,具备全文搜索工具的 AI 代理能够找到正确的文件,只读取匹配的片段并引用它们,索引在本地运行,无需嵌入模型和向量存储。GroupDocs.Search.Mcp 为 Claude Desktop、Claude Code、Cursor 或 Copilot 提供了这一工具,只需一条 Docker 命令:

索引合同文件夹,然后告诉我哪些合同提到了终止罚金并引用该条款。

步骤详尽的配置和故障排除指南请参见文档:如何使用 MCP 与 AI 代理搜索文档。

为什么大家首先想到嵌入?

因为“检索增强生成”(retrieval‑augmented generation)被包装成一种配方:将文档拆分成块,对每块进行嵌入,存储向量,对问题进行嵌入,取最近的块并粘贴到提示中。它能工作,且对于与文档表述完全不同的问题是合适的工具。但这是一条需要调用嵌入模型、运行向量存储、调优分块以及在文档每次变更时重新嵌入的流水线。对于“我的 300 份合同中哪些提到了终止罚金”,这套机器可以直接用搜索索引来回答。

证据已经追上直觉。2025 年底在 arXiv 上发表的一项研究(Keyword search is all you need)让代理仅使用关键字和正则表达式在文件夹中搜索,并将其与标准 RAG 流水线进行比较:在没有向量数据库的情况下,得分超过 RAG 的 90%,且更适合经常变化的集合。编码代理已经在实践中展示了这种模式:先用 grep 搜索,随后细化,再次搜索。

代理到底做了什么?

三次调用。GroupDocs.Search.Mcp 暴露了八个工具,循环中只需要其中三种:

user              agent                         Search MCP server
 |  "Which contracts mention a termination penalty?"           |
 |---------------->|                                           |
 |                 |-- add_to_index ------------------------->|  reads the
 |                 |   {"documentsPath":"contracts",           |  files once,
 |                 |    "indexName":"contracts"}               |  stores text
 |                 |<- "5 document(s) added, 5 in the index" --|
 |                 |-- search ------------------------------->|
 |                 |   {"query":"termination AND penalty"}     |
 |                 |<- {"documentsFound":3, "documents":[ ... |  which files
 |                 |-- get_text_fragments ------------------->|
 |                 |   {"query":"\"termination penalty\""}     |
 |                 |<- === contracts/acme-...-agreement.pdf ===|  the passages
 |<- "Two contracts carry one: Acme (3 monthly fees, 12.3),    |
 |    Globex (50% of the remaining fees). Initech excludes it."|

add_to_index 读取文件一次并将文本保存在磁盘上的命名索引中。search 以 JSON 形式返回匹配的文件及出现次数。get_text_fragments 为每个匹配返回带有少量上下文的片段,使得代理引用条款而不是加载整份合同。

下面是我们对五个合成合同进行测试时服务器实际返回的内容:

-> search {"query":"termination AND penalty","indexName":"contracts"}
<- documentsFound 3: acme-master-services-agreement.pdf,
   globex-consulting-agreement.docx, initech-nda.docx

-> get_text_fragments {"query":"\"termination penalty\"",...}
<- === contracts/acme-master-services-agreement.pdf (1 occurrence(s)) ===
     …a termination penalty of three monthly fees applies, payable
     within 30…
   === contracts/globex-consulting-agreement.docx (1 occurrence(s)) ===
     …Early termination penalty: the Client pays 50 percent of the fees…

请注意第三份合同。Initech NDA 匹配了 termination AND penalty,因为它写道 “there is no fee and no penalty associated with termination”。正是这段文字区分了匹配与提及,而读取这些片段的代理会如此说明。这就是 grounding:答案中的每一条主张都指向一个文件和一条可打开的句子。

各自的优势在哪里?

Embedding pipeline                       Agentic full-text search
-------------------------------------    -------------------------------------
split, embed, store in a vector store    add_to_index: a local full-text index
embed the question, take top-k chunks    agent searches, refines, searches again
paste the chunks into the prompt         get_text_fragments: quoted passages
re-embed when documents change           update_index re-reads what changed
needs an embedding model and a store     no model calls, no network at runtime
matches meaning; ranking is opaque       matches words; every hit is explainable

当问题与文档没有共享词汇时,全文搜索会失效,例如 “which contracts are risky for us?” 没有关键词。它在词汇共享时表现出色,这正是人们对自己文档最常提出的问题:条款名称、产品、客户、发票号、日期范围。当查询未命中时,代理会尝试 renewal OR renews,或使用模糊匹配,正如人类的思路。服务器会提供帮助:未加引号的两词查询在 GroupDocs.Search 中找不到匹配,空结果会携带一个 hint,提示代理对短语加引号。

哪个工具对应哪个问题?

用户的请求 代理调用
“索引此文件夹” add_to_index
“哪些文件提到了 X?” search
“X 的内容是什么?” get_text_fragments
“文件已更改,刷新” update_index
“忘掉 drafts 文件夹” remove_from_index
“索引里有什么?” get_index_info
“创建一个单独的索引” create_index
“为什么只有 10 条结果?” get_license_status

该索引支持 82 种格式,包括 PDF、Office、OpenDocument、HTML 以及电子邮件存档(PST、OST、MSG、EML)及其附件。

如何运行?

claude mcp add groupdocs-search -- docker run --rm -i \
  -v /path/to/documents:/data ghcr.io/groupdocs-search/search-net-mcp:latest

Cursor、Claude Desktop、VS Code(配合 GitHub Copilot)以及其他客户端都在各自的配置文件中使用相同的容器:在 AI 客户端中注册。在 Linux 上添加 --user "$(id -u):$(id -g)",使容器能够将索引写入你的文件夹。服务器运行的是 GroupDocs.Search 26.10 引擎,其全新索引格式使索引体积更小,内存占用约减半(发行说明)。

诚实的限制

  • 在评估模式下,索引最多容纳 100 份文档,搜索最多返回 10 条结果;每个响应都会说明这一点。请先调用 get_license_status。
  • 这是一种全文搜索,而非语义搜索:匹配的是词汇,而不是意义。
  • 不支持 OCR:没有文本层的扫描 PDF 只能通过文件属性进行索引。
  • 仅以 Docker 镜像形式提供(打包工具超过了 NuGet 的大小限制)。

FAQ

Claude 能在本地搜索我的文档而不上传吗?
可以。服务器在你的机器上的容器中运行,只读取你挂载的文件夹;只有代理引用的片段会发送给模型。

这算是 RAG 吗?
它是检索增强的,但属于代理式:模型自行决定何时搜索以及何时停止,使用全文索引而非嵌入。

文档变更后会怎样?
让代理刷新即可。update_index 只会重新读取已更改、已添加和已删除的文件。

深入了解