Giter Site home page Giter Site logo

mindinventory / mindsql Goto Github PK

View Code? Open in Web Editor NEW
93.0 7.0 6.0 81 KB

MindSQL: A Python Text-to-SQL RAG Library simplifying database interactions. Seamlessly integrates with PostgreSQL, MySQL, SQLite, Snowflake, and BigQuery. Powered by GPT-4 and Llama 2, it enables natural language queries. Supports ChromaDB and Faiss for context-aware responses.

Home Page: https://www.mindinventory.com/text-to-sql-mindsql.php?utm_source=sampromotiion&utm_medium=Button&utm_campaign=sampromotion&utm_id=sampromotion&utm_term=sampromotiion&utm_content=sampromotiion

License: GNU General Public License v3.0

Python 100.00%
chatbot gemini langchain rag retrival-augmented text-to-sql

mindsql's Introduction

๐Ÿง  MindSQL

MindSQL is a Python RAG (Retrieval-Augmented Generation) Library designed to streamline the interaction between users and their databases using just a few lines of code. With seamless integration for renowned databases such as PostgreSQL, MySQL, and SQLite, MindSQL also extends its capabilities to major databases like Snowflake and BigQuery by extending the IDatabase Interface. This library utilizes large language models (LLM) like GPT-4, Llama 2, Google Gemini, and supports knowledge bases like ChromaDB and Faiss.

MindSQL Chart

๐Ÿš€ Installation

To install MindSQL, you can use pip:

pip install mindsql

MindSQL requires Python 3.10 or higher.

๐Ÿ’ก Usage

# !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()

๐Ÿ“ Code Structure

  • _utils: Utility modules containing constants and a logger.
  • _helper: The helper module.
  • core: The main core module, minds_core.py.
  • databases: Database-related modules.
  • llms: Modules related to Language Models.
  • testing: Testing scripts.
  • vectorstores: Modules related to vector stores.
  • poetry.lock and pyproject.toml: Poetry dependencies and configuration files.
  • tests: Testcases.

๐Ÿค Contributing Guidelines

Thank you for considering contributing to our project! Please follow these guidelines for smooth collaboration:

  1. Fork the repository and create your branch from master.

  2. Ensure your code adheres to our coding standards and conventions.

  3. Test your changes thoroughly and add a test case in the tests folder.

  4. Submit a pull request with a clear description of the problem and solution.

    Learn more

๐Ÿ› Bug Reports

If you encounter a bug while using MindSQL, help us resolve it by following these steps:

  1. Check existing issues to see if the bug has been reported.

  2. If not, open a new issue with a detailed description, including steps to reproduce and relevant screenshots or error messages.

    Learn more

๐Ÿš€ Feature Requests

We welcome suggestions for new features or improvements to MindSQL. Here's how you can request a new feature:

  1. Check existing feature requests to avoid duplication.

  2. If your feature request is unique, open a new issue and describe the feature you would like to see.

  3. Provide as much context and detail as possible to help us understand your request.

    Learn more

๐Ÿ“ฃ Feedback

We value your feedback and strive to improve MindSQL. Here's how you can share your thoughts with us:

  • Open an issue to provide general feedback, suggestions, or comments.
  • Be constructive and specific in your feedback to help us understand your perspective better.

Thank you for your interest in contributing to our project! We appreciate your support and look forward to working with you. ๐Ÿš€

๐ŸŒŸ Contributors

GitHub Profile Link + Image Name
siddhant-mi Siddhant Pandey
ishika-mi Ishika Shah
Hasmukhsuthar05 Hasmukh Suthar
krishna-thakkar-mi Krishna Thakkar
UjjawalKRoy Ujjawal Roy

mindsql's People

Contributors

ishika-mi avatar sammindinventory avatar siddhant-mi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mindsql's Issues

minds.ask_db() : list index out of range

I am trying to run a local Llama 2 model against my SQL database on ubuntu. However, I'm encountering the following range error.

WARNING โ€” 2024-03-07 03:27:38,715 โ€” Minds Core โ€” Function:ask_db โ€” Line:498 โ€” An unexpected error occurred: list index out of range
Res: {'error': 'list index out of range'}

Here is the code:

from mindsql.core.mindsql_core import MindSQLCore
from mindsql.llms import LlamaCpp
from mindsql.databases import MySql
from mindsql.vectorstores import Faiss

config = {
    "model_path": "/home/guitmonk/Downloads/llama-2-7b.Q3_K_L.gguf"
}

class MindSqlGenAI(Faiss, LlamaCpp, MySql):
    def __init__(self, config=config):
        Faiss.__init__(self, config=config)
        LlamaCpp.__init__(self, config=config)
        MySql.__init__(self, config=config)

minds = MindSqlGenAI(config=config)
connection = minds.create_connection(<SQL_URL>)

# Index DB Schmas
ddls = minds.get_all_ddls(connection=connection, database="test")

for ind in ddls.index:
    minds.index_ddl(ddls["DDL"][ind])

# Provide Example query-SQL pairs
minds.index(bulk=False, path="examples.json")

# ask questions
res = minds.ask_db(question="How many total clients are there?", connection=connection)
print("Res: ", res)

connection.close()

I've tried to debug it but I'm not sure where is this error originating from.

Adding custom configurations for Llama

The context window in Llama is set to 512 by default. This can cause the prompt size to exceed the context window size if the DB schema is large enough.

It would be great if custom configuration for the Llama function from LlamaCpp can be passed in the config object for better control.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.