Skip to content

πŸš€ Quickstart

siddhant-mi edited this page Mar 11, 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, create a MindSQLCore instance by specifying the LLM, vector store, and database components. Here's an example using Google GenAi as the LLM, ChromaDB as the vector store, and Sqlite as the database:

    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"}
    
    # Create MindSQLCore Instance
    minds = MindSQLCore(
        llm=GoogleGenAi(config=config),
        vectorstore=ChromaDB(),
        database=Sqlite()
    )
  • Now, the minds object becomes the primary interface for interacting with the MindSQL package. Let's begin by establishing a connection with our database.

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

    With this connection established, you are ready to utilize the functionalities of MindSQL for your project.

πŸ“‘ Index DDL Statements:

  • Use the index_all_ddls method to retrieve and index all Data Definition Language (DDL) statements from the specified database into the vector store.

    # 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')

⚑ 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()