在不同模式之间切换

部署模式属于项目级配置。在两种模式之间切换不会移动或删除另一种模式中的数据。您可以使用 UpdateRagEngineConfig API 在 Serverless 和 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,以查看所选的模式和层级:

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 模式扩缩层级

以下代码示例演示了如何将 RagEngineConfig 设置为扩缩层级的 Spanner 模式:

控制台

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

    前往 RAG 引擎

  2. 选择要在其中运行 RAG Engine 的区域。
  3. 如果尚未处于 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 模式

以下代码示例演示了如何将 RagEngineConfig 设置为基本层级的 Spanner 模式:

控制台

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

    前往 RAG 引擎

  2. 选择要在其中运行 RAG Engine 的区域。
  3. 如果尚未处于 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 引擎页面。

    前往 RAG 引擎

  2. 选择要在其中运行 RAG Engine 的区域。
  3. 如果尚未处于 Spanner 模式,请点击切换到 Spanner 选项。
  4. 点击删除 RAG Engine。此时会显示一个确认对话框。
  5. 输入“delete”,确认您即将删除 RAG Engine 中的数据。
  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)