RAG Engine API

Vertex AI RAG 引擎是 Vertex AI 平台的一環,可促進檢索增強生成 (RAG)。RAG 引擎可讓大型語言模型 (LLM) 存取並整合外部知識來源的資料,例如文件和資料庫。使用 RAG 後,LLM 生成的回覆會更準確且實用。

參數清單

本節列出下列項目:

參數 範例
請參閱「語料庫管理參數」。 請參閱語料庫管理範例
請參閱「檔案管理參數」。 請參閱檔案管理範例
請參閱「擷取和預測參數」。 請參閱擷取查詢範例
請參閱「專案管理參數」。 請參閱專案管理範例

語料庫管理參數

如要瞭解 RAG 語料庫,請參閱「語料庫管理」。

建立 RAG 語料庫

下表列出用於建立 RAG 語料庫的參數。

要求主體
參數

corpus_type_config

選用:不可變動。

RagCorpus.CorpusTypeConfig

用於指定語料庫類型的設定。

display_name

必填:string

RAG 語料庫的顯示名稱。

description

選填:string

RAG 語料庫的說明。

encryption_spec

選用:不可變動:string

CMEK 金鑰名稱用於加密與 RAG 語料庫相關的靜態資料。金鑰名稱僅適用於向量資料庫的 RagManaged 選項。建立語料庫時可以設定這個欄位,但無法更新或刪除。

格式:projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{key_name}

vector_db_config

選用:不可變動:RagVectorDbConfig

向量資料庫的設定。

vertex_ai_search_config.serving_config

選填:string

Vertex AI Search 的設定。

格式:projects/{project}/locations/{location}/collections/{collection}/engines/{engine}/servingConfigs/{serving_config}projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}/servingConfigs/{serving_config}

CorpusTypeConfig
參數

document_corpus

oneof RagCorpus.CorpusTypeConfig.DocumentCorpus

corpus_type_config 的預設值,代表傳統的以文件為基礎的 RAG 語料庫。

memory_corpus

oneof RagCorpus.CorpusTypeConfig.MemoryCorpus

如果設定這個類型,RAG 語料庫就是 MemoryCorpus,可做為記憶體儲存空間搭配 Gemini Live API 使用。

詳情請參閱「將 Vertex AI RAG 引擎做為記憶體儲存空間」。

memory_corpus.llm_parser

oneof RagFileParsingConfig.LlmParser

用來剖析及儲存 Gemini Live API 工作階段背景資訊的 LLM 剖析器。您可以建構記憶體以建立索引。

RagVectorDbConfig
參數

rag_managed_db

oneof vector_dbRagVectorDbConfig.RagManagedDb

如未指定向量資料庫,則預設為 rag_managed_db

rag_managed_db.knn

oneof retrieval_strategyKNN

預設值。

比較 RAG 語料庫中的所有資料點,找出最鄰近的項目。

如果您在建立 RAG 語料庫時未指定策略,系統會預設使用 KNN 擷取策略。

rag_managed_db.ann

oneof retrieval_strategyANN

tree_depth

決定樹狀結構中的層數或層級數。

如果 RAG 語料庫中有 O(10K) 個 RAG 檔案,請將這個值設為 2。
  • 如需更多圖層或層級,請將這個值設為 3。
  • 如果未指定層數或級別數,Vertex AI RAG 引擎會為這個參數指派預設值 2。

leaf_count

決定樹狀結構中的葉節點數量。

  • 建議值為 10 * sqrt(num of RAG files in your RAG corpus)
  • 如未指定,Vertex AI RAG 引擎會為這個參數指派 500 的預設值

rebuild_ann_index

  • Vertex AI RAG 引擎會重建 ANN 索引。
  • ImportRagFiles API 要求中設為 true
  • 查詢 RAG 語料庫前,必須先重建 ANN 索引。
  • 每個位置的專案只能重建一個並行索引。

weaviate

oneof vector_dbRagVectorDbConfig.Weaviate

指定 Weaviate 執行個體。

weaviate.http_endpoint

string

Weaviate 執行個體的 HTTP 端點。

設定後即無法變更值。您可以在 CreateRagCorpus API 呼叫中將其留空,並在後續的 UpdateRagCorpus API 呼叫中設定非空白值。

weaviate.collection_name

string

RAG 語料庫對應的 Weaviate 集合。

設定後即無法變更值。您可以在 CreateRagCorpus API 呼叫中將其留空,並在後續的 UpdateRagCorpus API 呼叫中設定非空白值。

pinecone

oneof vector_dbRagVectorDbConfig.Pinecone

指定 Pinecone 執行個體。

pinecone.index_name

string

這是用來建立 Pinecone 索引的名稱,該索引會與 RAG 語料庫搭配使用。

設定後即無法變更值。您可以在 CreateRagCorpus API 呼叫中將其留空,並在後續的 UpdateRagCorpus API 呼叫中設定非空白值。

vertex_feature_store

oneof vector_dbRagVectorDbConfig.VertexFeatureStore

指定 Vertex AI 特徵儲存庫執行個體。

vertex_feature_store.feature_view_resource_name

string

RAG 語料庫對應的 Vertex AI 特徵儲存庫 FeatureView

格式:projects/{project}/locations/{location}/featureOnlineStores/{feature_online_store}/featureViews/{feature_view}

設定後即無法變更值。您可以在 CreateRagCorpus API 呼叫中將其留空,並在後續的 UpdateRagCorpus API 呼叫中設定非空白值。

vertex_vector_search

oneof vector_dbRagVectorDbConfig.VertexVectorSearch

指定 Vertex Vector Search 執行個體。

vertex_vector_search.index

string

這是與 RAG 語料庫搭配使用的向量搜尋索引資源名稱。

格式:projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}

設定後即無法變更值。您可以在 CreateRagCorpus API 呼叫中將其留空,並在後續的 UpdateRagCorpus API 呼叫中設定非空白值。

vertex_vector_search.index_endpoint

string

這是與 RAG 語料庫搭配使用的 Vector Search 搜尋索引端點資源名稱。

