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 管線比較:取得超過 90% 的 RAG 分數,且不需要向量資料庫,更適合經常變動的集合。編程代理早已在實踐中展示此模式:先用 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 因為包含 “there is no fee and no penalty associated with termination” 而匹配了 termination AND penalty。段落本身說明了匹配與提及的差別,讀取段落的代理會如此說明。這就是 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

當問題與文件沒有共享詞彙時,全文搜尋會失效:「哪些合約對我們有風險?」 沒有關鍵字。當詞彙共享時則表現良好,這描述了大多數人對自己文件的提問:條款名稱、產品、客戶、發票號碼、日期範圍。若查詢未命中,代理會嘗試 renewal OR renews 或模糊匹配,就像人類一樣。伺服器會協助:未加引號的兩字查詢在 GroupDocs.Search 中不會匹配任何結果,空結果會帶有 hint,告訴代理去加引號。

哪個工具對應哪個問題?

使用者提問 代理呼叫
「索引此資料夾」 add_to_index
「哪些檔案提到 X?」 search
「X 的說明是什麼?」 get_text_fragments
「檔案變更,請刷新」 update_index
「忘記草稿資料夾」 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 引擎,其全新索引格式使索引體積更小,記憶體使用量約減半(release notes)。

誠實的限制

  • 評估模式下,索引最多容納 100 份文件,搜尋最多返回 10 筆;每個回應都會說明此限制。請先呼叫 get_license_status。
  • 這是全文搜尋,而非語意搜尋:匹配的是字詞,而非意義。
  • 不支援 OCR:掃描的 PDF 若沒有文字層,僅會根據檔案屬性建立索引。
  • 僅以 Docker 映像方式提供(打包工具超過 NuGet 大小限制)。

常見問答

Claude 能在本機搜尋我的文件而不上傳嗎?
可以。伺服器在你的機器上以容器執行,讀取你掛載的資料夾;只有代理引用的段落會傳遞給模型。

這是 RAG 嗎?
它屬於檢索增強(retrieval‑augmented),但以代理方式實作:模型自行決定何時搜尋、何時停止,使用全文索引取代嵌入向量。

文件變更時會發生什麼事?
請讓代理刷新。update_index 只會重新讀取已變更、已新增或已刪除的檔案。

深入了解