跳转到主要内容

PDF 搜索工具

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

描述

PDFSearchTool 是一款专为 PDF 内容语义搜索而设计的 RAG 工具。它允许输入搜索查询和 PDF 文档,利用先进的搜索技术高效地查找相关内容。这一功能使其在从大型 PDF 文件中快速提取特定信息方面特别有用。

安装

要开始使用 PDFSearchTool,请首先确保使用以下命令安装了 crewai_tools 包:
pip install 'crewai[tools]'

示例

以下是如何使用 PDFSearchTool 在 PDF 文档中进行搜索:
代码
from crewai_tools import PDFSearchTool

# Initialize the tool allowing for any PDF content search if the path is provided during execution
tool = PDFSearchTool()

# OR

# Initialize the tool with a specific PDF path for exclusive search within that document
tool = PDFSearchTool(pdf='path/to/your/document.pdf')

参数

  • pdf可选 搜索的 PDF 路径。可以在初始化时或在 run 方法的参数中提供。如果在初始化时提供,该工具会将其搜索范围限制在指定的文档内。

自定义模型和嵌入

默认情况下,该工具使用 OpenAI 进行嵌入和摘要。要自定义模型,您可以使用如下所示的配置字典:
代码
tool = PDFSearchTool(
    config=dict(
        llm=dict(
            provider="ollama", # or google, openai, anthropic, llama2, ...
            config=dict(
                model="llama2",
                # temperature=0.5,
                # top_p=1,
                # stream=true,
            ),
        ),
        embedder=dict(
            provider="google", # or openai, ollama, ...
            config=dict(
                model="models/embedding-001",
                task_type="retrieval_document",
                # title="Embeddings",
            ),
        ),
    )
)