CSVSearchTool

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

描述

此工具用于在 CSV 文件内容中执行 RAG(检索增强生成)搜索。它允许用户在指定的 CSV 文件内容中对查询进行语义搜索。此功能对于从大型 CSV 数据集中提取信息特别有用,因为传统搜索方法可能效率低下。所有名称中包含“Search”的工具,包括 CSVSearchTool,都是为搜索不同数据源而设计的 RAG 工具。

安装

安装 crewai_tools 包

pip install 'crewai[tools]'

示例

代码
from crewai_tools import CSVSearchTool

# Initialize the tool with a specific CSV file. 
# This setup allows the agent to only search the given CSV file.
tool = CSVSearchTool(csv='path/to/your/csvfile.csv')

# OR

# Initialize the tool without a specific CSV file. 
# Agent will need to provide the CSV path at runtime.
tool = CSVSearchTool()

参数

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

参数类型描述
csv字符串可选。您要搜索的 CSV 文件的路径。如果工具初始化时未指定 CSV 文件,则此参数为必需;否则为可选。

自定义模型和嵌入

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

代码
tool = CSVSearchTool(
    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",
            ),
        ),
    )
)