> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentcloud.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Tutorial to Build a RAG with Google Bigquery

> Step by step guide to setup a conversational chat app to RAG a Google Big Query datasource (or any other data source)

## 1. Setup Models and Credentials

Go to the `/models` screen and add two models:

<Frame>
  <img src="https://mintcdn.com/rna/G04fBABrzw_cNbF_/images/demo-models.png?fit=max&auto=format&n=G04fBABrzw_cNbF_&q=85&s=4c506b5287fc2be30df6fe4b3f0f1803" alt="How to Setup Models in Agent Cloud" width="2640" height="1044" data-path="images/demo-models.png" />
</Frame>

<br />

<AccordionGroup>
  <Accordion icon="microchip" title="Add Embedding Model">
    Add new model of type fastembed add select the `text-embedding-3-small`
  </Accordion>

  <Accordion icon="comments" title="Add LLM Model">
    Add a new model of type Open AI and select `gpt-4o-mini`
    <Note>For best performance first time we reccommend using Open AI. If using Open AI sign up to [https://platform.openai.com/api-keys](https://platform.openai.com/api-keys) and generate an API Key. Copy and paste this into the Credenital screen within agentcloud. You can also connect to a local model via LM Studio or Ollama - if there any issues please raise on #help on Discord.</Note>
  </Accordion>
</AccordionGroup>

## 2. Setup Datasource

<Tip>
  If running locally via Docker, during this process we reccommend running `docker compose logs -f` in your terminal to follow along and catch any errors if they occur.
  For Advanced debugging you can also open up apps like Qdrant or Airbyte to see progress as data passes through each system.
  Click Advanced Debugging for instructions on how to access these UIs.
</Tip>

<AccordionGroup>
  <Accordion icon="bug" title="Advanced Debugging">
    If you want to debug the applications running under the hood, you can access them via the following addresses:

    | App       | Location                                                                                     | Authentication                       |
    | --------- | -------------------------------------------------------------------------------------------- | ------------------------------------ |
    | Airbyte   | [http://localhost:8000](http://localhost:8000)                                               | username: airbyte password: password |
    | Qdrant    | [http://localhost:6333/dashboard#/collections](http://localhost:6333/dashboard#/collections) | N/A                                  |
    | Rabbit MQ | [http://localhost:15672/](http://localhost:15672/)                                           | username: guest password: guest      |
  </Accordion>

  <Accordion icon="file-csv" title="Sample Elon Musk tweets dataset">
    You can get this dataset from [Github here](https://raw.githubusercontent.com/MartaCasdelg/Python-Projects/main/Twitter%20-Sentiment%20and%20text%20analysis%20of%20Elon%20Musk%20tweets/cleandata.csv). If you want to use Bigquery, you can upload the csv to Bigquery via their GUI.
  </Accordion>
</AccordionGroup>

Go to the `/datasources` screen, select New Connection and add a Bigquery data source:

<Frame>
  <img src="https://mintcdn.com/rna/G04fBABrzw_cNbF_/images/demo-bigquery-datasource.png?fit=max&auto=format&n=G04fBABrzw_cNbF_&q=85&s=4fe36ab2e7f318c774b974f072333bc6" alt="How to Add Datasource in Agent Cloud" width="2634" height="1214" data-path="images/demo-bigquery-datasource.png" />
</Frame>

<br />

<AccordionGroup>
  <Accordion icon="wrench" title="Provide a name and sync schedule">
    Provide a name and sync schedule for the data source. Select `Manual` for now.
    <Tip>For now, syncs configured via Agent Cloud, will sync all data from the source everytime. In airbyte terms this is called a `full refresh - overwrite`. We still need to enable other refresh options such as `Incremental - Append` or `Full Refresh - Append` in future versions, which will only sync new data via a provided cursor field (such as create date field). You can [read more about it here](https://docs.airbyte.com/using-airbyte/core-concepts/sync-modes/) </Tip>
  </Accordion>

  <Accordion icon="key" title="Provide Data Source Credentials">
    <Tip>If you have many datasets in bigquery, make sure to complete the dataset field, otherwise Airbyte will search all datasets and take too long.</Tip>
    <Warning> Make sure to copy and paste your keyfile json into a code editor and turn it into a single line before pasting it in to agent cloud. Failing to do so may result in an error.</Warning>
    Provide the GCP project ID, a dataset name and copy and paste your `keyfile.json`.
  </Accordion>

  <Accordion icon="table" title="Select Table and Fields to Sync">
    Select the table and fields to sync to Agent Cloud
    <Tip>Selecting the top level checkbox will sync all fields.</Tip>
  </Accordion>

  <Accordion icon="microchip" title="Select field to Embed">
    Select the Field you would like to embed and the model you want to embed with. You can use the `text-embedding-3-small` which we setup in step 1 or add it here if you haven't done so already.
  </Accordion>

  <Accordion icon="rotate" title="Sync will begin">
    The sync will begin, you should see the process in your logs. You can open up Airbyte and Qdrant to see if the data has been synced and the collection has been created. (refer to Advanced Troubleshooting tab above)
  </Accordion>
</AccordionGroup>

## 3. Setup an Agent

Go to the `/agents` screen and create a new Agent

<Frame>
  <img src="https://mintcdn.com/rna/G04fBABrzw_cNbF_/images/demo-agent.png?fit=max&auto=format&n=G04fBABrzw_cNbF_&q=85&s=9ab54dd1058286544780e37315e80ebd" alt="How to Setup an Agent in Agent Cloud" width="2630" height="1454" data-path="images/demo-agent.png" />
</Frame>

<br />

<AccordionGroup>
  <Accordion icon="flag" title="Provide a Role, Goal and Backstory">
    You can copy and paste the following prompts

    <Tabs>
      <Tab title="👤️ Role">
        ```
        You are an AI Assistant.
        ```
      </Tab>

      <Tab title="🎯️ Goal">
        ```
        Have a back and forth conversation with the User.
        ```
      </Tab>

      <Tab title="📖 Backstory">
        ```
        You are Agent Cloud Assistant, a useful assistant designed to answer questions provided by the user.
        ```
      </Tab>
    </Tabs>
  </Accordion>

  <Accordion icon="comments" title="Select the model">
    Provide the LLM model that was created in step 1 `gpt-4o-mini` and optionally add it as the Function Calling model.
  </Accordion>

  <Accordion icon="wrench" title="Select the datasource">
    Select the RAG tool that you created earlier. You can provide multiple tools if you have multiple data sources.
  </Accordion>
</AccordionGroup>

## 4. Create a Chat App

Go to the `/apps` screen and create a new Chat App

<AccordionGroup>
  <Accordion icon="people-arrows" title="Select Conversational App Type">
    Use the conversational App type.
    <Note>By default this adds a human input tool to the agent which will enable the chat experience to require input on every question.</Note>
  </Accordion>

  <Accordion icon="robot" title="Select the Agent">
    Select the Conversational Agent you just created.
  </Accordion>

  <Accordion icon="play" title="Run the App">
    Save the App and Run it. Ask a question based on the dataset.
  </Accordion>
</AccordionGroup>

## 5. Have a chat!

<Frame>
  <img src="https://mintcdn.com/rna/G04fBABrzw_cNbF_/images/demo-chat.png?fit=max&auto=format&n=G04fBABrzw_cNbF_&q=85&s=a2a0722c4c52fbe79ff8303fb723117d" alt="Chat Interface at Agent Cloud" width="2638" height="1548" data-path="images/demo-chat.png" />
</Frame>

<br />

<Tip>
  If you want to make sure the agent always uses the tool, you can update the agent prompt and tell it, ALWAYS use the .... tool.
  Otherwise if you want to build an agent with a bit more autonomy to decide on multiple tools, you can keep the config light and let it infer which tool is required.
  For example in the video we prompted the tool by writing *According to Elon...* which helped guide the LLM to the correct tool.
</Tip>
