useful for cases in which the number of tables in the database is large.This Sequential Chain handles the process of:Determining which tables to use based on the user questionCalling the normal SQL database chain using only relevant tablesAdding Sample RowsProviding sample data can help the LLM construct correct queries when the data format is not obvious. For example, we can tell LLM that artists are saved with their full names by providing two rows from the Track table.db = SQLDatabase.from_uri(    "sqlite:///Chinook.db",    include_tables=['Track'], # we include only one table to save tokens in the prompt :)    sample_rows_in_table_info=2)The sample rows are added to the prompt after each corresponding table's column information.We can use db.table_info and check which sample rows are included:print(db.table_info)        CREATE TABLE "Track" (        "TrackId" INTEGER NOT NULL,         "Name" NVARCHAR(200) NOT NULL,         "AlbumId" INTEGER,         "MediaTypeId" INTEGER NOT NULL,         "GenreId" INTEGER,         "Composer" NVARCHAR(220),         "Milliseconds" INTEGER NOT NULL,         "Bytes" INTEGER,         "UnitPrice" NUMERIC(10, 2) NOT NULL,         PRIMARY KEY ("TrackId"),         FOREIGN KEY("MediaTypeId") REFERENCES "MediaType" ("MediaTypeId"),         FOREIGN KEY("GenreId") REFERENCES "Genre" ("GenreId"),         FOREIGN KEY("AlbumId") REFERENCES "Album" ("AlbumId")    )        /*    2 rows from Track table:    TrackId Name    AlbumId MediaTypeId GenreId Composer    Milliseconds    Bytes   UnitPrice    1   For Those About To Rock (We Salute You) 1   1   1   Angus Young, Malcolm Young, Brian Johnson   343719  11170334    0.99    2   Balls to the Wall   2   2   1   None    342562  5510424 0.99    */Case 3: SQL agents‚ÄãLangChain has an SQL Agent which provides a more flexible way of interacting with SQL Databases than the SQLDatabaseChain.The main advantages of using the SQL Agent are:It can answer questions based on the databases' schema as well as
Open In Colab
Open In Colab ->: useful for cases in which the number of tables in the database is large.This Sequential Chain handles the process of:Determining which tables to use based on the user questionCalling the normal SQL database chain using only relevant tablesAdding Sample RowsProviding sample data can help the LLM construct correct queries when the data format is not obvious. For example, we can tell LLM that artists are saved with their full names by providing two rows from the Track table.db = SQLDatabase.from_uri(    "sqlite:///Chinook.db",    include_tables=['Track'], # we include only one table to save tokens in the prompt :)    sample_rows_in_table_info=2)The sample rows are added to the prompt after each corresponding table's column information.We can use db.table_info and check which sample rows are included:print(db.table_info)        CREATE TABLE "Track" (        "TrackId" INTEGER NOT NULL,         "Name" NVARCHAR(200) NOT NULL,         "AlbumId" INTEGER,         "MediaTypeId" INTEGER NOT NULL,         "GenreId" INTEGER,         "Composer" NVARCHAR(220),         "Milliseconds" INTEGER NOT NULL,         "Bytes" INTEGER,         "UnitPrice" NUMERIC(10, 2) NOT NULL,         PRIMARY KEY ("TrackId"),         FOREIGN KEY("MediaTypeId") REFERENCES "MediaType" ("MediaTypeId"),         FOREIGN KEY("GenreId") REFERENCES "Genre" ("GenreId"),         FOREIGN KEY("AlbumId") REFERENCES "Album" ("AlbumId")    )        /*    2 rows from Track table:    TrackId Name    AlbumId MediaTypeId GenreId Composer    Milliseconds    Bytes   UnitPrice    1   For Those About To Rock (We Salute You) 1   1   1   Angus Young, Malcolm Young, Brian Johnson   343719  11170334    0.99    2   Balls to the Wall   2   2   1   None    342562  5510424 0.99    */Case 3: SQL agents‚ÄãLangChain has an SQL Agent which provides a more flexible way of interacting with SQL Databases than the SQLDatabaseChain.The main advantages of using the SQL Agent are:It can answer questions based on the databases' schema as well as