在不同模式之间切换

部署模式是项目级配置。在这两种模式之间切换不会移动或删除另一模式中的数据。您可以使用 UpdateRagEngineConfig API 在无服务器部署模式和 Spanner 部署模式之间切换。您还可以使用此 API 设置 Spanner 部署模式的层级,或取消预配 Spanner 模式以停止结算。您可以使用 GetRagEngineConfig API 读取当前部署模式信息。

切换到无服务器模式

以下代码示例演示了如何将 RagEngineConfig 切换到无服务器模式:

控制台

  1. 在 Google Cloud 控制台中,前往 RAG 引擎页面。

    前往 RAG 引擎

  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 引擎页面。

    前往 RAG 引擎

  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 以查看所选的模式和层级: