# Google Drive

Index and search Google Drive documents in Risotto

## Prerequisites

#### Supported Formats

The Google Drive Index supports multiple file formats in or across multiple synced folders.

| Category         | Format                      |
| ---------------- | --------------------------- |
| Google           | Google Docs, Google Sheets  |
| PDF              | .pdf files                  |
| Microsoft Office | Word (.docx), Excel (.xlsx) |
| Plain Text       | .txt                        |
| CSV              | .csv                        |
| HTML             | .html                       |
| Markdown         | .md                         |

Risotto does not index Google Slides, PowerPoint files, images, or Google Drive shortcuts. To index a file that a shortcut points to, move or copy the original file into a folder that the index covers.

A Google Sheet or an Excel file is read row by row. Risotto uses the first row as the column names, and stores each other row as `column name: value` pairs.

Risotto does not sync Google Drive changes automatically. Edits, renamed files, new files, and deleted files show in answers only after you reindex. On the **Indexes** page, click the three-dot menu of the index, then click **Reindex**. On the **Knowledge** tab of the Google Workspace page, the folder's card has **Reindex** in its **Actions** menu too.

#### What you'll need

- A Google Cloud project where you can enable the Google Drive API and create a service account
- The Google Drive files or folders you want to index, shared with the service account's email address
- The folder ID of each Google Drive folder you want to index

You do not need the Google Admin console or domain-wide delegation for this index. Risotto reads Drive as the service account, with read-only access.

## Setup

### Enable the Google Drive API

1. In the [Google Cloud console](https://console.cloud.google.com/), select the project that will own the service account. If you do not have a project, [create one](https://console.cloud.google.com/projectcreate).
2. Go to **APIs & Services > Library**.
3. Search for **Google Drive API**, open it, and click **Enable**.

### Create a service account and a JSON key

1. In the Google Cloud console, go to **IAM & Admin > Service Accounts**.
2. Click **Create service account**. Enter a name (for example, "Risotto Drive index") and click **Create and continue**. Skip the optional role steps and click **Done**. The service account does not need a project role.
3. Open the service account. Copy its email address (it ends with `.iam.gserviceaccount.com`). You need it in the next section.
4. Open the **Keys** tab. Click **Add key > Create new key**.
5. Select **JSON**, then click **Create**. Google downloads the key file. Keep it in a safe place: you cannot download it again.

For more detail, see Google's guide to [creating service account keys](https://cloud.google.com/iam/docs/keys-create-delete#iam-service-account-keys-create-console).

### Share the files with the service account

The service account can only read files that are shared with it.

1. In Google Drive, open the folder you want to index and click **Share**.
2. Enter the service account's email address.
3. Give it the **Viewer** role, then click **Send** (or **Share**).

If the folder is in a shared drive, add the service account as a member of the shared drive with at least the **Viewer** role. If your organization limits sharing outside your domain, a Google Workspace admin may need to allow it.

> **Note:** The **Viewer** role is not enough for a file whose owner turned off download,
> print, and copy for viewers and commenters. Google refuses to export these
> files to the service account. For these files, give the service account the
> **Editor** role, or let viewers and commenters download the file. See [Some
> files are not indexed](#some-files-are-not-indexed).

### Create the Google Drive index

1. In the Risotto dashboard, go to [**Settings > Integrations > Google Workspace**](https://dashboard.tryrisotto.com/settings/integrations/google).

2. Open the **Knowledge** tab and click **Add folder**. If nothing is connected yet, click **Index a folder** on the **Drive folders** row. The **Index a folder** dialog opens.

3. Enter a **Name**.

4. For **Service account key**, click **Choose a vault credential**, then **Add a vault credential**. In the **Create Vault Credential** dialog, enter a name, click **Choose File**, select the JSON key file, and click **Create Vault Credential**. Risotto stores the key in the [credential vault](https://www.tryrisotto.com/docs/dashboard/settings/credential-vault). If the key is already in the vault, select it instead.

5. Enter the **Folder ID**. The folder ID is the last part of the folder URL:

   ```
   https://drive.google.com/drive/folders/{THIS_IS_THE_FOLDER_ID}
   ```

   The hint under it reminds you to share the folder with the service account's email, with at least the Viewer role.

6. Optional: set these fields.
   - **Included file IDs**: a comma-separated list of file IDs to index.
   - **Excluded file IDs**: a comma-separated list of file IDs to skip. Set **Included file IDs** or **Excluded file IDs**, not both.
   - **Query**: a [Google Drive API query](https://developers.google.com/drive/api/guides/search-files) that limits which files Risotto indexes.
   - **Department**: limit the index to one department.
   - **Audience**: **Everyone** or **Assistant only**. See [Indexes](https://www.tryrisotto.com/docs/dashboard/knowledge/indexes).

7. Click **Index folder**. The folder's card on the **Knowledge** tab shows the progress, and so does the **Indexing Jobs** panel on **Knowledge > Indexes**.

*Product example: The Index a folder dialog on the Google Workspace integration page: a name, the service account key from the vault, the folder ID, the optional file lists and query, Department and Audience, and Index folder.*

**Create index** on [**Knowledge > Indexes**](https://www.tryrisotto.com/docs/dashboard/knowledge/indexes#create-an-index) still adds a Google Drive index with the same details, plus **Profile filters**, which only that dialog has.

## Troubleshooting

### Some files are not indexed

When Google Drive does not return a file, Risotto skips the file and indexes the other files. When the job is complete, Risotto sends an **Indexing Job Complete** warning to the [Alerts](https://www.tryrisotto.com/docs/dashboard/alerts) page and to your notifications channel in Slack, if you have one. The warning shows how many files Risotto indexed, for example `Total files indexed: 2 of 34`, and the number of files in each **Not indexed** group, with the cause and the fix.

| Cause                                | Fix                                                                                                                                                                                          |
| ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Download turned off for viewers      | The file owner turned off download, print, and copy for viewers and commenters. Give the service account the **Editor** role, or let viewers and commenters download the file. Then reindex. |
| Too large to export                  | Google Drive exports files up to 10 MB. Split the file, then reindex.                                                                                                                        |
| Google Drive did not return the file | Reindex to try again.                                                                                                                                                                        |

If Google Drive does not return any file, the job fails with the message "No files were indexed", followed by the cause and the fix.

The **Count** column on the Indexes page (for example, `34 files`) shows the files that Risotto indexed, not all the files in the folder.

If you need additional assistance with this integration, contact your Risotto CSM.

Source: https://www.tryrisotto.com/docs/integrations/knowledge/google-drive
