AI Mind Tool
AIMindTool
Section titled “AIMindTool”AIMindTool 是对 MindsDB 提供的 AI-Minds 的封装。只需配置连接参数,它就允许你用自然语言查询数据源。这个工具适用于需要从各种数据源中获取答案的场景,包括 PostgreSQL、MySQL、MariaDB、ClickHouse、Snowflake 和 Google BigQuery。
Minds 是一种 AI 系统,工作方式类似大语言模型(LLMs),但它更进一步,能够从任意数据中回答任意问题。它通过以下方式实现:
- 使用参数化搜索选择最相关的数据来回答问题
- 通过语义搜索理解含义,并在正确上下文中给出响应
- 通过分析数据并使用机器学习(ML)模型提供精准答案
要把这个工具集成到项目中,需要安装 Minds SDK:
uv add minds-sdk要高效使用 AIMindTool,请按以下步骤操作:
- 安装包:确认你的 Python 环境中已安装
crewai[tools]和minds-sdk。 - 获取 API Key:在 这里 注册 Minds 账户,并获取 API key。
- 环境配置:将获取到的 API key 存入名为
MINDS_API_KEY的环境变量,方便该工具使用。
下面的示例展示了如何初始化工具并执行查询:
from crewai_tools import AIMindTool
# Initialize the AIMindToolaimind_tool = AIMindTool( datasources=[ { "description": "house sales data", "engine": "postgres", "connection_data": { "user": "demo_user", "password": "demo_password", "host": "samples.mindsdb.com", "port": 5432, "database": "demo", "schema": "demo_data" }, "tables": ["house_sales"] } ])
# Run a natural language queryresult = aimind_tool.run("How many 3 bedroom houses were sold in 2008?")print(result)AIMindTool 接受以下参数:
- api_key:可选。你的 Minds API key。如果未提供,会从
MINDS_API_KEY环境变量读取。 - datasources:字典列表,每个字典包含以下键:
- description:该 datasource 中数据的描述。
- engine:datasource 的引擎(或类型)。
- connection_data:包含 datasource 连接参数的字典。
- tables:该数据源将使用的表列表。可选;如果要使用数据源中的所有表,可以省略。
支持的数据源及其连接参数列表可在 这里 查看。
Agent 集成示例
Section titled “Agent 集成示例”下面展示如何将 AIMindTool 集成到 CrewAI agent 中:
from crewai import Agentfrom crewai.project import agentfrom crewai_tools import AIMindTool
# Initialize the toolaimind_tool = AIMindTool( datasources=[ { "description": "sales data", "engine": "postgres", "connection_data": { "user": "your_user", "password": "your_password", "host": "your_host", "port": 5432, "database": "your_db", "schema": "your_schema" }, "tables": ["sales"] } ])
# Define an agent with the AIMindTool@agentdef data_analyst(self) -> Agent: return Agent( config=self.agents_config["data_analyst"], allow_delegation=False, tools=[aimind_tool] )AIMindTool 提供了一种强大的方式,可以用自然语言查询数据源,从而无需编写复杂 SQL 就能更轻松地提取洞察。通过连接多种数据源并利用 AI-Minds 技术,该工具让 agents 能够高效访问和分析数据。