How to Build a Chat App with Your Postgres Data using Agent Cloud

tyaga001

Ankur Tyagi

Posted on May 13, 2024

How to Build a Chat App with Your Postgres Data using Agent Cloud

Introduction

Enterprises are turning to RAG (Retrieval-Augmented Generation) because it fundamentally changes how AI can be used for better decision-making.

RAG combines the power of information retrieval with AI generation, allowing businesses to:

  • Leverage vast amounts of data: RAG unlocks the value of internal and external data sources, providing a more comprehensive picture for informed choices.

  • Enhance accuracy and confidence: By grounding AI generation in reliable information, RAG reduces the risk of bias or errors in decision-making.

  • Streamline the process: RAG automates parts of the information-gathering and analysis process, leading to faster and more efficient decision-making cycles.
    RAG is a framework designed to improve language models by pulling in relevant, up-to-date data directly related to a user’s query and RAG chat apps allow you to chat with your data.

In this blog, we will learn to build a RAG chatbot in minutes using AgentCloud.

AgentCloud is an open-source platform enabling companies to build and deploy private LLM chat apps, empowering teams to securely interact with their data.

  • AgentCloud uses Airbyte to build data pipelines, which allow us to split, chunk, and embed data from over 300 data sources, including Postgres.

  • AgentCloud uses Qdrant as the vector store to efficiently store and manage large sets of vector embeddings. For a given user query the RAG application fetches relevant documents from vector store by analyzing how similar their vector representation is compared to the query vector.

So, let’s get started building a RAG chat application using Agent Cloud to talk privately and securely with your Postgres data.


Before we start building the RAG app

If you are an open Source lover and then please consider supporting Agent Cloud, by giving us a Star on GitHub ⭐️

Just click on the cat 🙏

Thanks. You're cool.


Setting up Agent Cloud via Docker

To run AgentCloud locally, ensure Docker is installed. Follow these steps to get AgentCloud up and running.

  • Clone the repo:

git clone https://github.com/rnadigital/agentcloud.git

  • Navigate to the agentcloud directory: cd agentcloud

  • Run this command:

chmod +x install.sh && ./install.sh

Running the install command will download necessary Docker images and launch the containers.

Image description

Once the install script is executed successfully we can view the containers running in the docker app:

Image description

To access Agent Cloud in the browser, we can hit the below URL: http://localhost:3000/register

Image description

Next, we need to sign to the platform

Image description

Post sign-up, and log in to the App, to get to this landing screen.

Image description

Congrats, setup is complete now.

Now let's move towards building our RAG app.


Adding New Model

Agent Cloud allows us to use models like FastEmbed and OpenAI in app.

To add a new model let’s go to the Models screen and click the Add Model option.

Image description

In the configuration screen, select a Model—such as the fast-bge-small-en for embedding text. Then, save your settings to finish the model setup.

Image description

Post successfully adding the model we will be able to view the model in the Models list.

Image description


Creating New Datasource

The data source for our app will be a Postgres table which contains information about Indian dishes.

Here is the snapshot of the table data.

Image description

Our table features 181 Indian dishes representing various Indian states.

Here is a description of the table columns.

  • name : Name of the dish
  • ingredients : Main ingredients used
  • diet : Type of diet - either vegetarian or non-vegetarian
  • prep_time : Preparation time
  • cook_time : Cooking time
  • flavor_profile : Flavor profile includes whether the dish is spicy, sweet, bitter, etc
  • course : Course of meal - starter, main course, dessert, etc
  • state : State where the dish is famous or is originated
  • region : Region where the state belongs
  • meta_info: This column contains the dish information in an unstructured format. The column data will be embedded for vector search.

To integrate table data into our app, add the data source by navigating to the Data Source page, clicking the New Connection button, and selecting a source from the modal.

Image description

Let's choose Postgres as our data source and then configure the connection.

Here's what's needed to set up the Postgres data source.

  • Schedule type
  • Host name
  • Port
  • Password
  • Postgres username
  • Postgres password
  • Database name

Image description

Let's disabled the SSL modes as we're running Postgres on our local machine.

Image description

