Prerequisites
Before proceeding, ensure the following prerequisites are met:- Install MindsDB locally via Docker or use MindsDB Cloud.
- To use LangChain within MindsDB, install the required dependencies following this instruction.
- Obtain the API key for a selected model (provider) that you want to use through LangChain.
Available models include the following:
- Anthropic (how to get the API key)
- OpenAI (how to get the API key)
- Anyscale (how to get the API key)
cloud.mindsdb.com/account.Setup
Create an AI engine from the LangChain handler.langchain_engine as an engine and one of OpenAI/Anthropic/Anyscale/LiteLLM as a model provider.
There are three different tools utilized by this agent:
- MindsDB is the internal MindsDB executor.
- Metadata fetches the metadata information for the available tables.
- Write is able to write agent responses into a MindsDB data source.
langchain_engine as an engine and one of OpenAI/Anthropic/Anyscale/LiteLLM as a model provider.
OpenAI
OpenAI
Anthropic
Anthropic
Anyscale
Anyscale
LiteLLM
LiteLLM
Usage
The following usage examples utilizelangchain_engine to create a model with the CREATE MODEL statement.
Create a model that will be used to describe, analyze, and retrieve.
tool_based_agent model using the LangChain engine, as defined in the engine parameter. This model answers users’ questions in a helpful way, as defined in the prompt_template parameter, which specifies input as the input column when calling the model.
Describe data
Query the model to describe data.mysql_demo_db.house_sales table, the agent uses the Metadata tool. Then the agent prepares the response.
Analyze data
Query the model to analyze data.beds column in the mysql_demo_db.home_rentals table, it uses the number_of_rooms column and writes the following query: