Skip to content

πŸš€ Quickstart

siddhant-mi edited this page Mar 5, 2024 · 3 revisions

Here's a quick start guide for using the Minds SQL Core project:

πŸ› οΈ Set Up Configuration:

  • Ensure you have the necessary environment variables set up in a .env file or your environment configuration. These variables include:
    1. API_KEY: Your API key for authentication with LLMs like OpenAI, Gemini, LLAMA, etc.
    2. DB_URL: The URL or connection string for your database.
    3. EXAMPLE_PATH: The path to any example JSON files or data you may want to use for bulk indexing.

🎬 Initialize a Class:

  • 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.

πŸ“‘ Retrieve and Index DDL Statements:

  • 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])

⚑ Execute Database Queries:

  • 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 to True.

    response = minds.ask_db(question="YOUR-QUESTION", connection=conn, visualize=True, table_names=['TABLE_NAME'])

πŸ“Š Visualization:

  • Visualize the data using the returned chart object.

    chart = response["chart"]
    chart.show()
  • Close the DB connection once you are done:

    conn.close()
Clone this wiki locally