在不同模式之间切换

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

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)