跳转至

MySQL搜索工具

描述

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

安装

要安装crewai_tools包并使用MySQL搜索工具,请在终端执行以下命令:

pip install 'crewai[tools]'

示例

以下示例展示了如何使用MySQL搜索工具在MySQL数据库中的表上进行语义搜索:

from crewai_tools import MySQLSearchTool

# 使用数据库URI和目标表名初始化工具
tool = MySQLSearchTool(db_uri='mysql://user:password@localhost:3306/mydatabase', table_name='employees')

参数

MySQL搜索工具运行时需要以下参数:

  • db_uri:一个字符串,表示要查询的MySQL数据库的URI。此参数是必需的,必须包含必要的身份验证详细信息以及数据库的位置。
  • table_name:一个字符串,指定数据库中将要进行语义搜索的表名。此参数是必需的。

自定义模型和嵌入

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

tool = MySQLSearchTool(
    config=dict(
        llm=dict(
            provider="ollama", # 或 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",
            ),
        ),
    )
)