PDFSearchTool

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

描述

PDFSearchTool 是一个 RAG 工具,专为 PDF 内容中的语义搜索而设计。它允许输入搜索查询和 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",
            ),
        ),
    )
)