主题
MySQL RAG 搜索
MySQLSearchTool旨在搜索 MySQL 数据库并返回最相关的结果。
概述
该工具旨在促进 MySQL 数据库表内的语义搜索。借助 RAG(检索与生成)技术, MySQLSearchTool 为用户提供了一种高效的数据库表内容查询方式,并专门针对 MySQL 数据库定制。 它通过语义搜索查询简化了查找相关数据的过程,对于需要在 MySQL 数据库中的大规模数据集上执行高级查询的用户来说,是宝贵的资源。
安装
要安装 crewai_tools 包并使用 MySQLSearchTool,请在终端中执行以下命令:
shell
pip install 'crewai[tools]'示例
以下示例展示了如何使用 MySQLSearchTool 在 MySQL 数据库中的表上执行语义搜索:
python
from crewai_tools import MySQLSearchTool
# Initialize the tool with the database URI and the target table name
tool = MySQLSearchTool(
db_uri='mysql://user:password@localhost:3306/mydatabase',
table_name='employees'
)参数
MySQLSearchTool 运行需要以下参数:
db_uri:表示要查询的 MySQL 数据库 URI 的字符串。此参数为必需项,必须包含必要的身份认证详细信息以及数据库的位置。table_name:指定要在其中执行语义搜索的数据库内表名称的字符串。此参数为必需项。
自定义模型和嵌入
默认情况下,该工具使用 OpenAI 进行嵌入和摘要。要自定义模型,你可以使用如下配置字典:
python
tool = MySQLSearchTool(
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-generativeai",
config=dict(
model_name="gemini-embedding-001",
task_type="RETRIEVAL_DOCUMENT",
# title="Embeddings",
),
),
)
)