Vertex AI RAG 引擎是 Vertex AI 平台的元件,可協助執行檢索增強生成 (RAG) 作業。RAG Engine 可讓大型語言模型 (LLM) 存取及整合來自外部知識來源的資料,例如文件和資料庫。透過 RAG,LLM 就能生成更準確且實用的回覆。
參數清單
本節列出以下內容:
參數 | 範例 |
---|---|
請參閱「語料庫管理參數」。 | 請參閱語料庫管理範例。 |
請參閱檔案管理參數。 | 請參閱檔案管理範例。 |
字庫管理參數
如要瞭解 RAG 語料庫的相關資訊,請參閱「語料庫管理」。
建立 RAG 語料庫
這個表格列出用來建立 RAG 語料庫的參數。
要求主體
參數 | |
---|---|
|
必要項目: RAG 語料庫的顯示名稱。 |
|
選用: RAG 語料庫的說明。 |
|
選用:不可變更: 向量資料庫的設定。 |
|
選用: Vertex AI Search 的設定。 格式: |
RagVectorDbConfig
參數 | |
---|---|
|
如未指定向量資料庫,預設值為 |
|
指定 Weaviate 執行個體。 |
|
Weaviate 執行個體的 HTTP 端點。 設定後即無法變更此值。您可以在 |
|
RAG 語料庫對應的 Weaviate 集合。 設定後即無法變更此值。您可以在 |
|
指定 Pinecone 例項。 |
|
這是用來建立與 RAG 語料庫搭配使用的 Pinecone 索引的名稱。 設定後即無法變更此值。您可以在 |
|
指定 Vertex AI 特徵儲存庫執行個體。 |
|
RAG 叢集對應的 Vertex AI 特徵儲存庫 格式: 設定後即無法變更此值。您可以在 |
|
指定 Vertex Vector Search 執行個體。 |
|
這是 RAG 語料庫所使用的向量搜尋索引資源名稱。 格式: 設定後即無法變更此值。您可以在 |
|
這是與 RAG 語料庫搭配使用的 Vector Search 索引端點資源名稱。 格式: 設定後即無法變更此值。您可以在 |
|
這是儲存在 Secret Manager 中的密鑰完整資源名稱,其中包含 Weaviate 或 Pinecone API 金鑰,取決於您選擇的向量資料庫。 格式: 您可以在 |
|
選用:不可變更: 要用於 RAG 語料庫的嵌入模型。設定後即無法變更此值。如果您將其留空,我們會使用 text-embedding-004 做為嵌入模型。 |
更新 RAG 語料庫
這個表格列出用於更新 RAG 語料庫的參數。
要求主體
參數 | |
---|---|
|
選用: RAG 語料庫的顯示名稱。 |
|
選用: RAG 語料庫的說明。 |
|
Weaviate 執行個體的 HTTP 端點。 如果您的 |
|
RAG 語料庫對應的 Weaviate 集合。 如果您的 |
|
這是用來建立 Pinecone 索引的名稱,用於與 RAG 語料庫搭配使用。 如果您的 |
|
RAG 叢集對應的 Vertex AI 特徵儲存庫 格式: 如果您的 |
|
這是 RAG 語料庫所使用的向量搜尋索引資源名稱。 格式: 如果您的 |
|
這是與 RAG 語料庫搭配使用的 Vector Search 索引端點資源名稱。 格式: 如果您的 |
|
儲存在 Secret Manager 中的密鑰完整資源名稱 (包含 Weaviate 或 Pinecone API 金鑰) 取決於您選擇的向量資料庫。 格式: |
列出 RAG 語料庫
這個表格列出用於列出 RAG 語料庫的參數。
參數 | |
---|---|
|
選用: 標準清單頁面大小。 |
|
選用: 標準清單頁面憑證。通常是從上一個 |
取得 RAG 語料庫
這個表格列出用於取得 RAG 語料庫的參數。
參數 | |
---|---|
|
|
刪除 RAG 語料庫
這個表格列出用來刪除 RAG 語料庫的參數。
參數 | |
---|---|
|
|
檔案管理參數
如要瞭解 RAG 檔案,請參閱檔案管理。
上傳 RAG 檔案
這個表格列出用於上傳 RAG 檔案的參數。
要求主體
參數 | |
---|---|
|
|
|
必要項目: 要上傳的檔案。 |
|
必要項目: 要上傳至 |
RagFile |
|
---|---|
|
必要項目: RAG 檔案的顯示名稱。 |
|
選用: RAG 檔案的說明。 |
UploadRagFileConfig |
|
---|---|
|
每個區塊的符記數量。 |
|
區塊之間的重疊。 |
匯入 RAG 檔案
這個表格列出用於匯入 RAG 檔案的參數。
參數 | |
---|---|
|
必要項目:
格式: |
|
Cloud Storage 位置。 支援匯入個別檔案和整個 Cloud Storage 目錄。 |
|
包含上傳檔案的 Cloud Storage URI。 |
|
Google 雲端硬碟位置。 支援匯入個別檔案和 Google 雲端硬碟資料夾。 |
|
檔案上傳的 Slack 頻道。 |
|
上傳檔案的 Jira 查詢。 |
|
上傳檔案的 SharePoint 來源。 |
|
每個區塊的符記數。 |
|
區塊之間的重疊。 |
|
選用: 指定 如果未設定這個欄位,RAG 會使用預設的剖析器。 |
|
選用: 此工作允許對詞彙庫中指定的嵌入模型進行的查詢數上限 (每分鐘)。這個值僅適用於這項工作,不會與其他匯入工作共用。請參閱專案的「配額」頁面,設定適當的值。 如未指定,系統會使用預設值 1,000 QPM。 |
GoogleDriveSource |
|
---|---|
|
必要項目: Google 雲端硬碟資源的 ID。 |
|
必要項目: Google 雲端硬碟資源的類型。 |
SlackSource |
|
---|---|
|
重複: Slack 頻道資訊,包括 ID 和匯入時間範圍。 |
|
必要項目: Slack 管道 ID。 |
|
選用: 要匯入訊息的起始時間戳記。 |
|
選用: 匯入訊息的結束時間戳記。 |
|
必要項目: 儲存在 Secret Manager 中的密鑰完整資源名稱,其中包含可存取 Slack 管道 ID 的 Slack 管道存取權杖。 格式: |
JiraSource |
|
---|---|
|
重複: 要完整匯入的 Jira 專案清單。 |
|
重複: 要匯入的自訂 Jira 查詢清單。如需有關 JQL (Jira 查詢語言) 的資訊,請參閱 |
|
必要項目: Jira 電子郵件地址。 |
|
必要項目: Jira 伺服器 URI。 |
|
必要項目: 儲存在 Secret Manager 中的密鑰完整資源名稱,其中包含可存取 Slack 頻道 ID 的 Jira API 金鑰。 格式: |
SharePointSources |
|
---|---|
|
要下載的 SharePoint 資料夾路徑。 |
|
要下載的 SharePoint 資料夾 ID。 |
|
要下載的雲端硬碟名稱。 |
|
要下載的雲端硬碟 ID。 |
|
在 Microsoft Azure 入口網站註冊的應用程式應用程式 ID。 |
|
必要項目: 儲存在 Secret Manager 中的密鑰完整資源名稱,其中包含在 Azure 註冊的應用程式所用的應用程式密鑰。 格式: |
|
Azure Active Directory 執行個體的專屬 ID。 |
|
要下載的 SharePoint 網站名稱。可以是網站名稱或網站 ID。 |
RagFileParsingConfig |
|
---|---|
|
用於 |
|
Document AI 處理器或處理器版本的完整資源名稱。 格式:
|
|
工作每分鐘可向 Document AI 處理器提出的要求數量上限。 請參閱 https://cloud.google.com/document-ai/quotas 和專案的「配額」頁面,在此設定適當的值。如未指定,系統會使用預設值 120 QPM。 |
取得 RAG 檔案
這個表格列出用於取得 RAG 檔案的參數。
參數 | |
---|---|
|
|
刪除 RAG 檔案
這個表格列出用來刪除 RAG 檔案的參數。
參數 | |
---|---|
|
|
擷取和預測
本節會列出擷取和預測參數。
擷取參數
本表列出 retrieveContexts
API 的參數。
參數 | |
---|---|
|
必要項目: 要擷取 格式: |
|
Vertex RagStore 的資料來源。 |
|
必要項目: 單一 RAG 擷取查詢。 |
VertexRagStore
VertexRagStore |
|
---|---|
|
清單: RAG 來源的表示法。可用來指定僅包含語料庫或 |
|
選用:
格式: |
|
名單:
格式: |
RagQuery |
|
---|---|
|
以文字格式提供查詢,以便取得相關的上下文。 |
|
選用: 查詢的擷取設定。 |
RagRetrievalConfig |
|
---|---|
|
選用: 要擷取的上下文數量。 |
|
選用: Alpha 值可控制稠密型和稀疏型向量搜尋結果之間的權重。範圍為 [0, 1],其中 0 表示只搜尋稀疏向量,1 則表示只搜尋密集向量。預設值為 0.5,可平衡稀疏和稠密向量搜尋。 混合搜尋功能僅適用於 Weaviate。 |
|
只傳回向量距離小於閾值的上下文。 |
|
只傳回向量相似度大於閾值的上下文。 |
|
選用: 排名服務的模型名稱。 範例: |
|
選用: 用於排名的模型名稱。 範例: |
預測參數
下表列出預測參數。
GenerateContentRequest |
|
---|---|
|
設定為使用由 Vertex AI RAG 儲存庫提供的資料來源。 |
詳情請參閱 VertexRagStore。
語料庫管理範例
本節將舉例說明如何使用 API 管理 RAG 語料庫。
建立 RAG 語料庫範例
以下程式碼範例說明如何建立 RAG 語料庫。
REST
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:您的專案 ID。
- LOCATION:處理要求的區域。
- CORPUS_DISPLAY_NAME:
RagCorpus
的顯示名稱。 - CORPUS_DESCRIPTION:
RagCorpus
的說明。
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
以下範例說明如何使用 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_NAME:
RagCorpus
的顯示名稱。 - CORPUS_DESCRIPTION:
RagCorpus
的說明。 - INDEX_NAME:
Vector Search Index
的資源名稱。格式:projects/{project}/locations/{location}/indexes/{index}
- INDEX_ENDPOINT_NAME:
Vector 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
列出 RAG 語料庫示例
以下程式碼範例示範如何列出所有 RAG 語料庫。
REST
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:您的專案 ID。
- LOCATION:處理要求的區域。
- PAGE_SIZE:標準清單頁面大小。您可以更新
page_size
參數,調整每頁傳回的RagCorpora
數量。 - 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
PROJECT_ID
下的 RagCorpora
清單。
取得 RAG 語料庫範例
REST
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:您的專案 ID。
- LOCATION:處理要求的區域。
- RAG_CORPUS_ID:
RagCorpus
資源的 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
資源。範例中使用 get
和 list
指令,說明 RagCorpus
如何使用 rag_embedding_model_config
欄位,並在 vector_db_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_ID:
RagCorpus
資源的 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
。檔案管理範例
本節提供使用 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
是指匯入作業中略過的檔案數量。系統會在符合下列條件時略過檔案:
- 檔案已匯入。
- 檔案並未變更。
- 檔案的分塊設定未變更。
REST
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:您的專案 ID。
- LOCATION:處理要求的區域。
- RAG_CORPUS_ID:
RagCorpus
資源的 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
資源。以下範例示範如何從 Cloud Storage 匯入檔案。使用 max_embedding_requests_per_min
控制欄位,限制 RAG Engine 在 ImportRagFiles
索引程序中呼叫嵌入模型的頻率。這個欄位的預設值為每分鐘 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
以下範例說明如何從 Google 雲端硬碟匯入檔案。使用 max_embedding_requests_per_min
控制欄位,限制 RAG 引擎在 ImportRagFiles
索引程序中呼叫嵌入模型的頻率。這個欄位的預設值為每分鐘 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_ID:
RagCorpus
資源的 ID。 - PAGE_SIZE:標準清單頁面大小。您可以更新
page_size
參數,調整每頁傳回的RagFiles
數量。 - 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
RAG_CORPUS_ID
底下的 RagFiles
清單。
取得 RAG 檔案範例
這個程式碼範例說明如何取得 RAG 檔案。
REST
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:您的專案 ID。
- LOCATION:處理要求的區域。
- RAG_CORPUS_ID:
RagCorpus
資源的 ID。 - RAG_FILE_ID:
RagFile
資源的 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_ID:
RagCorpus
資源的 ID。 - RAG_FILE_ID:
RagFile
資源的 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
使用任何要求資料之前,請先替換以下項目:
- LOCATION:處理要求的區域。
- PROJECT_ID:您的專案 ID。
- RAG_CORPUS_RESOURCE:
RagCorpus
資源的名稱。格式:projects/{project}/locations/{location}/ragCorpora/{rag_corpus}
。 - VECTOR_DISTANCE_THRESHOLD:只傳回向量距離小於閾值的上下文。
- TEXT:用於取得相關內容的查詢文字。
- SIMILARITY_TOP_K:要擷取的重要上下文數量。
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" }, "vector_distance_threshold": VECTOR_DISTANCE_THRESHOLD }, "query": { "text": "TEXT", "similarity_top_k": SIMILARITY_TOP_K } }
如要傳送要求,請選擇以下其中一個選項:
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
RagFiles
清單。
代別
大型語言模型會使用擷取的內容,生成有依據的回覆。
REST
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:您的專案 ID。
- LOCATION:處理要求的區域。
- MODEL_ID:用於產生內容的 LLM 模型。範例:
gemini-2.0-flash-001
- GENERATION_METHOD:用於產生內容的 LLM 方法。選項:
generateContent
、streamGenerateContent
- INPUT_PROMPT:傳送至 LLM 的文字,用於產生內容。請嘗試使用與上傳的 rag 檔案相關的提示。
- RAG_CORPUS_RESOURCE:
RagCorpus
資源的名稱。格式:projects/{project}/locations/{location}/ragCorpora/{rag_corpus}
。 - SIMILARITY_TOP_K:選用:要擷取的重要上下文數量。
- VECTOR_DISTANCE_THRESHOLD:選用:傳回向量距離小於閾值的上下文。
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" }, "similarity_top_k": SIMILARITY_TOP_K, "vector_distance_threshold": VECTOR_DISTANCE_THRESHOLD } } } }
如要傳送要求,請選擇以下其中一個選項:
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
後續步驟
- 如要進一步瞭解支援的生成模型,請參閱「支援 RAG 的生成式 AI 模型」。
- 如要進一步瞭解支援的嵌入模型,請參閱「嵌入模型」。
- 如要進一步瞭解開放式模型,請參閱「開放式模型」。
- 如要進一步瞭解 RAG 引擎,請參閱「RAG 引擎總覽」。