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

CSV RAG 搜索

CSVSearchTool 是一个强大的 RAG(检索增强生成)工具,专为在 CSV 文件内容中执行语义搜索而设计。

CSVSearchTool

NOTE

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

描述

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

安装

安装 crewai_tools 包

shell
pip install 'crewai[tools]'

示例

python
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 的行为:

参数类型描述
csvstring可选。要搜索的 CSV 文件路径。如果该工具在初始化时未指定特定 CSV 文件,则此参数为必填;否则为可选。

自定义模型和嵌入

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

python
from chromadb.config import Settings

tool = CSVSearchTool(
    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),
            }
        },
    }
)

## Security

### Path Validation

File paths provided to this tool are validated against the current working directory. Paths that resolve outside the working directory are rejected with a `ValueError`.

To allow paths outside the working directory (for example, in tests or trusted pipelines), set the environment variable:

CREWAI_TOOLS_ALLOW_UNSAFE_PATHS=true


### URL Validation

URL inputs are validated: `file://` URIs and requests targeting private or reserved IP ranges are blocked to prevent server-side request forgery (SSRF) attacks.

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.

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