How to Build a RAG Chat App With Agent Cloud and BigQuery
Tags: webdev, opensource, programming, tutorial
Published: 2024-04-17 08:57:49

## Introduction

Interacting with your data helps you and your team to gain relevant insights and make informed decisions for your business. Retrieval-augmented generation (RAG) chat applications allow you to chat with your data.

Retrieval-augmented generation enhances the accuracy of large language models by allowing them to consult an external data source before generating an output. The output of these LLMs is based on facts gathered from the embedded data sources.

[Agent Cloud](https://www.agentcloud.dev) is an open-source generative AI platform with a built-in RAG as a Service that enables you to build and deploy LLM-powered conversation chat apps for talking with your data.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xz2qse0ark00xz5swwdt.png)

> Agent Cloud’s RAG as a Service also has a built-in data pipeline that allows you to split, chunk, and embed data from over 300 data sources, including BigQuery.

This article will guide you on how to build a RAG chat application using Agent Cloud to privately and securely talk with your Google BigQuery data.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExbWlrOWoyYm5iN2Vvd2ZraGV3emFjd3RyNzh2cjhsbWhwdGh4anVjaSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/qt73FYHjuXqAj241m8/giphy.gif">

---

## Prerequisite

This article is a comprehensive guide that takes you on a step-by-step journey, explaining each concept and configuration clearly. No prior experience in building RAG chat apps or interacting with Google BigQuery data is required to follow along.

---

## Setting-Up BigQuery

Let’s set up our BigQuery data warehouse. You may skip this section if your data is on BigQuery already.

- Create a Google Cloud Platform [account](https://accounts.google.com/InteractiveLogin/signinchooser?continue=https%3A%2F%2Fconsole.cloud.google.com%2F&followup=https%3A%2F%2Fconsole.cloud.google.com%2F&osid=1&passive=1209600&service=cloudconsole&ifkv=ARZ0qKJ5dLT16AWdxJo6Db6DnQkbTsMOUnJyOvFVepGeD4DqeEEZ9yFt0HZRBYZWSc4Hf3WVtmgKiw&theme=mn&ddm=0&flowName=GlifWebSignIn&flowEntry=ServiceLogin).
- Create a new project and navigate into the BigQuery pane.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pegggo924azjobx2hsc9.png)

Here, we gave our project the name `test-agent-cloud`.

You can give yours any name whatever you prefer.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ke6eocw49kl210ok74ey.png)

- Create dataset. Click on the kebab menu near your project name and select Create Dataset.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7mnnwvyjb8isejab437c.png)

Configure the necessary information for your dataset e.g id and location.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bdv317jadwvmuu2rykb3.png)

Here are the details of our newly created dataset.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hxy31iq3p0z9kmvlshtk.png)

- Create tables inside your dataset. To create tables, click on the kebab button and select Create table.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9h78r2100n0n4ohpqpap.png)

- Add the table data. You can create an empty table, upload data, or add data from Google Cloud Storage, Drive, Bigtable, Amazon S3, and Amazon Blob Storage. In this demo, we will upload the World Economic Indicator dataset, publicly available data on [Maven Analytics](https://mavenanalytics.io/data-playground?page=1&pageSize=5).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qgwqxrobsuy7l2epgk21.png)

Here is our dataset schema.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fy70ouoe54buvd0etvrh.png)

Here is our dataset preview.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vhhhripw4zhf3g8om27a.png)

We are done setting up our BigQuery data warehouse. Next, we will setup Agent Cloud on our local machine.

---

## Creating Your GCP Service Account Key

You must provide your GCP service account key to embed your BigQuery data into Agent Cloud. This section will show you how to create a service account. You may skip this section if you have your service account JSON already.

Follow the steps below to create and download your service account key:

- Inside GCP, navigate to **IAM & Admin** > **Service Accounts ** and select **CREATE SERVICE ACCOUNT**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ivtz3bqt8fgapk8gr507.png)

- Fill in the details for your service account.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9khsgckjjbo1hkppudr3.png)

- Assign it a Storage Admin role and click Done.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3o98w84ynbqz39m8z9hu.png)

Your new service account is now live, but no key yet.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w9ir396c63ipwgs575ji.png)

- Click on the service account email, go to the **KEYS** tab, select **ADD KEY**, and then **Create new key**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vm1cibke07ac2xgq9ge1.png)

- Select JSON as key type then click on create. Your service account JSON or key JSON will automatically download.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8dy6iu50fncx8c3jj7iz.png)


Keep it safe. You will need it later -  Agent Cloud will request it (as Credential JSON) when embedding your BigQuery data.

---

## Running Agent Cloud Locally

