{"id":46811,"date":"2024-09-10T00:00:00","date_gmt":"2024-09-10T07:00:00","guid":{"rendered":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/"},"modified":"2025-11-13T12:57:05","modified_gmt":"2025-11-13T20:57:05","slug":"interact-with-griddb-data-using-a-langchain-chatbot","status":"publish","type":"post","link":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/","title":{"rendered":"Interact with GridDB Data Using a LangChain Chatbot"},"content":{"rendered":"<p>This article demonstrates creating an interactive LangChain chatbot to retrieve information from a GridDB database using natural language queries. We will use the Python <a href=\"https:\/\/python.langchain.com\/v0.2\/docs\/introduction\/\">LangChain library<\/a> and the <a href=\"https:\/\/openai.com\/index\/hello-gpt-4o\/\">OpenAI GPT-4o<\/a> LLM (Large Language Model), to convert natural language queries into GridDB queries to interact seamlessly with the database.<\/p>\n<h2>Source code And Jupyter Notebook<\/h2>\n<p>You can find the source code (jupyter notebook) from our github repo:<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-sh\">$ git clone https:\/\/github.com\/griddbnet\/Blogs.git --branch chatbot<\/code><\/pre>\n<\/div>\n<h2>Prerequisites<\/h2>\n<p>You need to install the following libraries to run codes in this article:<\/p>\n<ol>\n<li>GridDB C Client<\/li>\n<li>GridDB Python client<\/li>\n<\/ol>\n<p>Follow the instructions on the <a href=\"https:\/\/pypi.org\/project\/griddb-python\/\">GridDB Python Package Index (Pypi)<\/a> page to install these clients.<\/p>\n<p>You must also install LangChain, Numpy, Pandas, and Seaborn libraries.<\/p>\n<p>The scripts below install and import the libraries you will need to run the code in this blog.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-bash\">!pip install langchain\n!pip install langchain-core\n!pip install langchain-openai\n!pip install langchain-experimental\n!pip install tabulate<\/code><\/pre>\n<\/div>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">import griddb_python as griddb\nimport pandas as pd\nfrom langchain_openai import OpenAI\nfrom langchain_openai import ChatOpenAI\nfrom langchain_core.prompts import ChatPromptTemplate\nfrom langchain_core.pydantic_v1 import BaseModel, Field\nfrom langchain.agents.agent_types import AgentType\nfrom langchain_experimental.agents.agent_toolkits import create_pandas_dataframe_agent\nfrom langchain.memory import ConversationBufferMemory\nfrom langchain.chains import ConversationChain\nfrom typing import List, Dict<\/code><\/pre>\n<\/div>\n<h2>Creating a Connection with GridDB<\/h2>\n<p>To interact with GridDB via a LangChain chatbot, you must create a connection with GridDB instance. To do so, you must create an object of the <code>StoreFactory<\/code> class using the <code>get_instance()<\/code> method. Next, call the <code>get_store()<\/code> method on the factor object and pass it the database hostname, cluster name, user, and password parameters.<\/p>\n<p>In the following script, we create a connection with a GridDB instance and test if the connection is successful by creating a container object.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">factory = griddb.StoreFactory.get_instance()\n\nDB_HOST = \"127.0.0.1:10001\"\nDB_CLUSTER = \"myCluster\"\nDB_USER = \"admin\"\nDB_PASS = \"admin\"\n\ntry:\n    gridstore = factory.get_store(\n        notification_member = DB_HOST,\n        cluster_name = DB_CLUSTER,\n        username = DB_USER,\n        password = DB_PASS\n    )\n\n    container1 = gridstore.get_container(\"container1\")\n    if container1 == None:\n        print(\"Container does not exist\")\n    print(\"Successfully connected to GridDB\")\n\nexcept griddb.GSException as e:\n    for i in range(e.get_error_stack_size()):\n        print(\"[\", i, \"]\")\n        print(e.get_error_code(i))\n        print(e.get_location(i))\n        print(e.get_message(i))\n<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<pre><code>Container does not exist\nSuccessfully connected to GridDB\n<\/code><\/pre>\n<p>If the connection is successful, you should see the above message. Else, you can verify your credentials and try again.<\/p>\n<h2>Inserting Sample Data Into GridDB<\/h2>\n<p>We will create a Chatbot that will return information from a GridDB container.<\/p>\n<p>We will create a GridDB container that contains world population statistics of different countries from 1970 to 2022. You can find more details about the dataset in my previous article on <a href=\"https:\/\/griddb.net\/en\/blog\/analyzing-world-population-data-in-python\/\">world population data analysis using GridDB<\/a>.<\/p>\n<p>You can <a href=\"https:\/\/www.kaggle.com\/datasets\/iamsouravbanerjee\/world-population-dataset\">download the dataset from Kaggle<\/a>. The script below the <code>world_population.csv<\/code> you downloaded into a Pandas DataFrame.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">## Dataset link: https:\/\/www.kaggle.com\/datasets\/iamsouravbanerjee\/world-population-dataset\n\ndataset = pd.read_csv(r\"\/home\/mani\/GridDB Projects\/world_population.csv\")\nprint(dataset.shape)\ndataset.head()<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2024\/09\/img1-sample-population-dataset.png\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2024\/09\/img1-sample-population-dataset.png\" alt=\"\" width=\"1212\" height=\"292\" class=\"aligncenter size-full wp-image-30230\" srcset=\"\/wp-content\/uploads\/2024\/09\/img1-sample-population-dataset.png 1212w, \/wp-content\/uploads\/2024\/09\/img1-sample-population-dataset-300x72.png 300w, \/wp-content\/uploads\/2024\/09\/img1-sample-population-dataset-1024x247.png 1024w, \/wp-content\/uploads\/2024\/09\/img1-sample-population-dataset-768x185.png 768w, \/wp-content\/uploads\/2024\/09\/img1-sample-population-dataset-600x145.png 600w\" sizes=\"(max-width: 1212px) 100vw, 1212px\" \/><\/a><\/p>\n<p>You can see that the dataset contains information such as country population, capital, continent, etc.<\/p>\n<p>The dataset column contains special characters you must remove since GridDB doesn&#8217;t allow containers with column names to have special characters.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">dataset.columns = dataset.columns.str.replace('[^a-zA-Z0-9]', '_', regex=True)\ndataset.dtypes<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2024\/09\/img2-dataset-column-types.png\"><img decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2024\/09\/img2-dataset-column-types.png\" alt=\"\" width=\"402\" height=\"390\" class=\"aligncenter size-full wp-image-30231\" srcset=\"\/wp-content\/uploads\/2024\/09\/img2-dataset-column-types.png 402w, \/wp-content\/uploads\/2024\/09\/img2-dataset-column-types-300x291.png 300w\" sizes=\"(max-width: 402px) 100vw, 402px\" \/><\/a><\/p>\n<p>Next, we must map the DataFrame columns to the GridDB-compliant column types before inserting data into a GridDB container.<\/p>\n<p>The following script inserts the data from the <code>dataset<\/code> DataFrame into a <code>PopulationStats<\/code> GridDB container.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\"># see all GridDB data types: https:\/\/docs.griddb.net\/architecture\/data-model\/#data-type\n\ndef map_pandas_dtype_to_griddb(dtype):\n    if dtype == 'int64':\n        return griddb.Type.LONG\n    elif dtype == 'float64':\n        return griddb.Type.FLOAT\n    elif dtype == 'object':\n        return griddb.Type.STRING\n    # Add more column types if you want\n    else:\n        raise ValueError(f'Unsupported pandas type: {dtype}')\n\ncontainer_columns = []\nfor column_name, dtype in dataset.dtypes.items():\n    griddb_dtype = map_pandas_dtype_to_griddb(str(dtype))\n    container_columns.append([column_name, griddb_dtype])\n\ncontainer_info = griddb.ContainerInfo(\"PopulationStats\",\n                                      container_columns,\n                                      griddb.ContainerType.COLLECTION, True)\n\n\ntry:\n    cont = gridstore.put_container(container_info)\n    for index, row in dataset.iterrows():\n        cont.put(row.tolist())\n    print(\"All rows have been successfully stored in the GridDB container.\")\n\nexcept griddb.GSException as e:\n    for i in range(e.get_error_stack_size()):\n        print(\"[\", i, \"]\")\n        print(e.get_error_code(i))\n        print(e.get_location(i))\n        print(e.get_message(i))<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<pre><code>All rows have been successfully stored in the GridDB container.\n<\/code><\/pre>\n<p>Now that we have created a GridDB container containing sample records, we will create a LangChain chatbot that will allow you to retrieve information from the sample data container.<\/p>\n<h2>Creating a LangChain Chatbot to Interact with GridDB Data<\/h2>\n<p>In LangChain, you can create Chatbots using a wide range of large language (LLM) models. In this article, we will create a LangChain chatbot using <a href=\"https:\/\/openai.com\/index\/hello-gpt-4o\/\">GPT-4o<\/a>, a state-of-the-art LLM from OpenAI.<\/p>\n<p>To use GPT-4o in LangChain, you need to create an object of <code>ChatOpenAI<\/code> class and pass it your <a href=\"https:\/\/platform.openai.com\/api-keys\">OpenAI API Key<\/a>.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">OPENAI_API_KEY = \"YOUR_OPENAI_API_KEY\"\nllm = ChatOpenAI(api_key = OPENAI_API_KEY ,\n                 temperature = 0,\n                model_name = \"gpt-4o\")<\/code><\/pre>\n<\/div>\n<h3>Problem with Default LangChain Chains for Creating a Chatbot for Tabular Data<\/h3>\n<p>In my previous article, I explained how to perform <a href=\"https:\/\/github.com\/usmanmalik57\/GridDB-Blogs\/blob\/main\/CRUD%20Operations%20on%20GridDB%20with%20LangChain\/article_text.md\">CRUD operations on GridDB with LangChain<\/a>.<\/p>\n<p>The approach used in that article is good for interacting with GridDB using natural language if you already know the exact names of the GridDB container and columns. Otherwise, the LLM will attempt to retrieve information using made-up column names.<\/p>\n<p>For instance, in the following section, we try to get the names of the top 3 countries with the highest population in 2020.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">class SelectData(BaseModel):\n    container_name: str = Field(description=\"the container name from the user query\")\n    query:str = Field(description=\"natural language converted to SELECT query\")\n\nsystem_command = \"\"\"\nConvert user commands into SQL queries for Griddb.\n\"\"\"\n\nuser_prompt = ChatPromptTemplate.from_messages([\n    (\"system\", system_command),\n    (\"user\", \"{input}\")\n])\n\nselect_chain = user_prompt | llm.with_structured_output(SelectData)\n\ndef select_records(query):\n\n    select_data = select_chain.invoke(query)\n    container_name = select_data.container_name\n    select_query = select_data.query\n\n    print(select_query)\n\n    result_container = gridstore.get_container(container_name)\n    query = result_container.query(select_query)\n    rs = query.fetch()\n    result_data = rs.fetch_rows()\n    return result_data\n\n\nselect_records(\"From the PopulationStats container, return the top 3 countries with the highest population in 2020\")<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2024\/09\/img3-problem-with-default-langchain-chains.png\"><img decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2024\/09\/img3-problem-with-default-langchain-chains.png\" alt=\"\" width=\"1217\" height=\"477\" class=\"aligncenter size-full wp-image-30232\" srcset=\"\/wp-content\/uploads\/2024\/09\/img3-problem-with-default-langchain-chains.png 1217w, \/wp-content\/uploads\/2024\/09\/img3-problem-with-default-langchain-chains-300x118.png 300w, \/wp-content\/uploads\/2024\/09\/img3-problem-with-default-langchain-chains-1024x401.png 1024w, \/wp-content\/uploads\/2024\/09\/img3-problem-with-default-langchain-chains-768x301.png 768w, \/wp-content\/uploads\/2024\/09\/img3-problem-with-default-langchain-chains-600x235.png 600w\" sizes=\"(max-width: 1217px) 100vw, 1217px\" \/><\/a><\/p>\n<p>From the above output, you can see that the LLM generates a query that returns information from the <code>country<\/code>, <code>population<\/code>, and <code>year<\/code> columns. However, looking at the dataset, you will find no <code>year<\/code> column. Instead, the population information for the year 2020 is stored in the <code>2020 Population<\/code> column.<\/p>\n<p>To solve this problem, you can use LangChain agents.<\/p>\n<h3>LangChain Agents for Interacting with Tabular Data<\/h3>\n<p>To use LangChain agents, we will define a <code>BaseModel<\/code> class and a <code>select_chain<\/code> that extracts the container name and the additional query information from the user query.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">class SelectData(BaseModel):\n    container_name: str = Field(description=\"the container name from the user query\")\n    natural_query:str = Field(description = \"user query string to retrieve additional information from result returned by the SELECT query\")\n\nsystem_command = \"\"\"\nConvert user commands into SQL queries for Griddb.\n\"\"\"\n\nuser_prompt = ChatPromptTemplate.from_messages([\n    (\"system\", system_command),\n    (\"user\", \"{input}\")\n])\n\nselect_chain = user_prompt | llm.with_structured_output(SelectData)\n<\/code><\/pre>\n<\/div>\n<p>Next, we will define the <code>select_records()<\/code> function that accepts a user query and calls the <code>select_chain<\/code> to retrieve the container name and the additional query. The <code>select_records()<\/code> function retrieves the container data in Pandas DataFrame.<\/p>\n<p>The next step is to create an OpenAI <code>create_pandas_dataframe_agent()<\/code> and pass to it the DataFrame containing the container data from the GridDB instance.<\/p>\n<p>The additional query is passed to the agent&#8217;s <code>invoke()<\/code> method. The agent then retrieves information from the DataFrame based on the additional user query.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">def select_records(query):\n\n    select_data = select_chain.invoke(query)\n    container_name = select_data.container_name\n    select_query = f\"SELECT * FROM {container_name}\"\n    natural_query = select_data. natural_query\n\n    print(f\"Select query: {select_query}\")\n    print(f\"Additional query: {natural_query}\")\n\n    result_container = gridstore.get_container(container_name)\n    query = result_container.query(select_query)\n    rs = query.fetch()\n    result_data = rs.fetch_rows()\n\n    agent = create_pandas_dataframe_agent(\n            ChatOpenAI(\n                api_key = OPENAI_API_KEY,\n                temperature=0,\n                model=\"gpt-4o\"),\n                result_data,\n                verbose=True,\n                agent_type=AgentType.OPENAI_FUNCTIONS,\n                allow_dangerous_code = True\n            )\n\n    response = agent.invoke(f\"Return the following information: {natural_query}\")\n    return response\n<\/code><\/pre>\n<\/div>\n<p>Let&#8217;s test the <code>select_records<\/code> method using the following query: <code>From the PopulationStats container, return the top 3 countries with the highest population in 2020<\/code>.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">select_records(\"From the PopulationStats container, return the top 3 countries with the highest population in 2020\")<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2024\/09\/img4-langchain-agents-for-interacting-with-tabular-data.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2024\/09\/img4-langchain-agents-for-interacting-with-tabular-data.png\" alt=\"\" width=\"1197\" height=\"488\" class=\"aligncenter size-full wp-image-30228\" srcset=\"\/wp-content\/uploads\/2024\/09\/img4-langchain-agents-for-interacting-with-tabular-data.png 1197w, \/wp-content\/uploads\/2024\/09\/img4-langchain-agents-for-interacting-with-tabular-data-300x122.png 300w, \/wp-content\/uploads\/2024\/09\/img4-langchain-agents-for-interacting-with-tabular-data-1024x417.png 1024w, \/wp-content\/uploads\/2024\/09\/img4-langchain-agents-for-interacting-with-tabular-data-768x313.png 768w, \/wp-content\/uploads\/2024\/09\/img4-langchain-agents-for-interacting-with-tabular-data-600x245.png 600w\" sizes=\"(max-width: 1197px) 100vw, 1197px\" \/><\/a><\/p>\n<p>The output shows that the SELECT query selects all the records from the <code>PopulationStats<\/code> container, while the additional query fetches the <code>top 3 countries with the highest population in 2020<\/code>.<\/p>\n<p>As you can see from the above output, the agent will know the column names of the <code>PopulationStats<\/code> container since it can access the corresponding <code>result_data<\/code> DataFrame and will return the required information.<\/p>\n<h3>Creating a LangChain Chatbot Interaction with GridDB Data<\/h3>\n<p>Now let&#8217;s create a chatbot capable of remembering the previous interaction.<\/p>\n<p>I recommend that instead of repeatedly defining agents in the <code>select_records<\/code> function as you did in the previous script, you just fetch the container information in a DataFrame and then use that DataFrame once in the agent.<\/p>\n<p>The following script defines <code>SelectData<\/code> base class and the <code>select_records()<\/code> function to retrieve the container name from the user query.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">class SelectData(BaseModel):\n    container_name: str = Field(description=\"the container name from the user query\")\n    query:str = Field(description=\"natural language converted to SELECT query\")\n\n\n\nsystem_command = \"\"\"\nConvert user commands into SQL queries for Griddb.\n\"\"\"\n\nuser_prompt = ChatPromptTemplate.from_messages([\n    (\"system\", system_command),\n    (\"user\", \"{input}\")\n])\n\nselect_chain = user_prompt | llm.with_structured_output(SelectData)\n\ndef select_records(query):\n\n    select_data = select_chain.invoke(query)\n    container_name = select_data.container_name\n    select_query = select_data.query\n\n    result_container = gridstore.get_container(container_name)\n    query = result_container.query(select_query)\n    rs = query.fetch()\n    result_data = rs.fetch_rows()\n    return result_data\n\n\nresult_data = select_records(\"SELECT all records from PopulationStats container\")<\/code><\/pre>\n<\/div>\n<p>Next, we define the <code>create_pandas_dataframe_agent<\/code> and the <code>get_response()<\/code> functions, which accept a user query and return information about the Pandas DataFrame using the <code>create_pandas_dataframe_agent<\/code> agent.<\/p>\n<p>To implement the chatbot functionality, we can define the <code>chat_with_agent()<\/code> function, which executes a <code>while<\/code> loop that keeps calling the <code>get_response()<\/code> function and prints the agent response on the console. The loop terminates when a user enters&#8217; bye, quit<code>, or<\/code>exit`.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">agent = create_pandas_dataframe_agent(\n    ChatOpenAI(\n        api_key=OPENAI_API_KEY,\n        temperature=0,\n        model=\"gpt-4\"\n    ),\n    result_data,\n    agent_type=AgentType.OPENAI_FUNCTIONS,\n    allow_dangerous_code=True,\n)\n\n\n\ndef get_response(natural_query):\n    # Create a conversation chain\n\n\n    # Get the response from the agent\n    response = agent.invoke(f\"Return the following information: {natural_query}\")\n\n    # Add the interaction to the conversation memory\n    return response\n\n\n# Function to chat with the agent\ndef chat_with_agent():\n    while True:\n        user_input = input(\"You: \")\n        if user_input.lower() in ['exit', 'quit', 'bye']:\n            print(\"AI: Goodbye!\")\n            break\n\n        response = get_response(user_input)\n        print(f\"AI: {response['output']}\")\n\nchat_with_agent()<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2024\/09\/img5-chatbot-for-interacting-with-griddb.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2024\/09\/img5-chatbot-for-interacting-with-griddb.png\" alt=\"\" width=\"853\" height=\"253\" class=\"aligncenter size-full wp-image-30229\" srcset=\"\/wp-content\/uploads\/2024\/09\/img5-chatbot-for-interacting-with-griddb.png 853w, \/wp-content\/uploads\/2024\/09\/img5-chatbot-for-interacting-with-griddb-300x89.png 300w, \/wp-content\/uploads\/2024\/09\/img5-chatbot-for-interacting-with-griddb-768x228.png 768w, \/wp-content\/uploads\/2024\/09\/img5-chatbot-for-interacting-with-griddb-600x178.png 600w\" sizes=\"(max-width: 853px) 100vw, 853px\" \/><\/a><\/p>\n<p>From the above output, you can see chatbot-like functionality retrieving responses about the world population dataset from the GridDB container.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, you learned how to create a LangChain chatbot to interact with GridDB data using natural language queries. We explored how to connect Python to GridDB, insert sample data into a GridDB container, and retrieve information using LangChain agents. We also demonstrated how you can create a chatbot using LangChain agents.<\/p>\n<p>GridDB is a highly scalable NoSQL database designed to handle large volumes of real-time data, making it well-suited for the Internet of Things (IoT) and big data applications. With advanced in-memory processing capabilities and efficient time series data management, GridDB can effectively manage large datasets.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article demonstrates creating an interactive LangChain chatbot to retrieve information from a GridDB database using natural language queries. We will use the Python LangChain library and the OpenAI GPT-4o LLM (Large Language Model), to convert natural language queries into GridDB queries to interact seamlessly with the database. Source code And Jupyter Notebook You can [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":30236,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[121],"tags":[],"class_list":["post-46811","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Interact with GridDB Data Using a LangChain Chatbot | GridDB: Open Source Time Series Database for IoT<\/title>\n<meta name=\"description\" content=\"This article demonstrates creating an interactive LangChain chatbot to retrieve information from a GridDB database using natural language queries. We will\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Interact with GridDB Data Using a LangChain Chatbot | GridDB: Open Source Time Series Database for IoT\" \/>\n<meta property=\"og:description\" content=\"This article demonstrates creating an interactive LangChain chatbot to retrieve information from a GridDB database using natural language queries. We will\" \/>\n<meta property=\"og:url\" content=\"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/\" \/>\n<meta property=\"og:site_name\" content=\"GridDB: Open Source Time Series Database for IoT\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/griddbcommunity\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-10T07:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-13T20:57:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/wp-content\/uploads\/2024\/09\/Gemini_Generated_Image_u8ibcju8ibcju8ib.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1536\" \/>\n\t<meta property=\"og:image:height\" content=\"1536\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"griddb-admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@GridDBCommunity\" \/>\n<meta name=\"twitter:site\" content=\"@GridDBCommunity\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"griddb-admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/\"},\"author\":{\"name\":\"griddb-admin\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233\"},\"headline\":\"Interact with GridDB Data Using a LangChain Chatbot\",\"datePublished\":\"2024-09-10T07:00:00+00:00\",\"dateModified\":\"2025-11-13T20:57:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/\"},\"wordCount\":1033,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/griddb.net\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/#primaryimage\"},\"thumbnailUrl\":\"\/wp-content\/uploads\/2024\/09\/Gemini_Generated_Image_u8ibcju8ibcju8ib.jpg\",\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/\",\"url\":\"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/\",\"name\":\"Interact with GridDB Data Using a LangChain Chatbot | GridDB: Open Source Time Series Database for IoT\",\"isPartOf\":{\"@id\":\"https:\/\/griddb.net\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/#primaryimage\"},\"thumbnailUrl\":\"\/wp-content\/uploads\/2024\/09\/Gemini_Generated_Image_u8ibcju8ibcju8ib.jpg\",\"datePublished\":\"2024-09-10T07:00:00+00:00\",\"dateModified\":\"2025-11-13T20:57:05+00:00\",\"description\":\"This article demonstrates creating an interactive LangChain chatbot to retrieve information from a GridDB database using natural language queries. We will\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/#primaryimage\",\"url\":\"\/wp-content\/uploads\/2024\/09\/Gemini_Generated_Image_u8ibcju8ibcju8ib.jpg\",\"contentUrl\":\"\/wp-content\/uploads\/2024\/09\/Gemini_Generated_Image_u8ibcju8ibcju8ib.jpg\",\"width\":1536,\"height\":1536},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/griddb.net\/en\/#website\",\"url\":\"https:\/\/griddb.net\/en\/\",\"name\":\"GridDB: Open Source Time Series Database for IoT\",\"description\":\"GridDB is an open source time-series database with the performance of NoSQL and convenience of SQL\",\"publisher\":{\"@id\":\"https:\/\/griddb.net\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/griddb.net\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/griddb.net\/en\/#organization\",\"name\":\"Fixstars\",\"url\":\"https:\/\/griddb.net\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png\",\"contentUrl\":\"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png\",\"width\":200,\"height\":83,\"caption\":\"Fixstars\"},\"image\":{\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/griddbcommunity\/\",\"https:\/\/x.com\/GridDBCommunity\",\"https:\/\/www.linkedin.com\/company\/griddb-by-toshiba\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233\",\"name\":\"griddb-admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g\",\"caption\":\"griddb-admin\"},\"url\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/author\/griddb-admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Interact with GridDB Data Using a LangChain Chatbot | GridDB: Open Source Time Series Database for IoT","description":"This article demonstrates creating an interactive LangChain chatbot to retrieve information from a GridDB database using natural language queries. We will","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/","og_locale":"en_US","og_type":"article","og_title":"Interact with GridDB Data Using a LangChain Chatbot | GridDB: Open Source Time Series Database for IoT","og_description":"This article demonstrates creating an interactive LangChain chatbot to retrieve information from a GridDB database using natural language queries. We will","og_url":"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/","og_site_name":"GridDB: Open Source Time Series Database for IoT","article_publisher":"https:\/\/www.facebook.com\/griddbcommunity\/","article_published_time":"2024-09-10T07:00:00+00:00","article_modified_time":"2025-11-13T20:57:05+00:00","og_image":[{"width":1536,"height":1536,"url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/wp-content\/uploads\/2024\/09\/Gemini_Generated_Image_u8ibcju8ibcju8ib.jpg","type":"image\/jpeg"}],"author":"griddb-admin","twitter_card":"summary_large_image","twitter_creator":"@GridDBCommunity","twitter_site":"@GridDBCommunity","twitter_misc":{"Written by":"griddb-admin","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/#article","isPartOf":{"@id":"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/"},"author":{"name":"griddb-admin","@id":"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233"},"headline":"Interact with GridDB Data Using a LangChain Chatbot","datePublished":"2024-09-10T07:00:00+00:00","dateModified":"2025-11-13T20:57:05+00:00","mainEntityOfPage":{"@id":"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/"},"wordCount":1033,"commentCount":0,"publisher":{"@id":"https:\/\/griddb.net\/en\/#organization"},"image":{"@id":"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2024\/09\/Gemini_Generated_Image_u8ibcju8ibcju8ib.jpg","articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/","url":"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/","name":"Interact with GridDB Data Using a LangChain Chatbot | GridDB: Open Source Time Series Database for IoT","isPartOf":{"@id":"https:\/\/griddb.net\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/#primaryimage"},"image":{"@id":"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2024\/09\/Gemini_Generated_Image_u8ibcju8ibcju8ib.jpg","datePublished":"2024-09-10T07:00:00+00:00","dateModified":"2025-11-13T20:57:05+00:00","description":"This article demonstrates creating an interactive LangChain chatbot to retrieve information from a GridDB database using natural language queries. We will","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb.net\/en\/blog\/interact-with-griddb-data-using-a-langchain-chatbot\/#primaryimage","url":"\/wp-content\/uploads\/2024\/09\/Gemini_Generated_Image_u8ibcju8ibcju8ib.jpg","contentUrl":"\/wp-content\/uploads\/2024\/09\/Gemini_Generated_Image_u8ibcju8ibcju8ib.jpg","width":1536,"height":1536},{"@type":"WebSite","@id":"https:\/\/griddb.net\/en\/#website","url":"https:\/\/griddb.net\/en\/","name":"GridDB: Open Source Time Series Database for IoT","description":"GridDB is an open source time-series database with the performance of NoSQL and convenience of SQL","publisher":{"@id":"https:\/\/griddb.net\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/griddb.net\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/griddb.net\/en\/#organization","name":"Fixstars","url":"https:\/\/griddb.net\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/","url":"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png","contentUrl":"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png","width":200,"height":83,"caption":"Fixstars"},"image":{"@id":"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/griddbcommunity\/","https:\/\/x.com\/GridDBCommunity","https:\/\/www.linkedin.com\/company\/griddb-by-toshiba"]},{"@type":"Person","@id":"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233","name":"griddb-admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb.net\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g","caption":"griddb-admin"},"url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/author\/griddb-admin\/"}]}},"_links":{"self":[{"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/posts\/46811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/comments?post=46811"}],"version-history":[{"count":1,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/posts\/46811\/revisions"}],"predecessor-version":[{"id":51471,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/posts\/46811\/revisions\/51471"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/media\/30236"}],"wp:attachment":[{"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/media?parent=46811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/categories?post=46811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/tags?post=46811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}