格式:projects/{project}/locations/{location}/indexes/{index}

設定後即無法變更值。您可以在 CreateRagCorpus API 呼叫中將其留空,並在後續的 UpdateRagCorpus API 呼叫中設定非空白值。

api_auth.api_key_config.api_key_secret_version

string

這是儲存在 Secret Manager 中的密鑰完整資源名稱,內含 Weaviate 或 Pinecone API 金鑰,視您選擇的向量資料庫而定。

格式:projects/{PROJECT_NUMBER}/secrets/{SECRET_ID}/versions/{VERSION_ID}

您可以在 CreateRagCorpus API 呼叫中將其留空,並在後續的 UpdateRagCorpus API 呼叫中設定非空白值。

rag_embedding_model_config.vertex_prediction_endpoint.endpoint

選用:不可變動:string

用於 RAG 語料庫的嵌入模型。設定後即無法變更此值。如果留空,系統會使用 text-embedding-005 做為嵌入模型。

更新 RAG 語料庫

下表列出用於更新 RAG 語料庫的參數。

要求主體
參數

display_name

選填:string

RAG 語料庫的顯示名稱。

description

選填:string

RAG 語料庫的說明。

rag_vector_db.weaviate.http_endpoint

string

Weaviate 執行個體的 HTTP 端點。

如果您的 RagCorpus 是以 Weaviate 設定建立,且這個欄位先前從未設定,則可以更新 Weaviate 執行個體的 HTTP 端點。

rag_vector_db.weaviate.collection_name

string

RAG 語料庫對應的 Weaviate 集合。

如果您的 RagCorpus 是以 Weaviate 設定建立,且這個欄位先前從未設定,則可以更新 Weaviate 執行個體的集合名稱。

rag_vector_db.pinecone.index_name

string

這是用來建立 Pinecone 索引的名稱,該索引會與 RAG 語料庫搭配使用。

如果您的 RagCorpus 是以 Pinecone 設定建立,且這個欄位先前從未設定,則您可以更新 Pinecone 執行個體的索引名稱。

rag_vector_db.vertex_feature_store.feature_view_resource_name

string

RAG 語料庫對應的 Vertex AI 特徵儲存庫 FeatureView

格式:projects/{project}/locations/{location}/featureOnlineStores/{feature_online_store}/featureViews/{feature_view}

如果 RagCorpus 是以 Vertex AI Feature Store 設定建立,且這個欄位先前從未設定過,則可以更新。

rag_vector_db.vertex_vector_search.index

string

這是與 RAG 語料庫搭配使用的向量搜尋索引資源名稱。

格式:projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}

如果 RagCorpus 是以 Vector Search 設定建立,且這個欄位先前從未設定過,則可以更新。

rag_vector_db.vertex_vector_search.index_endpoint

string

這是與 RAG 語料庫搭配使用的 Vector Search 搜尋索引端點資源名稱。

格式:projects/{project}/locations/{location}/indexes/{index}

如果 RagCorpus 是以 Vector Search 設定建立,且這個欄位先前從未設定過,則可以更新。

rag_vector_db.api_auth.api_key_config.api_key_secret_version

string

儲存在 Secret Manager 中的密鑰完整資源名稱,內含 Weaviate 或 Pinecone API 金鑰,視您選擇的向量資料庫而定。

格式:projects/{PROJECT_NUMBER}/secrets/{SECRET_ID}/versions/{VERSION_ID}

列出 RAG 語料庫

下表列出用於列出 RAG 語料庫的參數。

參數

page_size

選填:int

標準清單頁面大小。

page_token

選填:string

標準清單頁面符記。通常是從前一個 [VertexRagDataService.ListRagCorpora][] 呼叫的 [ListRagCorporaResponse.next_page_token][] 取得。

取得 RAG 語料庫

下表列出用於取得 RAG 語料庫的參數。

參數

name

string

RagCorpus 資源的名稱。格式:projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}

刪除 RAG 語料庫

下表列出用於刪除 RAG 語料庫的參數。

參數

name

string

RagCorpus 資源的名稱。格式:projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}

批次建立中繼資料結構定義

下表列出用於為 RAG 語料庫批次建立中繼資料結構定義的參數。

要求主體
參數

requests

必要:CreateRagDataSchemaRequest 清單

CreateRagDataSchema 的要求訊息。

CreateRagDataSchemaRequest
參數

rag_data_schema

必填:RagDataSchema

要建立的中繼資料結構定義。

RagDataSchema
參數

key

必填:string

中繼資料結構定義的鍵。

schema_details

RagMetadataSchemaDetails

中繼資料結構定義的詳細資料。

RagMetadataSchemaDetails
參數

type

DataType

中繼資料架構的資料類型。選項:INTEGERFLOATSTRINGDATETIMEBOOLEANLIST

列出中繼資料結構定義

下表列出用於列出中繼資料結構定義的參數。

參數 說明

parent

必填:string

RagCorpus 的資源名稱。格式:projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}

批次刪除中繼資料結構定義

下表列出用於批次刪除中繼資料結構定義的參數。

參數

names

必要:string 清單

要刪除的 RagDataSchema 資源名稱。格式:projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}/ragDataSchemas/{rag_data_schema_id}

檔案管理參數

如要瞭解 RAG 檔案及其相關中繼資料,請參閱「檔案管理」。

上傳 RAG 檔案

下表列出上傳 RAG 檔案時使用的參數。

要求主體
參數

parent

string

RagCorpus 資源的名稱。格式:projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}

rag_file

必填:RagFile

要上傳的檔案。

upload_rag_file_config

必填:UploadRagFileConfig

要上傳至 RagCorpusRagFile 設定。

RagFile 說明

display_name

必填:string

RAG 檔案的顯示名稱。

description

選填:string

RAG 檔案的說明。

UploadRagFileConfig 說明

rag_file_transformation_config.rag_file_chunking_config.fixed_length_chunking.chunk_size

int32

每個區塊的權杖數量。