We need to set up Agent Cloud on our local machine to build our RAG chat app. Soon, you will have the option to use Agent Cloud’s managed [cloud platform](https://www.agentcloud.dev/join-cloud-waitlist).

Use the following steps to set up Agent Cloud on your local machine:

- Clone the [repository](https://github.com/rnadigital/agentcloud)
- Navigate into the repository clone and run [Docker Desktop](https://www.docker.com/products/docker-desktop/).
- Start Services. To start services, run the following command for Mac and Linux users. For Windows users, we recommend using [WSL](https://learn.microsoft.com/en-us/windows/wsl/install).

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

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vkedqwwrjvuqg5mnnocg.png)

If everything goes well with the installation, there will be seven containers running.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zanqosjiuov50e7nil9b.png)

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExOGhtNWxoYW1yYnp0ZTd2eGFkbG1nend3aHR3aHV0cjl6ZDkxNnF3NSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/YMgEC6u53fctZruPsc/giphy.gif">

> ❗️Heads up: Installing might take a while depending on your computer. It's a good idea to check out our docs for tips on setting up your system. You can find them [here](https://docs.agentcloud.dev/documentation/get-started/quickstart).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ly608d8r18gyngtg746l.png)


- Once all the Docker containers are running.
- Go to http://localhost:3000 to signin/signup on Agent Cloud and start building your application.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l7e9325s0bnnkqtvqy7l.png)


This is what Agent Cloud looks like after logging in.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8xdsbmfoalddtiiecnft.png)

---

## Add Your Model

Go into the **Models** page and add two models.

- the fast embed model
- an LLM

The fast embed model is a lightweight model that will run locally on your machine to split, chunk, and embed data.

For your LLM, you can use either OpenAI, Azure OpenAI, or LMStudio and add your credentials.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zydt4k27c2hazyqzusoc.png)

---

## Connect Datasource

Agent Cloud allows you to split, chunk, and embed data from over 300 sources. In this case, our data source is BigQuery. Let’s connect to BigQuery.

- Navigate to the **Data Sources** screen and click **New Connection**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8cl9syqr37ot42youzpl.png)

- Select BigQuery as your datasource

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/embywa2cwgr50iep9jv0.png)

Give your datasource a name and select the sync schedule for your data (for now, you may set it to **Manual**).

> Under the hood, Agent Cloud runs Airbyte on localhost:8000 to process your data. Other application running under the hood are Qdrant (http://localhost:6333/dashboard#/collections) and RabbitMQ (http://localhost:15672)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/is1z85o9kgwsu1ex1beh.png)


Add your BigQuery **Dataset ID** so that Airbyte won’t have to search all datasets which may take too long if you have many datasets. Enter your Google Cloud Project ID and your credentials JSON. Your credential JSON is the service account JSON you created in a previous section of this article.

> Note: Ensure to convert your credential JSON to a single line code to avoid getting an error from Agent Cloud.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7hb21rvf57tq9uaa7v7w.png)

- Select tables and fields to sync. Then select your embedding model.

---

## Create a Tool

Go into the **Tools** screen and create a new tool.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mr7v88ousjcf1rwrmd64.png)

Create a detailed description of your tool. It helps the LLM decide what tool to use.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wfq9f2ddph70gn1zoqa8.png)

---

## Create an Agent

Go into the **Agents** screen and create a new agent.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wws9raszzkmf58v575t6.png)

Give the Agent a **Role**, **Goal**, and **Backstory**. 

Also, select the LLM and tool you want to use. Select the RAG tool that we created earlier. Note that you can use multiple tools if you have multiple data sources.

You can use the following information for the role, goal, and backstory:

- **Role**: You are an AI Assistant.
- **Goal**: Have a back-and-forth conversation with the user.
- **Backstory**: You are an Agent Cloud Assistant, a helpful assistant designed to answer questions provided by a user.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yx8skfi0zk3w1bhh6mtz.png)

---

## Create a Task

Navigate into the **Tasks** screen and set up a task.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ctm8shtkrkscr9xrrsvq.png)

**Add the following description for your task description:**

> Have a back-and-forth conversation with the user.
> Be clear in your answers always.
> If you don't know the answer, say "I do not know."

---


## Create an App

Let’s create a conversation interface for chatting with your data. 

Go into the **Apps** and click on **New App**.

- Select **Conversation Chat App** as the **App Type**.
- Select the Conversation Agent you created earlier.
- Also, select the Task you created earlier.
- Select **Sequential** as the Process type.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n1q8kxi8qrqmw4lkyvm7.png)

- Save the app and run it.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ddn3d50d83fcxocad2ol.png)

- Start chatting with your data

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1owuv7k5ovscgo89ye9w.png)

Yay, we did it 😎

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExeGFmYWVpMXc4c3p0d3I5bDFlamtvazMyNmJ2OXpwajd5Z2FwczcwNiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/l0unkiodQqmA3lPO5e/giphy.gif">

---


## 🚀 Want more? Check out our video tutorial! 🎥

If you prefer a visual walkthrough, we've got you covered.

Watch the complete guide on "How to Build a RAG Chat App With Agent Cloud and BigQuery" on our YouTube channel: [Video Tutorial](https://youtu.be/POLdnrjsy9c?feature=shared)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5u0j6d3wsdrkherncl4x.png)

And 👋 hey, if you have any questions or need further assistance, don't hesitate to join our Discord community.

We're here to help and chat anytime. 

Join us [here](https://discord.gg/QFD7hcGCWn).


---

## Conclusion

This article showed a step-by-step guide for building a RAG chat app with Agent Cloud and BigQuery.

> [Agent Cloud](https://www.agentcloud.dev) is an open-source generative AI platform that enables organizations and teams to build and deploy a conversation chat app for interacting with their data. The built-in RAG as a Service has a data pipeline that allows you to embed data from over 300 sources. Agent Cloud can be useful for customer service, sales automation, streamlining data analysis, improved employee onboarding, etc.

**🔍 Want to learn more? Check out our comparison blogs! 📊**

Explore how Agent Cloud compares with other platforms:

- [Agent Cloud vs. CrewAI
](https://www.agentcloud.dev/blog/agent-cloud-vs-crewai-a-comparison)

- [Agent Cloud vs. OpenAI](https://www.agentcloud.dev/blog/agent-cloud-vs-openai)

Discover which option suits you best ✨