1. 總覽
在現今快速變遷的零售環境中,提供出色的客戶服務並打造個人化購物體驗,是首要之務。我們會逐步引導您建立知識導向的即時通訊應用程式,藉此回答客戶問題、引導產品探索,並打造切合需求的搜尋結果。這項創新解決方案結合了 AlloyDB 的資料儲存功能、內部分析引擎的內容理解功能、Gemini (大型語言模型) 的關聯性驗證功能,以及 Google 的 Agent Builder 快速啟動智慧對話式助理的功能。
挑戰:現代零售業的消費者希望能即時獲得解答,並獲得符合個人偏好的產品推薦。傳統搜尋方法通常無法提供這麼高的個人化服務。
解決方案:我們的知識導向即時通訊應用程式正面解決這個問題。AI 會利用從零售資料衍生的豐富知識庫瞭解客戶意圖、以智慧方式回應,並提供高度相關的結果。
建構項目
在本實驗室 (第 2 部分) 中,您將:
- 建構 Vertex AI Agent Builder 服務專員
- 將 AlloyDB 工具與代理程式整合
需求條件
2. 架構
資料流:讓我們進一步瞭解資料在系統中的移動歷程:
內容擷取:
零售資料 (庫存、產品說明、客戶互動) 會持續載入 AlloyDB。
數據分析引擎:
我們會使用 AlloyDB 做為數據分析引擎執行下列作業:
- 擷取內容:引擎會分析 AlloyDB 中儲存的資料,以瞭解產品、類別、客戶行為等之間的關係。
- 嵌入建立:系統會為使用者的查詢和 AlloyDB 中儲存的資訊產生嵌入項目 (文字的數學表示法)。
- Vector Search:引擎會執行相似度搜尋,將查詢嵌入項目與產品說明、評論和其他相關資料的嵌入項目進行比較。這項功能會找出 25 個最相關的「最近鄰居」。
Gemini 驗證:
這些潛在回應會傳送至 Gemini 進行評估。Gemini 會判斷這些內容是否確實相關且安全,並與使用者分享。
回覆產生:
經過驗證的回應會以 JSON 陣列的形式建構,整個引擎會封裝為從代理程式建構工具叫用的無伺服器 Cloud Run 函式。
上述步驟已在本研究室的第 1 部分 中介紹。
我們探討瞭如何建立知識導向分析引擎的技術細節,打造智慧購物助理。接下來,我們將探討如何運用 Agent Builder 的魔力,在對話式介面中實現這個引擎。請先準備好端點網址,再開始進行第 2 部分。本實驗室的下一個步驟如下:
對話式互動:
代理程式建構工具會以自然語言格式向使用者呈現回應,方便雙方進行對話。
3. 事前準備
建立專案
- 在 Google Cloud 控制台的專案選取器頁面中,選取或建立 Google Cloud 專案。
- 確認 Cloud 專案已啟用計費功能。瞭解如何檢查專案是否已啟用帳單功能。
- 您將使用 Cloud Shell,這是在 Google Cloud 中運作的指令列環境,並已預先載入 bq。按一下 Google Cloud 控制台頂端的「啟用 Cloud Shell」。
- 連線至 Cloud Shell 後,請使用下列指令來檢查是否已通過驗證,以及專案是否已設為專案 ID:
gcloud auth list
- 在 Cloud Shell 中執行下列指令,確認 gcloud 指令知道您的專案。
gcloud config list project
- 如果尚未設定專案,請使用下列指令進行設定:
gcloud config set project <YOUR_PROJECT_ID>
- 啟用必要的 API。您可以透過主控台搜尋每項產品,或使用這個連結,來代替 gcloud 指令。
如果遺漏任何 API,您隨時可以在實作期間啟用。
如要查看 gcloud 指令和使用方式,請參閱說明文件。
重要注意事項:此外,請務必完成研究室的第 1 部分,完成操作。
4. 建立代理程式
隆重推出 Agent Builder
Agent Builder 是一款功能強大的低程式碼工具,可讓我們快速有效率地建立對話型虛擬服務專員。這可以簡化設計對話流程、整合知識庫及連線至外部 API 的程序。在本範例中,我們將使用 Agent Builder,順暢連線至我們在第 1 部分建立的 Cloud Function 端點,讓購物助理能夠存取我們的零售知識庫,聰明地回應客戶查詢。
建構代理程式
我們現在就開始建立這個新服務專員,以便回答使用者有關服飾產品的問題。
- 首先,請登入Agent Builder 平台。如果系統提示您啟用 API,請按一下「繼續並啟用 API」。
- 按一下「建立應用程式」,並為代理程式命名 (例如「零售購物助理」)。
- 按一下應用程式類型「Agent」。
- ,直接在 Google Cloud 控制台實際操作。為虛擬服務專員命名,例如「零售購物助理」並將區域設為 us-central1
- 輸入代理人的詳細資料:
- 將代理程式名稱變更為「Retail Shopping Agent」。
- 新增下列「Goal」:
You are a shopping assistant agent! Your job is to help the customer search for their ideal apparels, allow them to add items to their cart, remove items from their cart, and review items in their cart. Once a user is done searching, open the search results in a user friendly html page.
- 請儲存現在的代碼,暫時將說明留白。
- 接著,依序點選導覽選單中的「工具」和「建立」。
輸入工具名稱:零售購物工具
輸入工具說明:
This tool refers to the dataset in the backend as the context information for product inventory. It takes as input the user's search text summarized by the agent and matches with the most appropriate list of items and returns as an array of items.
輸入結構定義,並以 YAML 格式開啟 OpenAPI:
這就是我們使用後端端點為代理程式提供動力的部分。複製下列 OpenAPI 規格,並將網址預留位置 (以尖括號包圍) 替換為 Cloud Functions 端點:
openapi: 3.0.0
info:
title: AlloyDB Product Matcher
description: A Cloud Function to query AlloyDB for product matches based on user search text.
version: 1.0.0
servers:
- url: <<https://us-central1-YOUR_PROJECT_ID.cloudfunctions.net/alloy-gem>>
paths:
/:
post:
summary: Find matching products based on search text.
operationId: apparelSearch
requestBody:
description: JSON object containing the search text.
required: true
content:
application/json:
schema:
type: object
properties:
search:
type: string
description: The user's search query for product matching.
responses:
'200':
description: Successful response with a JSON array of matching products.
content:
application/json:
schema:
type: array
items:
type: object
properties:
id:
type: string
description: Product ID.
category:
type: string
description: Product category.
sub_category:
type: string
description: Product sub-category.
uri:
type: string
description: Product URI or URL.
description:
type: string
description: Product description.
literature:
type: object
description: JSON object containing match information from the ML model.
properties:
MATCH:
type: string
description: Whether the product matches the search query (YES/NO).
PERCENTAGE:
type: string
description: Percentage of match.
DIFFERENCE:
type: string
description: Description of differences between the search and product.
'500':
description: Internal server error.
將其他設定保留為預設值,然後按一下「儲存」。
- 我們想要新增「工具」,因此請返回代理程式。設為代理程式的「操作說明」在操作說明預留位置中加入下方文字 (請注意,縮排對於定義流程很重要):
- Greet the user and answer their question to the best of your knowledge.
- Summarize the user's request and ask them to confirm that you understood correctly.
- Check if the request has details like gender, color, material, style and other key apparel details already.
- If not, seek clarifying details.
- If the search request is very broad, then ask the user to narrow down the request with specific details that you believe could be personal preferences.
- Once all the necessary details are met, summarize your final understanding of the request with the user.
- Use ${TOOL: Retail Shopping Tool} to help the user with their task.
- If the request has unrelated input text, gracefully convey that you don't have information on that topic.
- Do not give product availability information outside the source that is provided to you in ${TOOL: Retail Shopping Tool}.
- Do not assist with any information unless you are certain that you know the answer and it is grounded in the source of truth.
- Thank the user for their business and say goodbye.
確認工具「零售購物工具」在「可用工具」中選取專區,然後再次儲存代理程式
5. 測試服務專員
右側窗格中應會顯示「Preview Agent」部分,讓您測試代理程式。
正如下方的螢幕截圖所示,我已聯絡使用者,在即時通訊中要求穿著藍色印花的白色襯衫:
以下是 JSON 回應:
這是來自 Cloud 函式的原始 JSON 結果,該函式會處理 AlloyDB 相似度搜尋。大功告成!我們現在已與服務專員聯絡。
6. 對話流程範例
此時,您可以測試並疊代對話方塊 (對話) 代理程式的流程:
User: I'm looking for women's boots for winter.
Agent: (OpenAPI call to Cloud Function that works with AlloyDB Similarity Search)
Cloud Function: (Processes query, returns JSON array)
Agent: Based on your preferences, here are some options: [Product 1, Product 2, Product 3]. Would you like to see more details about any of these?
User: No, That is all. Bye!
Agent: Have a good day!
少量樣本提示
現在,假設您想要在對話式代理程式中,以特定圖形格式查看結果,包括圖片和連結。我們會利用「少量畫面提示」這類對話的範例來達成這個目的。
也就是說,我們想在代理程式建構工具中新增一些範例,以便提供一致的結果格式。
在「測試服務機器人」部分的其中一張先前擷圖中,我們看到服務機器人的回應是「我知道了。你在找有藍色印花的白色襯衫...」前往該回應,或在服務機器人的右側窗格中建立新的測試對話:
- 在「輸入使用者輸入內容」部分輸入以下內容:
您會看到類似下方的回應:
您也會看到 API 端點傳回的 JSON 陣列。
- 現在,按一下預覽區邊界的「探員名稱」(如下圖中以紅色勾號標示),系統會醒目顯示即時通訊預覽區段中的所有分頁。接著,按一下預覽區塊右上角的「Save Example」。介面外觀如下:
- 將對話儲存為「含圖片的回覆」或類似的顯示名稱,然後按一下「建立」。
- 接著前往上圖中以黑色勾號標示的回應分頁,然後替換「我看到。你想買黃色涼鞋。對嗎?」取代為:
I see you are looking for yellow sandals. Here are a few options for you:
<!DOCTYPE html>
<html>
<body>
<h2>Featured Sandals</h2>
<table style="overflow-x: auto; white-space: nowrap;">
<tr>
<td>
<img src="https://assets.myntassets.com/v1/images/style/properties/d27dbd8e9666b9af2d72fbfde315f76d_images.jpg" alt="Yellow sandals from Estd. 1977" width="300">
</td>
<td>
<img src="https://assets.myntassets.com/v1/images/style/properties/b7a479fe5f56457e930541a789c5df68_images.jpg" alt="Yellow sandals from Gliders" width="300">
</td>
<td>
<img src="https://assets.myntassets.com/v1/images/style/properties/b6c813734b29b89d1055fd000ea50743_images.jpg" alt="Yellow sandals from Rocia" width="300">
</td>
<td>
<img src="https://assets.myntassets.com/v1/images/style/properties/ee0e918c229e76e0e7e61712e9d2ecb3_images.jpg" alt="Yellow flip flops from Numero Uno" width="300">
</td>
<td>
<img src="https://assets.myntassets.com/v1/images/style/properties/5bdd4c9e739205e28ee134ff7849bc60_images.jpg" alt="Yellow flip flops from Numero Uno" width="300">
</td>
</tr>
</table>
</body>
</html>
- 按一下 [儲存]也就是頂部
重複執行這個程序,並使用不同的對話變化和流程,以便建立更多範例。
接著,請使用使用者輸入內容進行測試:
其他類型的回應:
就是這麼簡單!我們已成功為零售應用程式建立及測試對話式服務專員。
7. 部署和整合
當您對代理程式感到滿意時,可以使用 Agent Builder 的整合功能,輕鬆將代理程式部署到各種管道。您可以將徽章嵌入自家網站、與熱門訊息平台整合,甚至建構專屬的行動應用程式。也可以直接在我們的網路用戶端應用程式中使用 Agent Builder API,詳情請參閱這個網誌。
8. 清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取這篇文章所用資源的費用,請按照下列步驟操作:
- 前往 Google Cloud 控制台中的「管理」
- 資源頁面。
- 在專案清單中選取要刪除的專案,然後點按「刪除」。
- 在對話方塊中輸入專案 ID,然後按一下「Shut down」(關閉) 即可刪除專案。
9. 恭喜
恭喜!我們將自訂建構的分析引擎與 Agent Builder 的直覺式介面整合,打造出智慧型零售購物助理,提供個人化體驗、準確回答問題,進而提升顧客滿意度和銷售量。我們結合 AlloyDB、Vertex AI 和 Vector Search 的功能,大幅提高語境和向量搜尋的效率、效率、意義明確,以及建立人性化的搜尋體驗。