rag_file_transformation_config.rag_file_chunking_config.fixed_length_chunking.chunk_overlap

int32

區塊之間的重疊。

匯入 RAG 檔案

下表列出匯入 RAG 檔案時使用的參數。

參數

parent

必填:string

RagCorpus 資源的名稱。

格式:projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}

gcs_source

oneof import_sourceGcsSource

Cloud Storage 位置。

支援匯入個別檔案和整個 Cloud Storage 目錄。

gcs_source.uris

list/string

包含上傳檔案的 Cloud Storage URI。

google_drive_source

oneof import_sourceGoogleDriveSource

Google 雲端硬碟位置。

支援匯入個別檔案和 Google 雲端硬碟資料夾。

slack_source

oneof import_sourceSlackSource

上傳檔案的 Slack 頻道。

jira_source

oneof import_sourceJiraSource

上傳檔案的 Jira 查詢。

share_point_sources

oneof import_sourceSharePointSources

上傳檔案的 SharePoint 來源。

rag_file_transformation_config.rag_file_chunking_config.fixed_length_chunking.chunk_size

int32

每個區塊的權杖數量。

rag_file_transformation_config.rag_file_chunking_config.fixed_length_chunking.chunk_overlap

int32

區塊之間的重疊。

rag_file_parsing_config

選填:RagFileParsingConfig

指定 RagFiles 的剖析設定。

如果未設定這個欄位,RAG 會使用預設剖析器。

max_embedding_requests_per_min

選填:int32

這項工作每分鐘可以傳送給指定嵌入模型的查詢數量上限,模型於語料庫中指定。這個值專屬於這項工作,不會與其他匯入工作共用。請參閱專案的「配額」頁面,設定適當的值。

如未指定,系統會使用每分鐘 1,000 個查詢的預設值。

GoogleDriveSource

resource_ids.resource_id

必填:string

Google 雲端硬碟資源的 ID。

resource_ids.resource_type

必填:string

Google 雲端硬碟資源的類型。

SlackSource

channels.channels

重複:SlackSource.SlackChannels.SlackChannel

Slack 頻道資訊,包括要匯入的 ID 和時間範圍。

channels.channels.channel_id

必填:string

Slack 頻道 ID。

channels.channels.start_time

選填:google.protobuf.Timestamp

要匯入訊息的起始時間戳記。

channels.channels.end_time

選填:google.protobuf.Timestamp

要匯入訊息的結束時間戳記。

channels.api_key_config.api_key_secret_version

必填:string

儲存在 Secret Manager 中的密鑰完整資源名稱,內含可存取 Slack 管道 ID 的 Slack 管道存取權杖。
請參閱:https://api.slack.com/tutorials/tracks/getting-a-token。

格式:projects/{PROJECT_NUMBER}/secrets/{SECRET_ID}/versions/{VERSION_ID}

JiraSource

jira_queries.projects

重複:string

要完整匯入的 Jira 專案清單。

jira_queries.custom_queries

重複:string

要匯入的自訂 Jira 查詢清單。如要瞭解 JQL (Jira 查詢語言),請參閱
Jira 支援

jira_queries.email

必填:string

Jira 電子郵件地址。

jira_queries.server_uri

必填:string

Jira 伺服器 URI。

jira_queries.api_key_config.api_key_secret_version

必填:string

儲存在 Secret Manager 中的密鑰完整資源名稱,內含可存取 Slack 頻道 ID 的 Jira API 金鑰。
請參閱:https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/

格式:projects/{PROJECT_NUMBER}/secrets/{SECRET_ID}/versions/{VERSION_ID}

SharePointSources

share_point_sources.sharepoint_folder_path

folder_source當地好感度預測值達 oneofstring

要從中下載的 SharePoint 資料夾路徑。

share_point_sources.sharepoint_folder_id

folder_source當地好感度預測值達 oneofstring

要從中下載檔案的 SharePoint 資料夾 ID。

share_point_sources.drive_name

drive_source當地好感度預測值達 oneofstring

要從中下載檔案的雲端硬碟名稱。

share_point_sources.drive_id

drive_source當地好感度預測值達 oneofstring

要從中下載檔案的雲端硬碟 ID。

share_point_sources.client_id

string

在 Microsoft Azure 入口網站中註冊的應用程式 ID。
應用程式也必須設定 MS Graph 權限「Files.ReadAll」、「Sites.ReadAll」和「BrowserSiteLists.Read.All」。

share_point_sources.client_secret.api_key_secret_version

必填:string

儲存在 Secret Manager 中的密鑰完整資源名稱, 內含在 Azure 中註冊的應用程式密鑰。

格式:projects/{PROJECT_NUMBER}/secrets/{SECRET_ID}/versions/{VERSION_ID}

share_point_sources.tenant_id

string

Azure Active Directory 執行個體的專屬 ID。

share_point_sources.sharepoint_site_name

string

要從中下載的 SharePoint 網站名稱。可以是網站名稱或網站 ID。

RagFileParsingConfig

layout_parser

oneof parserRagFileParsingConfig.LayoutParser

用於 RagFile 的版面配置剖析器。

layout_parser.processor_name

string

Document AI 處理器或處理器版本的完整資源名稱。

格式:
projects/{project_id}/locations/{location}/processors/{processor_id}
projects/{project_id}/locations/{location}/processors/{processor_id}/processorVersions/{processor_version_id}

layout_parser.max_parsing_requests_per_min

string

這項工作每分鐘可傳送給 Document AI 處理器的要求數量上限。

請參閱 https://cloud.google.com/document-ai/quotas 和專案的「配額」頁面,在此設定適當的值。如未指定,系統會使用預設值 120 QPM。

llm_parser

oneof parserRagFileParsingConfig.LlmParser

用於 RagFile 的 LLM 剖析器。

llm_parser.model_name

string

LLM 模型的資源名稱。

格式:
{publisher}/models/{model}

llm_parser.max_parsing_requests_per_min

string

這項工作每分鐘可以傳送給 LLM 模型的請求數量上限。

