Skip to main content
LangChain LangChain is a framework for developing applications powered by language models. It enables developers to build context-aware applications that can reason about data and take actions. LangChain provides tools for connecting LLMs to various data sources, including databases, making it possible to query and analyze data using natural language. This guide shows you how to connect LangChain to Firebolt using the SQLAlchemy connector, enabling natural language interactions with your Firebolt database.

Prerequisites

Before you begin, ensure you have the following prerequisites:
  1. Python installation: You need Python 3.8 or higher installed on your machine. You can download it from python.org.
  2. Firebolt account: You need an active Firebolt account with a configured database and engine. If you don’t have one, you can sign up for free.
  3. Firebolt credentials: Create a service account in Firebolt and note its client ID and secret.
  4. LLM API key: You’ll need an API key from a supported LLM provider to power the natural language processing. This guide uses OpenAI as an example, but LangChain supports many other chat model providers. You can obtain an OpenAI API key from the OpenAI website.

Connecting to Firebolt with LangChain

1. Install Required Packages

Install the necessary Python packages. This example uses OpenAI, but you can install packages for any LangChain-supported chat model:

2. Set Up Environment Variables

For security best practices, store your credentials as environment variables. This example uses OpenAI, but you can use any LangChain-supported model:

3. Configure the Connection

Connect to Firebolt using a SQLAlchemy engine. You’ll need to provide your Firebolt credentials and the database connection details: The SQLAlchemy connection string is the key component that enables LangChain integration with Firebolt. This example uses OpenAI, but you can substitute with any LangChain-supported chat model:

Usage Examples

Basic Database Analysis

Natural Language Queries

Advanced Analytics

Compatibility and Limitations

  • LangChain Versions: This integration is compatible with LangChain 0.1.0 and later versions.
  • Performance: For large datasets, consider using appropriate filters and limits in your natural language prompts to optimize query performance.
  • Token Limits: Be aware of LLM token limits when working with large schema descriptions or query results.

Further Reading