# Vertex AI

This guide will walk you through Vertex AI integration with BotDistrikt to enhance your bot's natural language understanding and generation capabilities. Before you begin the integration process, ensure the following prerequisites:

1. Ensure you have **Created an active Access Token** on **Personality -> Settings**
2. **Google Cloud Account**: You must have a Google Cloud Project account to access Vertex AI services.
3. Go to [Vertex AI](https://cloud.google.com/vertex-ai) --> **Go to console** --> ![](https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2Fh23yiBpCh8auop5TIDEq%2Fimage.png?alt=media\&token=614a33fb-aee0-4dfa-9de7-710438539fba)
4. Open your [Google Cloud Console](https://console.cloud.google.com).
5. Click **IAM and admin** under **Quick Access.**

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FEDZNQHXsxHzxY7si13hf%2FBotDistrikt57.png?alt=media&#x26;token=47a8509d-8959-4392-846d-3698245760e8" alt=""><figcaption><p>Google Console --> Quick Access --> IAM and admin</p></figcaption></figure>

5. On the left-hand side navigation panel, click **Service accounts** --> **+ CREATE SERVICE ACCOUNT**

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2F80ojz7H3aCAZ5Hi2ZOH8%2FBotDistrikt58.gif?alt=media&#x26;token=1e521e57-1525-4c7b-999e-254defd5f160" alt=""><figcaption><p>Setup a Service Account in Google Console</p></figcaption></figure>

6. Under **Roles**, add role as **Vertex AI user.**

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FWu0DikSoQ7JX78gNcb6L%2FBotDistrikt58.png?alt=media&#x26;token=188eb25d-a8df-46bc-8ddb-87e97bd3aab3" alt=""><figcaption><p>Roles --> Vertex AI user</p></figcaption></figure>

7. On the **Service accounts** dashboard, click on the three vertical dots ![](https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FBeDsaPCYlbt6jwJX02pA%2Fimage.png?alt=media\&token=4ec53847-2bd6-4e1c-848d-eb133eb3a668) under **Action** and select **Manage keys.**
8. Click **Add key --> Create new key.** Select **key type** as **JSON** and **Create.**

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FcftrKYEgcUON6pjrrQiJ%2FBotDistrikt59.gif?alt=media&#x26;token=1021db69-ff51-41dd-b3c5-b64c9e03fc2b" alt=""><figcaption><p>Create JSON key</p></figcaption></figure>

In your BotDistrikt chatbot, go to **Integrations --> Artificial Intelligence --> Vertex AI.**

Drop the recently downloaded JSON file to **Vertex AI private key JSON file** drop box. Once you successfully integrate Vertex AI to your chatbot, click **Training** and toggle **Generate Embeddings for Text Responses** ON.

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FeFajsYggtzJeJZUzJHTA%2Fimage.png?alt=media&#x26;token=b2ceb47d-d8dd-4d1d-8bd1-64de42c71a24" alt=""><figcaption><p>Toggle Generate Embeddings ON.</p></figcaption></figure>

In the **Intro** prompt, enter the following Retrieval Augmented Generation (RAG) or RetrievalQA Prompt:

```
Answer the question based on the context below. If the question cannot be answered using the information provided, answer with "I am not trained to answer that question".

Context:
{{nlp.query_responses}}

Rules:
- Answer strictly with only the Context provided above
- If no Context is provided, do not use Vertex to answer, just say "I am not trained to answer that question"
- If no Context is provided, do not make up an answer, just say "I am not trained to answer that question"
- If someone asks about who you are or what you are, you must say "I am a chatbot assistant"
```

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FXaMEWwxbxpwaxPl6Ax3G%2Fimage.png?alt=media&#x26;token=2cd3f76c-2bfb-4335-bfc9-4247d04fbb43" alt=""><figcaption><p>Retrieval Augmented Generation (RAG) or RetrievalQA Prompt to Intro Prompt</p></figcaption></figure>

To add a new website in **Sources**, navigate to **Sources -->** **Websites --> New Source Website.**

1. Enter a **Crawl Base URL** (base URL that the chatbot will crawl to find responses)

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2F7dzA6sbW9vakyFMBCRZO%2Fimage.png?alt=media&#x26;token=da7c3ee0-a288-4208-b856-f3431ead09e8" alt=""><figcaption><p>Enter a Crawl Base URL</p></figcaption></figure>

Click **Crawl.**

Or enter your website's **Sitemap**

Click **Load Sitemap.**

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FzrKV6YzrJgiBfO3eXtRG%2Fimage.png?alt=media&#x26;token=fcd99da3-3dba-41ae-ad4c-2683c18d76b8" alt=""><figcaption><p>Load Sitemap</p></figcaption></figure>

&#x20;You will see a list of the URLs available on the website. Once the webpages are loaded, click ![](https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FVtdYtgaobkb6O2byinbz%2Fimage.png?alt=media\&token=8ff4420c-ae84-49c5-a5d1-89080221829d)beside each URL to inspect responses. Click **Add** to add individual resources, or **Bulk Add** to add resources in bulk.

Once the resources are trained, check the Vertex AI embeddings.&#x20;

To check, click **Responses** on the source dashboard for the associated source.&#x20;

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2Fva0ZGCZI5WZWYDnm2bEi%2Fimage.png?alt=media&#x26;token=80f4adca-0f35-43ce-8da6-6210fccca39b" alt=""><figcaption><p>Click associated URL <strong>Responses</strong> to check Vertex AI response. </p></figcaption></figure>

Successful source setup is indicated by a tick in front of Vertex AI. &#x20;

Test your sources through the chatbot widget.&#x20;
