跳转到内容

MySQL RAG Search

这个工具专为在 MySQL 数据库表中进行语义搜索而设计。借助 RAG(Retrieve and Generate)技术, MySQLSearchTool 为用户提供了一种高效查询数据库表内容的方式,特别适合 MySQL 数据库。 它通过语义搜索查询简化了查找相关数据的过程,对于需要在 MySQL 数据库中的大规模数据集上执行高级查询的用户来说,这是一个非常有价值的资源。

要安装 crewai_tools 包并使用 MySQLSearchTool,请在终端中执行以下命令:

Terminal window
pip install 'crewai[tools]'

下面是一个示例,展示如何使用 MySQLSearchTool 在 MySQL 数据库中的表上执行语义搜索:

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 进行 embeddings 和 summarization。你可以使用如下 config 字典自定义模型:

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",
),
),
)
)