Skip to content
CrewAI 文档版本 跟随上游 源快照 13103368 更新于 2026-10-18

DOCX RAG 搜索

DOCXSearchTool 是一个 RAG 工具,专为在 DOCX 文档中执行语义搜索而设计。

DOCXSearchTool

NOTE

我们仍在改进这些工具,因此未来可能会出现意外行为或变更。

描述

DOCXSearchTool 是一个 RAG 工具,专为在 DOCX 文档中执行语义搜索而设计。 它使用户能够通过基于查询的搜索,有效地从 DOCX 文件中搜索并提取相关信息。 对于数据分析、信息管理和研究任务,此工具非常宝贵, 可简化在大型文档集合中查找特定信息的过程。

安装

在终端中运行以下命令安装 crewai_tools 包:

shell
uv pip install docx2txt 'crewai[tools]'

示例

以下示例演示如何初始化 DOCXSearchTool,以在任意 DOCX 文件的内容中搜索,或使用特定的 DOCX 文件路径进行搜索。

python
from crewai_tools import DOCXSearchTool

# Initialize the tool to search within any DOCX file's content
tool = DOCXSearchTool()

# OR

# Initialize the tool with a specific DOCX file, 
# so the agent can only search the content of the specified DOCX file
tool = DOCXSearchTool(docx='path/to/your/document.docx')

参数

以下参数可用于自定义 DOCXSearchTool 的行为:

参数类型描述
docxstring可选。指定要搜索的 DOCX 文件路径的参数。如果在初始化时未提供,该工具允许稍后指定任意 DOCX 文件的内容路径进行搜索。

自定义模型和嵌入

默认情况下,该工具使用 OpenAI 进行嵌入和摘要。要自定义模型,你可以使用如下配置字典:

python
from chromadb.config import Settings

tool = DOCXSearchTool(
    config={
        "embedding_model": {
            "provider": "openai",
            "config": {
                "model": "text-embedding-3-small",
                # "api_key": "sk-...",
            },
        },
        "vectordb": {
            "provider": "chromadb",  # or "qdrant"
            "config": {
                # "settings": Settings(persist_directory="/content/chroma", allow_reset=True, is_persistent=True),
                # from qdrant_client.models import VectorParams, Distance
                # "vectors_config": VectorParams(size=384, distance=Distance.COSINE),
            }
        },
    }
)

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。