如要為專案設定適當的值,請參閱模型配額部分和專案的「配額」頁面,以便在此設定適當的值。如未指定,系統會使用每分鐘 5000 個查詢的預設值。

取得 RAG 檔案

下表列出用於取得 RAG 檔案的參數。

參數

name

string

RagFile 資源的名稱。格式:projects/{project}/locations/{location}/ragCorpora/{rag_file_id}

刪除 RAG 檔案

下表列出用於刪除 RAG 檔案的參數。

參數

name

string

RagFile 資源的名稱。格式:projects/{project}/locations/{location}/ragCorpora/{rag_file_id}

批次建立中繼資料

下表列出用於批次建立 RAG 檔案中繼資料的參數。

要求主體
參數

requests

必要:CreateRagMetadataRequest 清單

CreateRagMetadata 的要求訊息。

CreateRagMetadataRequest
參數

rag_metadata

必填:RagMetadata

要建立的中繼資料。

rag_metadata_id

選填:string

用於中繼資料的 ID,會成為中繼資料資源名稱的最終元件。

RagMetadata
參數

user_specified_metadata

UserSpecifiedMetadata

使用者提供的中繼資料。

UserSpecifiedMetadata
參數

key

必填:string

中繼資料的鍵。這個鍵必須對應 RagDataSchema 中定義的鍵。

value

MetadataValue

中繼資料的值。

MetadataValue
參數

int_value

oneof valueint64

float_value

oneof valuefloat

str_value

oneof valuestring

datetime_value

oneof valuestring

bool_value

oneof valueboolean

list_value

oneof valueMetadataList

清單中繼資料

下表列出用於列出 RAG 檔案中繼資料的參數。

參數

parent

必填:string

RagFile 的資源名稱。格式:projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}/ragFiles/{rag_file_id}

更新中繼資料

下表列出用於更新中繼資料的參數。

參數

rag_metadata

必填:RagMetadata

RagMetadata,取代伺服器上的資源。

批次刪除中繼資料

下表列出用於批次刪除中繼資料的參數。

參數

names

必要:string 清單

要刪除的 RagMetadata 資源名稱。格式:projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}/ragFiles/{rag_file_id}/ragMetadata/{rag_metadata_id}

擷取和預測參數

本節列出擷取和預測參數。

擷取參數

下表列出 retrieveContexts API 的參數。

參數

parent

必填:string

要執行擷取的 Location 資源名稱。
使用者必須具備在專案中進行通話的權限。

格式:projects/{project}/locations/{location}

vertex_rag_store

VertexRagStore

Vertex RagStore 的資料來源。

query

必填:RagQuery

單一 RAG 擷取查詢。

VertexRagStore
VertexRagStore

rag_resources

名單:RagResource

RAG 來源的表示法。可用於指定語料庫或 RagFile。僅支援一個語料庫或來自一個語料庫的多個檔案。

rag_resources.rag_corpus

選填:string

RagCorpora 資源名稱。

格式:projects/{project}/locations/{location}/ragCorpora/{rag_corpus}

rag_resources.rag_file_ids

名單:string

RagFile 資源清單。

格式:projects/{project}/locations/{location}/ragCorpora/{rag_corpus}/ragFiles/{rag_file}

RagQuery

text

string

以文字格式表示的查詢,可取得相關內容。

rag_retrieval_config

選填:RagRetrievalConfig

查詢的擷取設定。

RagRetrievalConfig

top_k

選填:int32

要擷取的內容數量。

hybrid_search.alpha

選填:float

Alpha 值可控制稠密型和稀疏型向量搜尋結果的權重。範圍為 [0, 1],其中 0 代表僅限稀疏向量搜尋,1 代表僅限密集向量搜尋。預設值為 0.5,可平均分配稀疏和密集向量搜尋的權重。

混合型搜尋僅適用於 Weaviate。

filter.vector_distance_threshold

oneof vector_db_thresholddouble

只傳回向量距離小於閾值的上下文。

filter.metadata_filter

選填:string

在擷取期間套用的中繼資料篩選器,使用一般運算語言 (CEL)。詳情請參閱 [中繼資料搜尋](/vertex-ai/generative-ai/docs/rag-engine/use-metadata-search)。

範例:author == "Shakespeare" && page_number == 42

filter.vector_similarity_threshold

oneof vector_db_thresholddouble

只傳回向量相似度大於閾值的上下文。

ranking.rank_service.model_name

選填:string

排序服務的型號名稱。

範例:semantic-ranker-512@latest

ranking.llm_ranker.model_name

選填:string

用於排名的模型名稱。

範例:gemini-2.5-flash

非同步擷取參數

下表列出 asyncRetrieveContexts API 的參數。

參數

parent

必填:string

要擷取的位置資源名稱 RagContexts
使用者必須具備在專案中進行通話的權限。

格式:projects/{project}/locations/{location}

query

必填:RagQuery

單一 RAG 擷取查詢。

tools

選用:Tool 清單

用於擷取的工具。支援的工具包括 retrieval,其中指定了 vertex_rag_store

要求內容參數

下表列出 askContexts API 的參數。

參數

parent

必填:string

要擷取的位置資源名稱 RagContexts
使用者必須具備在專案中進行通話的權限。

格式:projects/{project}/locations/{location}

query

必填:RagQuery

單一 RAG 擷取查詢。

tools

選用:Tool 清單

用於擷取的工具。支援的工具包括 retrieval,其中指定了 vertex_rag_store

預測參數

下表列出預測參數。

GenerateContentRequest

tools.retrieval.vertex_rag_store

VertexRagStore

設定為使用由 Vertex AI RAG 儲存庫支援的資料來源。

詳情請參閱 VertexRagStore

專案管理參數

這個表格會列出專案層級的參數。

