切換模式

部署模式是專案層級的設定。切換模式時,系統不會移動或刪除其他模式的資料。您可以使用 UpdateRagEngineConfig API 在無伺服器和 Spanner 部署模式之間切換,也可以使用這個 API 設定 Spanner 部署模式的層級,或取消佈建 Spanner 模式以停止計費。您可以使用 GetRagEngineConfig API 讀取目前的部署模式資訊。

切換為無伺服器模式

下列程式碼範例示範如何將 RagEngineConfig 切換為無伺服器模式:

控制台

  1. 前往 Google Cloud 控制台的「RAG Engine」頁面。

    前往 RAG Engine

  2. 選取 RAG Engine 的執行區域。
  3. 按一下「切換至無伺服器」選項。如果您目前處於無伺服器模式,可能不會看到這個選項。如要確認目前的模式,請查看頁面右上方的模式標籤。

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 模式。

控制台

  1. 前往 Google Cloud 控制台的「RAG Engine」頁面。

    前往 RAG Engine

  2. 選取 RAG Engine 的執行區域。
  3. 按一下「切換至 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 模式,並使用「已縮放」層級:

控制台

  1. 前往 Google Cloud 控制台的「RAG Engine」頁面。

    前往 RAG Engine

  2. 選取 RAG Engine 的執行區域。
  3. 如果尚未切換至 Spanner 模式,請點選「Switch to Spanner」(切換至 Spanner) 選項。
  4. 按一下「設定 RAG Engine」,隨即顯示「設定 RAG Engine」窗格。
  5. 選取要執行 RAG Engine 的層級。
  6. 按一下 [儲存]

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 模式,並使用 Basic 層級

下列程式碼範例說明如何將 RagEngineConfig 設為 Spanner 模式 (基本層級):

控制台

  1. 前往 Google Cloud 控制台的「RAG Engine」頁面。

    前往 RAG Engine

  2. 選取 RAG Engine 的執行區域。
  3. 如果尚未切換至 Spanner 模式,請點選「Switch to Spanner」(切換至 Spanner) 選項。
  4. 按一下「設定 RAG Engine」,隨即顯示「設定 RAG Engine」窗格。
  5. 選取要執行 RAG Engine 的層級。
  6. 按一下 [儲存]

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 部署模式中的所有資料,並停止產生相關費用。

控制台

  1. 前往 Google Cloud 控制台的「RAG Engine」頁面。

    前往 RAG Engine

  2. 選取 RAG Engine 的執行區域。
  3. 如果尚未切換至 Spanner 模式,請點選「Switch to Spanner」(切換至 Spanner) 選項。
  4. 按一下「刪除 RAG Engine」。即會顯示確認對話方塊。
  5. 輸入 delete,確認要刪除 RAG 引擎中的資料。
  6. 按一下「確認」。
  7. 按一下 [儲存]

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)