CSVSearchTool
实验性:我们仍在努力改进工具,因此未来可能会出现意外行为或更改。
此工具用于在 CSV 文件的内容中执行 RAG (Retrieval-Augmented Generation) 搜索。它允许用户在指定的 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 进行嵌入和摘要。要自定义模型,您可以使用如下所示的配置字典:
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),
}
},
}
)