RagEngineConfig
參數
RagManagedDbConfig.serverless 將部署模式設為無伺服器模式,或切換至該模式,為 RAG Engine 資源提供擴充性高的全代管資料庫。
RagManagedDbConfig.spanner 將部署模式設為 Spanner/切換為 Spanner,並以適用於正式環境的 Spanner 執行個體為後端。
RagManagedDbConfig.spanner.scaled 這個層級提供正式環境規模的效能,以及 Spanner 模式下的自動調度資源功能。
RagManagedDbConfig.spanner.basic 這個層級提供符合成本效益的低運算資源層級,適用於 Spanner 模式。
RagManagedDbConfig.spanner.unprovisioned 這個層級會刪除 RagManagedDb 和基礎 Spanner 執行個體。

語料庫管理範例

本節提供範例,說明如何使用 API 管理 RAG 語料庫。

建立 RAG 語料庫範例

這個程式碼範例示範如何建立 RAG 語料庫。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • CORPUS_DISPLAY_NAMERagCorpus 的顯示名稱。
  • CORPUS_DESCRIPTIONRagCorpus 的說明。

HTTP 方法和網址:

POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora

JSON 要求內文:

{
  "display_name" : "CORPUS_DISPLAY_NAME",
  "description": "CORPUS_DESCRIPTION",
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora" | Select-Object -Expand Content
您應該會收到執行成功的狀態碼 (2xx)。 <0x

以下範例說明如何使用 REST API 建立 RAG 語料庫。

  PROJECT_ID: Your project ID.
  LOCATION: The region to process the request.
  CORPUS_DISPLAY_NAME: The display name of the <code>RagCorpus</code>.
    // CreateRagCorpus
    // Input: LOCATION, PROJECT_ID, CORPUS_DISPLAY_NAME
    // Output: CreateRagCorpusOperationMetadata
    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora \
    -d '{
          "display_name" : "CORPUS_DISPLAY_NAME"
      }'

更新 RAG 語料庫範例

您可以更新 RAG 語料庫,包括新的顯示名稱、說明和向量資料庫設定。不過,您無法在 RAG 語料庫中變更下列參數

  • 向量資料庫類型。舉例來說,您無法將向量資料庫從 Weaviate 變更為 Vertex AI 特徵儲存庫。
  • 如果您使用受管理資料庫選項,則無法更新向量資料庫設定。

以下範例說明如何更新 RAG 語料庫。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • CORPUS_ID:RAG 語料庫的語料庫 ID。
  • CORPUS_DISPLAY_NAMERagCorpus 的顯示名稱。
  • CORPUS_DESCRIPTIONRagCorpus 的說明。
  • INDEX_NAMEVector Search Index 的資源名稱。格式:projects/{project}/locations/{location}/indexes/{index}
  • INDEX_ENDPOINT_NAMEVector Search Index Endpoint 的資源名稱。格式:projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}

HTTP 方法和網址:

PATCH https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/CORPUS_ID

JSON 要求內文:

