MindSQL

发布于:2024-04-15 ⋅ 阅读:(100) ⋅ 点赞:(0)

在这里插入图片描述


关于 MindSQL

MindSQL 是一个 Python RAG 库,旨在仅使用几行代码来简化用户与其数据库之间的交互。
MindSQL 与 PostgreSQL、MySQL、SQLite 等知名数据库无缝集成,还通过扩展接口将其功能扩展到 Snowflake、BigQuery 等主流数据库IDatabase。
该库利用 GPT-4、Llama 2、Google Gemini 等大型语言模型 (LLM),并支持 ChromaDB 和 Faiss 等知识库。


结构

在这里插入图片描述


安装

需要 Python 3.10+

pip install mindsql

代码调用

# !pip install mindsql

from mindsql.core import MindSQLCore
from mindsql.databases import Sqlite
from mindsql.llms import GoogleGenAi
from mindsql.vectorstores import ChromaDB

# Add Your Configurations
config = {"api_key": "YOUR-API-KEY"}

# Choose the Vector Store. LLM and DB You Want to Work With And
# Create MindSQLCore Instance With Configured Llm, Vectorstore, And Database
minds = MindSQLCore(
    llm=GoogleGenAi(config=config),
    vectorstore=ChromaDB(),
    database=Sqlite()
)

# Create a Database Connection Using The Specified URL
connection = minds.database.create_connection(url="YOUR_DATABASE_CONNECTION_URL")

# Index All Data Definition Language (DDL) Statements in The Specified Database Into The Vectorstore
minds.index_all_ddls(connection=connection, db_name='NAME_OF_THE_DB')

# Index Question-Sql Pair in Bulk From the Specified Example Path
minds.index(bulk=True, path="your-qsn-sql-example.json")

# Ask a Question to The Database And Visualize The Result
response = minds.ask_db(
    question="YOUR_QUESTION",
    connection=connection,
    visualize=True
)

# Extract And Display The Chart From The Response
chart = response["chart"]
chart.show()

# Close The Connection to Your DB
connection.close()

📁 项目代码结构

  • _utils: 包含常量和记录器的实用程序模块。
  • _helper: 帮助模块。
  • core: 主要核心模块,minds_core.py.
  • 数据库: 数据库相关模块。
  • llms: 与语言模型相关的模块。
  • 测试: 测试脚本。
  • 矢量存储: 与矢量存储相关的模块。
  • 诗歌.lockpyproject.toml: 诗歌依赖项和配置文件。
  • 测试: 测试用例。

其它


2024-04-11(四)


网站公告

今日签到

点亮在社区的每一天
去签到