部署模式是專案層級的設定。在兩種模式之間切換時,系統不會移動或刪除另一種模式的資料。您可以使用 UpdateRagEngineConfig API,在無伺服器和 Spanner 部署模式之間切換。您也可以使用這個 API 設定 Spanner 部署模式的級別,或取消佈建 Spanner 模式來停止計費。您可以使用 GetRagEngineConfig API 讀取目前的部署模式資訊。
切換為無伺服器模式
下列程式碼範例示範如何將 RagEngineConfig 切換為無伺服器模式:
控制台
- 前往 Google Cloud 控制台的「RAG Engine」頁面。
- 選取 RAG Engine 執行的區域。
- 點選「切換為無伺服器模式」選項。如果您使用無伺服器模式,可能不會看到這個選項。您可以從頁面右上方的模式標籤,確認目前的模式。
REST
PROJECT_ID: Your project ID.
LOCATION: The region to process the request.
curl -X PATCH \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragEngineConfig -d "{'ragManagedDbConfig': {'serverless': {}}}"
Python
from vertexai.preview import rag
import vertexai
PROJECT_ID = YOUR_PROJECT_ID
LOCATION = YOUR_RAG_ENGINE_LOCATION
# Initialize Agent Platform API once per session
vertexai.init(project=PROJECT_ID, location=LOCATION)
rag_engine_config_name=f"projects/{PROJECT_ID}/locations/{LOCATION}/ragEngineConfig"
new_rag_engine_config = rag.RagEngineConfig(
name=rag_engine_config_name,
rag_managed_db_config=rag.RagManagedDbConfig(mode=rag.Serverless()),
)
updated_rag_engine_config = rag.rag_data.update_rag_engine_config(
rag_engine_config=new_rag_engine_config
)
print(updated_rag_engine_config)
切換為 Spanner 模式
下列程式碼範例示範如何將 RagEngineConfig 切換至 Spanner 模式。如果您先前曾使用 Spanner 模式,並已選擇級別,則切換時不必明確提供級別。如果不是,請參閱下方的程式碼範例,瞭解如何在提供級別時切換至 Spanner 模式。
控制台
- 前往 Google Cloud 控制台的「RAG Engine」頁面。
- 選取 RAG Engine 執行的區域。
- 點選「切換至 Spanner」選項,如果您使用 Spanner 模式,可能不會看到這個選項。你可以透過模式標籤確認目前模式。
REST
PROJECT_ID: Your project ID.
LOCATION: The region to process the request.
curl -X PATCH \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragEngineConfig -d "{'ragManagedDbConfig': {'spanner': {}}}"
Python
from vertexai.preview import rag
import vertexai
PROJECT_ID = YOUR_PROJECT_ID
LOCATION = YOUR_RAG_ENGINE_LOCATION
# Initialize Agent Platform API once per session
vertexai.init(project=PROJECT_ID, location=LOCATION)
rag_engine_config_name=f"projects/{PROJECT_ID}/locations/{LOCATION}/ragEngineConfig"
new_rag_engine_config = rag.RagEngineConfig(
name=rag_engine_config_name,
rag_managed_db_config=rag.RagManagedDbConfig(mode=rag.Spanner()),
)
updated_rag_engine_config = rag.rag_data.update_rag_engine_config(
rag_engine_config=new_rag_engine_config
)
print(updated_rag_engine_config)
讀取目前的 RagEngineConfig
下列程式碼範例示範如何讀取 RagEngineConfig,查看所選模式和級別:
REST
PROJECT_ID: Your project ID.
LOCATION: The region to process the request.
curl -X GET \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragEngineConfig
Python
from vertexai.preview import rag
import vertexai
PROJECT_ID = YOUR_PROJECT_ID
LOCATION = YOUR_RAG_ENGINE_LOCATION
# Initialize Agent Platform API once per session
vertexai.init(project=PROJECT_ID, location=LOCATION)
rag_engine_config = rag.rag_data.get_rag_engine_config(
name=f"projects/{PROJECT_ID}/locations/{LOCATION}/ragEngineConfig"
)
print(rag_engine_config)
更新 Spanner 模式的級別
下列程式碼範例示範如何更新 Spanner 模式的級別:
將 RagEngineConfig 更新為 Spanner 模式 Scaled 級別
下列程式碼範例示範如何將 RagEngineConfig 設為 Spanner 模式,並採用 Scaled 級別:
控制台
- 前往 Google Cloud 控制台的「RAG Engine」頁面。
- 選取 RAG Engine 執行的區域。
- 如果尚未進入 Spanner 模式,請點選「切換至 Spanner」選項。
- 按一下「設定 RAG Engine」。「Configure RAG Engine」(設定 RAG Engine) 窗格隨即顯示。
- 選取要用於執行 RAG Engine 的級別。
- 按一下「儲存」。
REST
PROJECT_ID: Your project ID.
LOCATION: The region to process the request.
curl -X PATCH \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragEngineConfig -d "{'ragManagedDbConfig': {'spanner': {'scaled': {}}}}"
Python
from vertexai.preview import rag
import vertexai
PROJECT_ID = YOUR_PROJECT_ID
LOCATION = YOUR_RAG_ENGINE_LOCATION
# Initialize Agent Platform API once per session
vertexai.init(project=PROJECT_ID, location=LOCATION)
rag_engine_config_name=f"projects/{PROJECT_ID}/locations/{LOCATION}/ragEngineConfig"
new_rag_engine_config = rag.RagEngineConfig(
name=rag_engine_config_name,
rag_managed_db_config=rag.RagManagedDbConfig(mode=rag.Spanner(tier=rag.Scaled())),
)
updated_rag_engine_config = rag.rag_data.update_rag_engine_config(
rag_engine_config=new_rag_engine_config
)
print(updated_rag_engine_config)
將 RagEngineConfig 更新為基本級別的 Spanner 模式
下列程式碼範例示範如何將 RagEngineConfig 設為 Spanner 模式,並採用基本級:
控制台
- 前往 Google Cloud 控制台的「RAG Engine」頁面。
- 選取 RAG Engine 執行的區域。
- 如果尚未進入 Spanner 模式,請點選「切換至 Spanner」選項。
- 按一下「設定 RAG Engine」。「Configure RAG Engine」(設定 RAG Engine) 窗格隨即顯示。
- 選取要執行 RAG Engine 的級別。
- 按一下「儲存」。
REST
PROJECT_ID: Your project ID.
LOCATION: The region to process the request.
curl -X PATCH \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragEngineConfig -d "{'ragManagedDbConfig': {'spanner': {'basic': {}}}}"
Python
from vertexai.preview import rag
import vertexai
PROJECT_ID = YOUR_PROJECT_ID
LOCATION = YOUR_RAG_ENGINE_LOCATION
# Initialize Agent Platform API once per session
vertexai.init(project=PROJECT_ID, location=LOCATION)
rag_engine_config_name=f"projects/{PROJECT_ID}/locations/{LOCATION}/ragEngineConfig"
new_rag_engine_config = rag.RagEngineConfig(
name=rag_engine_config_name,
rag_managed_db_config=rag.RagManagedDbConfig(mode=rag.Spanner(tier=rag.Basic())),
)
updated_rag_engine_config = rag.rag_data.update_rag_engine_config(
rag_engine_config=new_rag_engine_config
)
print(updated_rag_engine_config)
將 RagEngineConfig 更新為未佈建級別
下列程式碼範例示範如何將 RagEngineConfig 設為 Spanner 模式,並使用未佈建級別。這項操作會永久刪除 Spanner 部署模式中的所有資料,並停止產生相關費用。
控制台
- 前往 Google Cloud 控制台的「RAG Engine」頁面。
- 選取 RAG Engine 執行的區域。
- 如果尚未進入 Spanner 模式,請點選「切換至 Spanner」選項。
- 按一下「Delete RAG Engine」(刪除 RAG Engine)。即會顯示確認對話方塊。
- 輸入 delete,確認要刪除 RAG Engine 中的資料。
- 按一下「確認」。
- 按一下「儲存」。
REST
PROJECT_ID: Your project ID.
LOCATION: The region to process the request.
curl -X PATCH \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragEngineConfig -d "{'ragManagedDbConfig': {'spanner': {'unprovisioned': {}}}}"
Python
from vertexai.preview import rag
import vertexai
PROJECT_ID = YOUR_PROJECT_ID
LOCATION = YOUR_RAG_ENGINE_LOCATION
# Initialize Agent Platform API once per session
vertexai.init(project=PROJECT_ID, location=LOCATION)
rag_engine_config_name=f"projects/{PROJECT_ID}/locations/{LOCATION}/ragEngineConfig"
new_rag_engine_config = rag.RagEngineConfig(
name=rag_engine_config_name,
rag_managed_db_config=rag.RagManagedDbConfig(mode=rag.Spanner(tier=rag.Unprovisioned())),
)
updated_rag_engine_config = rag.rag_data.update_rag_engine_config(
rag_engine_config=new_rag_engine_config
)
print(updated_rag_engine_config)