Next, we need to select the replication method; I have selected Xmin.

Xmin replication is the new cursor-less replication method for Postgres.

Cursorless syncs enable syncing new or updated rows without explicitly choosing a cursor field. The Xmin system column is used to track inserts and updates to your source data.

Now, we need to click on the Test and Save button, which will first test the DB connection and, if successful, save the data connector.

Image description

We'll select the table and all its columns.

Image description

The column meta_info is selected for embedding, which means the vector search will be performed on the contents of this column.

Image description

Then we press the Continue button to create the Data Source.

It will take some time to embed the data, and post that you will be able to see this data in a new collection in the Qdrant collection dashboard.

After setting up the data source, Agent Cloud uses Airbyte in the background to create a data pipeline between Postgres and Qdrant.

Image description

Once the sync is complete, the new collection will appear in the Qdrant DB.

Image description

Example of how the data is stored inside a Qdrant point.

Image description

Next, we will be setting up a tool for using our data source.


Setting up Tools

Tools are essential for enabling the AI agent to interact effectively with its environment, process information, and take appropriate actions to achieve its goals.

The tools used by an AI agent can include functions, APIs, data sources, and other resources that help the agent perform specific tasks autonomously and efficiently.

The tool we will be setting up will be responsible for querying the data source and fetching relevant documents. Agent Cloud creates a tool for us when we add a new data source by default.

The screenshot below shows that the Postgres Food data tool has been automatically created by the platform.

Image description

Image description

I have updated the tool configuration to change the description.

This description is very important as it will be used by the Agent to decide which tool to use for a given task.

Image description

Click on the Save button to update the tool.


Creating Agent

An Agent is an intelligent system that can efficiently accomplish complex tasks.

To create an Agent, let’s go to the Agents screen and click on the New Agent button.

Image description

In the Agent configuration, we need to provide certain information one of the information is the LLM Model. Agents use LLMs to enhance their capabilities and improve communication.

We are using gpt-4-0125-preview OpenAI model for our agent.

Image description

Here are the remaining details needed for configuration:

  • Agent Name
  • Agent role
  • Agent Goal
  • Agent Backstory
  • Agent Tools

Image description

Now click on the Save button to complete the Agent configuration.


Creating Task

Tasks are specific assignments assigned to an agent for completion.

To create a new task let’s click the Add Task button in the Task screen.

Image description

When configuring the task, provide the following information:

  • Task name
  • Task description
  • Task tools
  • Task Agent

Image description

Post that we can click on the Save button to save the configuration.


Creating App

So till now, we have created a data source for the App, a tool to retrieve to information from the data source, an LLM Agent that will be working on complex tasks using the tool, and a Task that will be assigned to the Agent based on the user’s instruction.

Now we will be creating a conversational App that will allow us to chat with our data.

To create the App, let’s go to the App screen and click on the New App button.

Image description

In the configuration page, let’s enter the app name and select the app type, which will be a conversation chat app in our case.

Select the Task and Agent that we created. In the process, we will select sequential, and finally, in the Chat manager model, we will select the OpenAI GPT 4 model.

Now we can click on the Save button to complete the app setup.

Image description

After completing the app setup, the newly created app will appear in the dashboard.

Now let's see the app in action by clicking the Play button.

Image description

A conversion window is opened for us where we can chat with our data.

Image description

Here is the app's response to our question.

Image description

Yay, we did it 😎


Conclusion

In this blog, we learned to build a RAG chat app with Agent Cloud and Postgres.

We covered creating a data source, embedding it, and storing it in Qdrant DB. Additionally, we learned how to build tools for Agents and create an app where users can interact with their private data.

🔍 Want to learn more about Agent Cloud?

  1. Agent Cloud vs. CrewAI
  2. Agent Cloud vs. OpenAI
  3. Agent Cloud vs. Vertex AI Agents
  4. How to Build a RAG Chatbot using Agent Cloud and BigQuery
  5. How to Build a RAG Chatbot Using Agent Cloud And MongoDB
💖 💪 🙅 🚩
tyaga001
Ankur Tyagi

Posted on May 13, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related