{
  "display_name" : "CORPUS_DISPLAY_NAME",
  "description": "CORPUS_DESCRIPTION",
  "rag_vector_db_config": {
     "vertex_vector_search": {
         "index": "INDEX_NAME",
         "index_endpoint": "INDEX_ENDPOINT_NAME",
     }
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/CORPUS_ID"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/CORPUS_ID" | Select-Object -Expand Content
您應該會收到執行成功的狀態碼 (2xx)。 <0x

列出 RAG 語料庫的範例

這段程式碼範例示範如何列出所有 RAG 語料庫。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • PAGE_SIZE:標準清單頁面大小。如要調整每頁傳回的 RagCorpora 數量,請更新 page_size 參數。
  • PAGE_TOKEN:標準清單頁面符記。通常是透過先前 VertexRagDataService.ListRagCorpora 呼叫的 ListRagCorporaResponse.next_page_token 取得。

HTTP 方法和網址:

GET https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora?page_size=PAGE_SIZE&page_token=PAGE_TOKEN

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora?page_size=PAGE_SIZE&page_token=PAGE_TOKEN"

PowerShell

執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora?page_size=PAGE_SIZE&page_token=PAGE_TOKEN" | Select-Object -Expand Content
您應該會收到執行成功的狀態碼 (`2xx`),以及指定 PROJECT_ID 下的 RagCorpora 清單。

取得 RAG 語料庫範例

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • RAG_CORPUS_IDRagCorpus 資源的 ID。

HTTP 方法和網址:

GET https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID"

PowerShell

執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID" | Select-Object -Expand Content
成功的回應會傳回 RagCorpus 資源。 <0x0A

範例會使用 getlist 指令,說明 RagCorpus 如何搭配使用 vector_db_config 中的 rag_embedding_model_config 欄位,指向您選擇的嵌入模型。

  PROJECT_ID: Your project ID.
  LOCATION: The region to process the request.
  RAG_CORPUS_ID: The corpus ID of your RAG corpus.
// GetRagCorpus
// Input: LOCATION, PROJECT_ID, RAG_CORPUS_ID
// Output: RagCorpus
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/ragCorpora/RAG_CORPUS_ID

// ListRagCorpora
curl -sS -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/ragCorpora/

刪除 RAG 語料庫範例

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • RAG_CORPUS_IDRagCorpus 資源的 ID。

HTTP 方法和網址:

DELETE https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID"

PowerShell

執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID" | Select-Object -Expand Content
成功的回應會傳回 DeleteOperationMetadata

批次建立中繼資料結構定義範例

這個程式碼範例示範如何為 RAG 語料庫批次建立中繼資料結構。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • RAG_CORPUS_IDRagCorpus 資源的 ID。
  • SCHEMA_KEY_1:第一個中繼資料結構定義的鍵。
  • SCHEMA_TYPE_1:第一個中繼資料架構的資料型別 (例如 INTEGER)。
  • SCHEMA_KEY_2:第二個中繼資料結構定義的鍵。
  • SCHEMA_TYPE_2:第二個中繼資料結構定義的資料型別 (例如 STRING)。

HTTP 方法和網址:

POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragDataSchemas:batchCreate

JSON 要求內文:

{
  "requests": [
    {
      "rag_data_schema": {
        "key": "SCHEMA_KEY_1",
        "schema_details": {"type": "SCHEMA_TYPE_1"}
      }
    },
    {
      "rag_data_schema": {
        "key": "SCHEMA_KEY_2",
        "schema_details": {"type": "SCHEMA_TYPE_2"}
      }
    }
  ]
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragDataSchemas:batchCreate"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragDataSchemas:batchCreate" | Select-Object -Expand Content
您應該會收到執行成功的狀態碼 (2xx)。 <0x

列出中繼資料結構定義範例

這個程式碼範例示範如何列出 RAG 語料庫的中繼資料結構定義。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • RAG_CORPUS_IDRagCorpus 資源的 ID。

HTTP 方法和網址:

GET https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragDataSchemas

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragDataSchemas"

PowerShell

執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragDataSchemas" | Select-Object -Expand Content
成功的回應會傳回 RagDataSchema 資源清單。

批次刪除中繼資料結構定義範例

這個程式碼範例示範如何批次刪除中繼資料結構定義。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • RAG_CORPUS_IDRagCorpus 資源的 ID。
  • SCHEMA_ID_1:要刪除的第一個中繼資料結構定義 ID。
  • SCHEMA_ID_2:要刪除的第二個中繼資料結構定義 ID。

HTTP 方法和網址:

POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragDataSchemas:batchDelete

JSON 要求內文:

{
  "names": [
    "projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragDataSchemas/SCHEMA_ID_1",
    "projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragDataSchemas/SCHEMA_ID_2"
  ]
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragDataSchemas:batchDelete"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragDataSchemas:batchDelete" | Select-Object -Expand Content
您應該會收到執行成功的狀態碼 (2xx)。 <0x

檔案管理範例

本節提供範例,說明如何使用 API 管理 RAG 檔案。

上傳 RAG 檔案範例

REST

使用任何要求資料之前,請先替換以下項目:

  PROJECT_ID: Your project ID.
  LOCATION: The region to process the request.
  RAG_CORPUS_ID: The corpus ID of your RAG corpus.
  LOCAL_FILE_PATH: The local path to the file to be uploaded.
  DISPLAY_NAME: The display name of the RAG file.
  DESCRIPTION: The description of the RAG file.

如要傳送要求,請使用下列指令:

  curl -X POST \
    -H "X-Goog-Upload-Protocol: multipart" \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -F metadata="{'rag_file': {'display_name':' DISPLAY_NAME', 'description':'DESCRIPTION'}}" \
    -F file=@LOCAL_FILE_PATH \
    "https://LOCATION-aiplatform.googleapis.com/upload/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles:upload"

匯入 RAG 檔案範例

您可以從雲端硬碟或 Cloud Storage 匯入檔案和資料夾。

response.skipped_rag_files_count 是指匯入期間略過的檔案數。符合下列條件時,系統會略過檔案:

  1. 該檔案已匯入。
  2. 檔案未變更。
  3. 檔案的分塊設定未變更。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • RAG_CORPUS_IDRagCorpus 資源的 ID。
  • GCS_URIS:Cloud Storage 位置清單。範例:gs://my-bucket1, gs://my-bucket2
  • CHUNK_SIZE:選用:每個分塊應有的權杖數量。
  • CHUNK_OVERLAP:(選填) 區塊之間重疊的權杖數量。

HTTP 方法和網址:

POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles:import

JSON 要求內文:

{
  "import_rag_files_config": {
    "gcs_source": {
      "uris": "GCS_URIS"
    },
    "rag_file_chunking_config": {
      "chunk_size": CHUNK_SIZE,
      "chunk_overlap": CHUNK_OVERLAP
    }
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles:import"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles:import" | Select-Object -Expand Content
成功的回應會傳回 ImportRagFilesOperationMetadata 資源。 <0x0A

下列範例示範如何從 Cloud Storage 匯入檔案。在 ImportRagFiles 索引程序期間,使用 max_embedding_requests_per_min 控制欄位限制 RAG 引擎呼叫嵌入模型的速度。這個欄位的預設值為每分鐘 1000 次呼叫。

  PROJECT_ID: Your project ID.
  LOCATION: The region to process the request.
  RAG_CORPUS_ID: The corpus ID of your RAG corpus.
  GCS_URIS: A list of Cloud Storage locations. Example: gs://my-bucket1.
  CHUNK_SIZE: Number of tokens each chunk should have.
  CHUNK_OVERLAP: Number of tokens overlap between chunks.
  EMBEDDING_MODEL_QPM_RATE: The QPM rate to limit RAGs access to your embedding model. Example: 1000.
// ImportRagFiles
// Import a single Cloud Storage file or all files in a Cloud Storage bucket.
// Input: LOCATION, PROJECT_ID, RAG_CORPUS_ID, GCS_URIS
// Output: ImportRagFilesOperationMetadataNumber
// Use ListRagFiles to find the server-generated rag_file_id.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles:import \
-d '{
  "import_rag_files_config": {
    "gcs_source": {
      "uris": "GCS_URIS"
    },
    "rag_file_chunking_config": {
      "chunk_size": CHUNK_SIZE,
      "chunk_overlap": CHUNK_OVERLAP
    },
    "max_embedding_requests_per_min": EMBEDDING_MODEL_QPM_RATE
  }
}'

// Poll the operation status.
// The response contains the number of files imported.
OPERATION_ID: The operation ID you get from the response of the previous command.
poll_op_wait OPERATION_ID

下列範例說明如何從雲端硬碟匯入檔案。在 ImportRagFiles 索引程序期間,使用 max_embedding_requests_per_min 控制欄位限制 RAG 引擎呼叫嵌入模型的速率。這個欄位的預設值為每分鐘 1000 次呼叫。

  PROJECT_ID: Your project ID.
  LOCATION: The region to process the request.
  RAG_CORPUS_ID: The corpus ID of your RAG corpus.
  FOLDER_RESOURCE_ID: The resource ID of your Google Drive folder.
  CHUNK_SIZE: Number of tokens each chunk should have.
  CHUNK_OVERLAP: Number of tokens overlap between chunks.
  EMBEDDING_MODEL_QPM_RATE: The QPM rate to limit RAGs access to your embedding model. Example: 1000.
// ImportRagFiles
// Import all files in a Google Drive folder.
// Input: LOCATION, PROJECT_ID, RAG_CORPUS_ID, FOLDER_RESOURCE_ID
// Output: ImportRagFilesOperationMetadataNumber
// Use ListRagFiles to find the server-generated rag_file_id.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles:import \
-d '{
  "import_rag_files_config": {
    "google_drive_source": {
      "resource_ids": {
        "resource_id": "FOLDER_RESOURCE_ID",
        "resource_type": "RESOURCE_TYPE_FOLDER"
      }
    },
    "max_embedding_requests_per_min": EMBEDDING_MODEL_QPM_RATE
  }
}'

// Poll the operation status.
// The response contains the number of files imported.
OPERATION_ID: The operation ID you get from the response of the previous command.
poll_op_wait OPERATION_ID

列出 RAG 檔案的範例

這個程式碼範例說明如何列出 RAG 檔案。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • RAG_CORPUS_IDRagCorpus 資源的 ID。
  • PAGE_SIZE:標準清單頁面大小。如要調整每頁傳回的 RagFiles 數量,請更新 page_size 參數。
  • PAGE_TOKEN:標準清單頁面符記。通常是透過先前 VertexRagDataService.ListRagFiles 呼叫的 ListRagFilesResponse.next_page_token 取得。

HTTP 方法和網址:

GET https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles?page_size=PAGE_SIZE&page_token=PAGE_TOKEN

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles?page_size=PAGE_SIZE&page_token=PAGE_TOKEN"

PowerShell

執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles?page_size=PAGE_SIZE&page_token=PAGE_TOKEN" | Select-Object -Expand Content
您應該會收到執行成功的狀態碼 (2xx),以及指定 RAG_CORPUS_ID 下的 RagFiles 清單。

取得 RAG 檔案範例

這段程式碼範例說明如何取得 RAG 檔案。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • RAG_CORPUS_IDRagCorpus 資源的 ID。
  • RAG_FILE_IDRagFile 資源的 ID。

HTTP 方法和網址:

GET https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID"

PowerShell

執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID" | Select-Object -Expand Content
成功的回應會傳回 RagFile 資源。

刪除 RAG 檔案範例

這段程式碼範例示範如何刪除 RAG 檔案。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • RAG_CORPUS_IDRagCorpus 資源的 ID。
  • RAG_FILE_IDRagFile 資源的 ID。格式:projects/{project}/locations/{location}/ragCorpora/{rag_corpus}/ragFiles/{rag_file_id}

HTTP 方法和網址:

DELETE https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID"

PowerShell

執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID" | Select-Object -Expand Content
成功的回應會傳回 DeleteOperationMetadata 資源。

批次建立中繼資料範例

這段程式碼範例說明如何為 RAG 檔案批次建立中繼資料。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • RAG_CORPUS_IDRagCorpus 資源的 ID。
  • RAG_FILE_IDRagFile 資源的 ID。
  • METADATA_KEY_1:第一個中繼資料項目的鍵。
  • VALUE_TYPE_1:第一個中繼資料項目的值類型欄位 (例如 int_value)。
  • METADATA_VALUE_1:第一個中繼資料項目的值。
  • METADATA_KEY_2:第二個中繼資料項目的鍵。
  • VALUE_TYPE_2:第二個中繼資料項目的值類型欄位 (例如 str_value)。
  • METADATA_VALUE_2:第二個中繼資料項目的值。

HTTP 方法和網址:

POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID/ragMetadata:batchCreate

JSON 要求內文:

{
  "requests": [
    {
      "rag_metadata": {
        "user_specified_metadata": {
          "key": "METADATA_KEY_1",
          "value": { "VALUE_TYPE_1": METADATA_VALUE_1 }
        }
      }
    },
    {
      "rag_metadata": {
        "user_specified_metadata": {
          "key": "METADATA_KEY_2",
          "value": { "VALUE_TYPE_2": "METADATA_VALUE_2" }
        }
      }
    }
  ]
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID/ragMetadata:batchCreate"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID/ragMetadata:batchCreate" | Select-Object -Expand Content
您應該會收到執行成功的狀態碼 (2xx)。 <0x

列出中繼資料範例

這個程式碼範例說明如何列出 RAG 檔案的中繼資料。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • RAG_CORPUS_IDRagCorpus 資源的 ID。
  • RAG_FILE_IDRagFile 資源的 ID。

HTTP 方法和網址:

GET https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID/ragMetadata

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID/ragMetadata"

PowerShell

執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID/ragMetadata" | Select-Object -Expand Content
成功的回應會傳回 RagMetadata 資源清單。

更新中繼資料範例

這段程式碼範例說明如何更新 RAG 檔案的中繼資料。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • RAG_CORPUS_IDRagCorpus 資源的 ID。
  • RAG_FILE_IDRagFile 資源的 ID。
  • METADATA_ID:要更新的中繼資料項目 ID。
  • METADATA_KEY:中繼資料項目的鍵。
  • VALUE_TYPE:值類型欄位 (例如 int_value)。
  • METADATA_VALUE:中繼資料項目的新值。

HTTP 方法和網址:

PATCH https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID/ragMetadata/METADATA_ID

JSON 要求內文:

{
  "user_specified_metadata": {
    "key": "METADATA_KEY",
    "value": { "VALUE_TYPE": METADATA_VALUE }
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID/ragMetadata/METADATA_ID"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID/ragMetadata/METADATA_ID" | Select-Object -Expand Content
您應該會收到執行成功的狀態碼 (2xx)。 <0x

批次刪除中繼資料範例

這個程式碼範例示範如何批次刪除 RAG 檔案的中繼資料項目。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • RAG_CORPUS_IDRagCorpus 資源的 ID。
  • RAG_FILE_IDRagFile 資源的 ID。
  • METADATA_ID_1:要刪除的第一個中繼資料項目 ID。
  • METADATA_ID_2:要刪除的第二個中繼資料項目 ID。

HTTP 方法和網址:

POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID/ragMetadata:batchDelete

JSON 要求內文:

{
  "names": [
    "projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID/ragMetadata/METADATA_ID_1",
    "projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID/ragMetadata/METADATA_ID_2"
  ]
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID/ragMetadata:batchDelete"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles/RAG_FILE_ID/ragMetadata:batchDelete" | Select-Object -Expand Content
您應該會收到執行成功的狀態碼 (2xx)。 <0x

擷取查詢範例

使用者提問或提供提示時,RAG 中的檢索元件會搜尋知識庫,找出與查詢相關的資訊。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • LOCATION:處理要求的區域。
  • PROJECT_ID:您的專案 ID
  • RAG_CORPUS_RESOURCERagCorpus 資源的名稱。格式:projects/{project}/locations/{location}/ragCorpora/{rag_corpus}
  • TOP_K:要擷取的重要上下文數量。
  • VECTOR_DISTANCE_THRESHOLD:只傳回向量距離小於閾值的上下文。
  • METADATA_FILTER:選用:在擷取期間套用的中繼資料篩選器。
  • TEXT:要取得相關情境的查詢文字。

HTTP 方法和網址:

POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION:retrieveContexts

JSON 要求內文:

{
  "vertex_rag_store": {
    "rag_resources": [
      {
        "rag_corpus": "RAG_CORPUS_RESOURCE"
      }
    ]
  },
  "query": {
    "text": "TEXT",
    "rag_retrieval_config": {
      "top_k": TOP_K,
      "filter": {
        "vector_distance_threshold": VECTOR_DISTANCE_THRESHOLD,
        "metadata_filter": "METADATA_FILTER"
      }
    }
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION:retrieveContexts"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION:retrieveContexts" | Select-Object -Expand Content
您應該會收到執行成功的狀態碼 (2xx) 和相關 RagFiles 清單。

生成範例

LLM 會使用檢索到的脈絡資訊,生成有依據的回覆。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的專案 ID
  • LOCATION:處理要求的區域。
  • MODEL_ID:用於生成內容的 LLM 模型。範例:gemini-2.5-flash
  • GENERATION_METHOD:用於生成內容的 LLM 方法。選項:generateContentstreamGenerateContent
  • INPUT_PROMPT:傳送至 LLM 的文字,用於生成內容。請嘗試使用與上傳的 RAG 檔案相關的提示。
  • RAG_CORPUS_RESOURCERagCorpus 資源的名稱。格式:projects/{project}/locations/{location}/ragCorpora/{rag_corpus}
  • TOP_K:(選用) 要擷取的重要上下文數量。
  • VECTOR_DISTANCE_THRESHOLD:(選填) 傳回向量距離小於閾值的上下文。
  • METADATA_FILTER:選用:在擷取期間套用的中繼資料篩選器。

HTTP 方法和網址:

POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:GENERATION_METHOD

JSON 要求內文:

{
  "contents": {
    "role": "user",
    "parts": {
      "text": "INPUT_PROMPT"
    }
  },
  "tools": {
    "retrieval": {
      "disable_attribution": false,
      "vertex_rag_store": {
        "rag_resources": [
          {
            "rag_corpus": "RAG_CORPUS_RESOURCE"
          }
        ],
        "rag_retrieval_config": {
          "top_k": TOP_K,
          "filter": {
            "vector_distance_threshold": VECTOR_DISTANCE_THRESHOLD,
            "metadata_filter": "METADATA_FILTER"
          }
        }
      }
    }
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:GENERATION_METHOD"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:GENERATION_METHOD" | Select-Object -Expand Content
成功的回應會傳回附有引文的生成內容。 <0

專案管理範例

部署模式和層級是資源 RagEngineConfig 下的專案層級設定,會影響使用 RagManagedDb 的 RAG 語料庫。如要取得目前的設定,請使用 GetRagEngineConfig。如要更新設定,請使用 UpdateRagEngineConfig

如要進一步瞭解如何管理模式和層級設定,請參閱「RAG Engine 中的部署模式」。

讀取目前的 RagEngineConfig

下列程式碼範例說明如何讀取 RagEngineConfig,查看目前選擇的模式和層級:

控制台

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

    前往 RAG Engine

  2. 選取 RAG Engine 的執行區域。RAG 語料庫清單已更新。
  3. 按一下「設定 RAG Engine」。「設定 RAG Engine」窗格隨即顯示。您可以查看為 RAG 引擎選取的層級。
  4. 按一下「取消」

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 Vertex AI 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)

切換為無伺服器模式

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

控制台

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

    前往 RAG Engine

  2. 選取 Vertex AI RAG 引擎的執行區域。
  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 Vertex AI 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. 選取 Vertex AI RAG 引擎的執行區域。
  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 Vertex AI 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 更新為 Spanner 模式的 Scaled 層級

下列程式碼範例說明如何將 RagEngineConfig 設為 Spanner 模式,並使用「已縮放」層級:

控制台

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

    前往 RAG Engine

  2. 選取 Vertex AI RAG 引擎的執行區域。
  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 Vertex AI 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. 選取 Vertex AI RAG 引擎的執行區域。
  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 Vertex AI 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. 選取 Vertex AI RAG 引擎的執行區域。
  3. 如果尚未切換至 Spanner 模式,請按一下「切換至 Spanner」按鈕。
  4. 按一下「刪除 RAG Engine」。即會顯示確認對話方塊。
  5. 輸入「delete」確認要刪除 Vertex AI RAG 引擎中的資料,然後按一下「Confirm」(確認)
  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': {'unprovisioned': {}}}}"

Python

from vertexai.preview import rag
import vertexai

PROJECT_ID = YOUR_PROJECT_ID
LOCATION = YOUR_RAG_ENGINE_LOCATION

# Initialize Vertex AI 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)

後續步驟