-
Notifications
You must be signed in to change notification settings - Fork 21
π Quickstart
Here's a quick start guide for using the Minds SQL Core project:
- Ensure you have the necessary environment variables set up in a
.env
file or your environment configuration. These variables include:- API_KEY: Your API key for authentication with LLMs like OpenAI, Gemini, LLAMA, etc.
- DB_URL: The URL or connection string for your database.
- EXAMPLE_PATH: The path to any example JSON files or data you may want to use for bulk indexing.
-
To harness the power of MindSQL, begin by creating a Python class that extends three essential components: a database class, a vector store, and an LLm class. A basic MindSQL class could look like this:
from mindsql.databases import DATABASE from mindsql.llms import LLM from mindsql.vectorstores import VECTORSTORE load_dotenv() api_key = os.getenv('API_KEY') db_url = os.getenv('DB_URL') example_path = os.getenv('EXAMPLE_PATH') class MyClass(DATABASE, LLM, VECTORSTORE): def __init__(self, config): DATABASE.__init__(self, config=config) LLM.__init__(self, config=config) VECTORSTORE.__init__(self, config=config)
-
Once you have created the class you can instantiate it by passing the appropriate configs like this:
config = {'api_key': api_key} minds = MyClass(config=config)
-
Now, the minds object becomes the primary interface for interacting with the MindSQL package. Let's begin by establishing a connection with our database.
conn = minds.create_connection(url=db_url)
With this connection established, you are ready to utilize the functionalities of MindSQL for your project.
-
Use the get_all_ddls method to retrieve all DDL (Data Definition Language) statements from the database.
-
Index the retrieved DDL statements into the vector store using the index_ddl method.
ddls = minds.get_all_ddls(connection=conn, database='YOUR-DATABASE-NAME') for ind in ddls.index: minds.index_ddl(ddls["DDL"][ind])
-
Use the
ask_db
method to execute database queries and retrieve results. -
Provide the question, database connection, and optional parameters like table names or visualization preferences.
-
The
ask_db
method can optionally generate charts based on the query results if the visualize parameter is set toTrue
.response = minds.ask_db(question="YOUR-QUESTION", connection=conn, visualize=True, table_names=['TABLE_NAME'])
-
Visualize the data using the returned chart object.
chart = response["chart"] chart.show()
-
Close the DB connection once you are done:
conn.close()