# 關聯 AI 助理與群組權限

建立資料庫並設定好資料表後，您需要將資料庫**關聯至 AI 助理**，AI 助理才能使用 Text to SQL 功能查詢資料。

## 關聯 AI 助理 <a href="#link-ai-agent" id="link-ai-agent"></a>

### 操作步驟 <a href="#steps" id="steps"></a>

1. 進入資料庫設定頁面，切換至「<mark style="color:blue;">關聯 AI 助理</mark>」頁籤
2. 頁面左側顯示可選 AI 助理，右側顯示已關聯 AI 助理
3. 從左側選取要關聯的 AI 助理，點擊箭頭按鈕移至右側
4. 完成後點擊「<mark style="color:blue;">儲存</mark>」

<figure><img src="/files/mTuMMBsTb27pikGXkgdE" alt="關聯 AI 助理"><figcaption><p>關聯 AI 助理頁籤：左側為可選助理，右側為已關聯助理</p></figcaption></figure>

{% hint style="info" %}
您可以使用搜尋欄位快速找到特定的 AI 助理。當 AI 助理數量較多時，列表會分頁顯示。
{% endhint %}

{% hint style="warning" %}
請確保 AI 助理的回答模式已切換至 **Agent 模式**，否則無法使用 Text to SQL 功能。

回答模式詳細說明請參考：[建立 AI 助理](https://github.com/Playma-Co-Ltd/maiagent-user-guide-gitbook/blob/main/zh-tw/build/setup.md)
{% endhint %}

### 多資料庫查詢 <a href="#multi-database-query" id="multi-database-query"></a>

一個 AI 助理可以關聯多個資料庫。當使用者提問時，AI 助理會根據問題內容自動判斷應該查詢哪個資料庫：

```
使用者：「上個月的銷售額是多少？」
→ AI 助理自動查詢「銷售資料庫」

使用者：「行銷部目前有幾位員工？」
→ AI 助理自動查詢「人事資料庫」
```

{% hint style="info" %}
為了讓 AI 助理能準確區分不同資料庫，建議為每個資料庫取一個清楚描述其用途的名稱，並填寫詳細的描述及欄位描述。
{% endhint %}

## 群組權限管理 <a href="#group-permission-management" id="group-permission-management"></a>

群組權限讓您控制組織中不同團隊對資料庫的存取範圍，確保每個團隊只能看到與自己相關的資料庫。

### 設定群組權限 <a href="#configure-group-permission" id="configure-group-permission"></a>

1. 進入資料庫設定頁面，切換至「<mark style="color:blue;">群組權限</mark>」頁籤
2. 使用穿梭元件，將要授權的群組從左側移至右側
3. 完成後點擊「<mark style="color:blue;">儲存</mark>」

{% hint style="info" %}
群組權限與「關聯 AI 助理」是獨立的設定。即使資料庫已關聯至某個 AI 助理，如果使用者所屬的群組沒有該資料庫的存取權限，使用者仍然無法查詢該資料庫。
{% endhint %}

### 權限層級 <a href="#permission-levels" id="permission-levels"></a>

資料庫的存取權限由以下條件共同決定：

```
使用者能否透過 AI 助理查詢資料庫？

✅ 資料庫已啟用
  └── ✅ 資料庫已關聯至該 AI 助理
       └── ✅ 使用者所屬群組擁有該資料庫的存取權限
            └── ✅ 可以查詢
```

* **資料庫擁有者**（建立者）可以存取自己建立的所有資料庫，不受群組權限限制
* **非擁有者**需要透過群組權限才能存取資料庫


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.maiagent.ai/database/link-chatbots-groups.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
