Skip to content

Commit b9fecea

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
fix: Rag - fix upload file environment mismatch
PiperOrigin-RevId: 703549419
1 parent a604a2e commit b9fecea

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

tests/unit/vertex_rag/test_rag_constants.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@
163163
TEST_FILE_DISPLAY_NAME = "my-file.txt"
164164
TEST_FILE_DESCRIPTION = "my file."
165165
TEST_HEADERS = {"X-Goog-Upload-Protocol": "multipart"}
166-
TEST_UPLOAD_REQUEST_URI = "https://{}/upload/v1/projects/{}/locations/{}/ragCorpora/{}/ragFiles:upload".format(
167-
TEST_API_ENDPOINT, TEST_PROJECT_NUMBER, TEST_REGION, TEST_RAG_CORPUS_ID
166+
TEST_UPLOAD_REQUEST_URI = (
167+
"https://{}/v1/projects/{}/locations/{}/ragCorpora/{}/ragFiles:upload".format(
168+
TEST_API_ENDPOINT, TEST_PROJECT_NUMBER, TEST_REGION, TEST_RAG_CORPUS_ID
169+
)
168170
)
169171
TEST_RAG_FILE_ID = "generate-456"
170172
TEST_RAG_FILE_RESOURCE_NAME = (

tests/unit/vertex_rag/test_rag_constants_preview.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,10 @@
308308
TEST_FILE_DISPLAY_NAME = "my-file.txt"
309309
TEST_FILE_DESCRIPTION = "my file."
310310
TEST_HEADERS = {"X-Goog-Upload-Protocol": "multipart"}
311-
TEST_UPLOAD_REQUEST_URI = "https://{}/upload/v1beta1/projects/{}/locations/{}/ragCorpora/{}/ragFiles:upload".format(
312-
TEST_API_ENDPOINT, TEST_PROJECT_NUMBER, TEST_REGION, TEST_RAG_CORPUS_ID
311+
TEST_UPLOAD_REQUEST_URI = (
312+
"https://{}/v1beta1/projects/{}/locations/{}/ragCorpora/{}/ragFiles:upload".format(
313+
TEST_API_ENDPOINT, TEST_PROJECT_NUMBER, TEST_REGION, TEST_RAG_CORPUS_ID
314+
)
313315
)
314316
TEST_RAG_FILE_ID = "generate-456"
315317
TEST_RAG_FILE_RESOURCE_NAME = (

vertexai/preview/rag/rag_data.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,14 @@ def upload_file(
409409
if display_name is None:
410410
display_name = "vertex-" + utils.timestamped_unique_name()
411411
headers = {"X-Goog-Upload-Protocol": "multipart"}
412-
upload_request_uri = "https://{}-{}/upload/v1beta1/{}/ragFiles:upload".format(
413-
location,
414-
aiplatform.constants.base.API_BASE_PATH,
412+
if not initializer.global_config.api_endpoint:
413+
request_endpoint = "{}-{}".format(
414+
location, aiplatform.constants.base.API_BASE_PATH
415+
)
416+
else:
417+
request_endpoint = initializer.global_config.api_endpoint
418+
upload_request_uri = "https://{}/v1beta1/{}/ragFiles:upload".format(
419+
request_endpoint,
415420
corpus_name,
416421
)
417422
js_rag_file = {"rag_file": {"display_name": display_name}}
@@ -448,7 +453,9 @@ def upload_file(
448453
raise RuntimeError("Failed in uploading the RagFile due to: ", e) from e
449454

450455
if response.status_code == 404:
451-
raise ValueError("RagCorpus '%s' is not found.", corpus_name)
456+
raise ValueError(
457+
"RagCorpus '%s' is not found: %s", corpus_name, upload_request_uri
458+
)
452459
if response.json().get("error"):
453460
raise RuntimeError(
454461
"Failed in indexing the RagFile due to: ", response.json().get("error")

vertexai/rag/rag_data.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,14 @@ def upload_file(
332332
if display_name is None:
333333
display_name = "vertex-" + utils.timestamped_unique_name()
334334
headers = {"X-Goog-Upload-Protocol": "multipart"}
335-
upload_request_uri = "https://{}-{}/upload/v1/{}/ragFiles:upload".format(
336-
location,
337-
aiplatform.constants.base.API_BASE_PATH,
335+
if not initializer.global_config.api_endpoint:
336+
request_endpoint = "{}-{}".format(
337+
location, aiplatform.constants.base.API_BASE_PATH
338+
)
339+
else:
340+
request_endpoint = initializer.global_config.api_endpoint
341+
upload_request_uri = "https://{}/v1/{}/ragFiles:upload".format(
342+
request_endpoint,
338343
corpus_name,
339344
)
340345
js_rag_file = {"rag_file": {"display_name": display_name}}
@@ -372,7 +377,9 @@ def upload_file(
372377
raise RuntimeError("Failed in uploading the RagFile due to: ", e) from e
373378

374379
if response.status_code == 404:
375-
raise ValueError("RagCorpus '%s' is not found.", corpus_name)
380+
raise ValueError(
381+
"RagCorpus '%s' is not found: %s", corpus_name, upload_request_uri
382+
)
376383
if response.json().get("error"):
377384
raise RuntimeError(
378385
"Failed in indexing the RagFile due to: ", response.json().get("error")

0 commit comments

Comments
 (0)