Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKQA over structured dataSQLRetrieval-augmented generation (RAG)Interacting with APIsChatbotsExtractionSummarizationTaggingWeb scrapingSynthetic data generationGraph queryingQA over structured dataSQLOn this pageSQLUse case‚ÄãEnterprise data is often stored in SQL databases.LLMs make it possible to interact with SQL databases using natural language.LangChain offers SQL Chains and Agents to build and run SQL queries based on natural language prompts. These are compatible with any SQL dialect supported by SQLAlchemy (e.g., MySQL, PostgreSQL, Oracle SQL, Databricks, SQLite).They enable use cases such as:Generating queries that will be run based on natural language questionsCreating chatbots that can answer questions based on database dataBuilding custom dashboards based on insights a user wants to analyzeOverview‚ÄãLangChain provides tools to interact with SQL Databases:Build SQL queries based on natural language user questionsQuery a SQL database using chains for query creation and executionInteract with a SQL database using agents for robust and flexible querying Quickstart‚ÄãFirst, get required packages and set environment variables:pip install langchain langchain-experimental openai# Set env var OPENAI_API_KEY or load from a .env file# import dotenv# dotenv.load_dotenv()The below example will use a SQLite connection with Chinook database. Follow installation steps to create Chinook.db in the same directory as this notebook:Save this file to the directory as Chinook_Sqlite.sqlRun sqlite3 Chinook.dbRun .read Chinook_Sqlite.sqlTest SELECT * FROM Artist LIMIT 10;Now, Chinhook.db is in our directory.Let's create a SQLDatabaseChain to create and execute SQL queries.from langchain.utilities import SQLDatabasefrom langchain.llms import OpenAIfrom langchain_experimental.sql import SQLDatabaseChaindb = SQLDatabase.from_uri("sqlite:///Chinook.db")llm =
Open In Colab
Open In Colab ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKQA over structured dataSQLRetrieval-augmented generation (RAG)Interacting with APIsChatbotsExtractionSummarizationTaggingWeb scrapingSynthetic data generationGraph queryingQA over structured dataSQLOn this pageSQLUse case‚ÄãEnterprise data is often stored in SQL databases.LLMs make it possible to interact with SQL databases using natural language.LangChain offers SQL Chains and Agents to build and run SQL queries based on natural language prompts. These are compatible with any SQL dialect supported by SQLAlchemy (e.g., MySQL, PostgreSQL, Oracle SQL, Databricks, SQLite).They enable use cases such as:Generating queries that will be run based on natural language questionsCreating chatbots that can answer questions based on database dataBuilding custom dashboards based on insights a user wants to analyzeOverview‚ÄãLangChain provides tools to interact with SQL Databases:Build SQL queries based on natural language user questionsQuery a SQL database using chains for query creation and executionInteract with a SQL database using agents for robust and flexible querying Quickstart‚ÄãFirst, get required packages and set environment variables:pip install langchain langchain-experimental openai# Set env var OPENAI_API_KEY or load from a .env file# import dotenv# dotenv.load_dotenv()The below example will use a SQLite connection with Chinook database. Follow installation steps to create Chinook.db in the same directory as this notebook:Save this file to the directory as Chinook_Sqlite.sqlRun sqlite3 Chinook.dbRun .read Chinook_Sqlite.sqlTest SELECT * FROM Artist LIMIT 10;Now, Chinhook.db is in our directory.Let's create a SQLDatabaseChain to create and execute SQL queries.from langchain.utilities import SQLDatabasefrom langchain.llms import OpenAIfrom langchain_experimental.sql import SQLDatabaseChaindb = SQLDatabase.from_uri("sqlite:///Chinook.db")llm =