MySQLSearchTool

描述

此工具旨在促进 MySQL 数据库表中的语义搜索。MySQLSearchTool 利用 RAG(检索与生成)技术,为用户提供了一种高效的方式来查询数据库表内容,专门针对 MySQL 数据库进行优化。它通过语义搜索查询简化了查找相关数据的过程,对于需要在 MySQL 数据库中对大量数据集执行高级查询的用户来说,它是一种宝贵的资源。

安装

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

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 进行嵌入和摘要。要自定义模型,可以使用如下配置字典:

代码
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",
            config=dict(
                model="models/embedding-001",
                task_type="retrieval_document",
                # title="Embeddings",
            ),
        ),
    )
)