Skip to content

Commit a885b5d

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: RAG - Add support for max_embedding_requests_per_min in upload_file request
Aligning the default to import_files and the backend of 1000 PiperOrigin-RevId: 797149402
1 parent 1a3f477 commit a885b5d

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

tests/unit/vertex_rag/test_rag_data.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,30 @@ def test_upload_file_success_with_transformation_config(
756756

757757
rag_file_eq(rag_file, test_rag_constants.TEST_RAG_FILE)
758758

759+
@pytest.mark.usefixtures("open_file_mock")
760+
def test_upload_file_success_with_max_embedding_requests_per_min(
761+
self,
762+
upload_file_with_upload_config_mock,
763+
):
764+
aiplatform.init(
765+
project=test_rag_constants.TEST_PROJECT,
766+
location=test_rag_constants.TEST_REGION,
767+
)
768+
rag_file = rag.upload_file(
769+
corpus_name=test_rag_constants.TEST_RAG_CORPUS_RESOURCE_NAME,
770+
path=test_rag_constants.TEST_PATH,
771+
display_name=test_rag_constants.TEST_FILE_DISPLAY_NAME,
772+
transformation_config=create_transformation_config(),
773+
max_embedding_requests_per_min=666,
774+
)
775+
776+
upload_file_with_upload_config_mock.assert_called_once()
777+
_, mock_kwargs = upload_file_with_upload_config_mock.call_args
778+
assert mock_kwargs["url"] == test_rag_constants.TEST_UPLOAD_REQUEST_URI
779+
assert mock_kwargs["headers"] == test_rag_constants.TEST_HEADERS
780+
781+
rag_file_eq(rag_file, test_rag_constants.TEST_RAG_FILE)
782+
759783
@pytest.mark.usefixtures("rag_data_client_mock_exception", "open_file_mock")
760784
def test_upload_file_failure(self):
761785
with pytest.raises(RuntimeError) as e:

vertexai/rag/rag_data.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ def upload_file(
343343
description: Optional[str] = None,
344344
transformation_config: Optional[TransformationConfig] = None,
345345
timeout: int = 600,
346+
max_embedding_requests_per_min: int = 1000,
346347
) -> RagFile:
347-
"""
348-
Synchronous file upload to an existing RagCorpus.
348+
"""Synchronous file upload to an existing RagCorpus.
349349
350350
Example usage:
351351
@@ -375,12 +375,17 @@ def upload_file(
375375
corpus_name: The name of the RagCorpus resource into which to upload the file.
376376
Format: ``projects/{project}/locations/{location}/ragCorpora/{rag_corpus}``
377377
or ``{rag_corpus}``.
378-
path: A local file path. For example,
379-
"usr/home/my_file.txt".
378+
path: A local file path. For example, "usr/home/my_file.txt".
380379
display_name: The display name of the data file.
381380
description: The description of the RagFile.
382381
transformation_config: The config for transforming the RagFile, like chunking.
383382
timeout: Default is 600 seconds.
383+
max_embedding_requests_per_min: Optional. The max number of queries per
384+
minute that this job is allowed to make to the embedding model specified
385+
on the corpus. This value is specific to this job and not shared across
386+
other import jobs. Consult the Quotas page on the project to set an
387+
appropriate value here. If unspecified, a default value of 1,000 QPM
388+
would be used.
384389
385390
Returns:
386391
RagFile.
@@ -421,7 +426,8 @@ def upload_file(
421426
"chunk_overlap": chunk_overlap,
422427
}
423428
}
424-
}
429+
},
430+
"max_embedding_requests_per_min": max_embedding_requests_per_min,
425431
}
426432

427433
files = {

0 commit comments

Comments
 (0)