Skip to content

Commit bc61708

Browse files
yinghsienwucopybara-github
authored andcommitted
fix: fix rag resource parsing
Fixes #6442 PiperOrigin-RevId: 888772249
1 parent 798dd81 commit bc61708

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

tests/unit/vertex_rag/test_rag_data.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,32 @@ def test_update_corpus_failure(self):
653653
)
654654
e.match("Failed in RagCorpus update due to")
655655

656+
@pytest.mark.usefixtures("rag_data_client_mock")
657+
@pytest.mark.parametrize("corpus_name", ["Capital-Corpus", "123-Corpus"])
658+
def test_get_corpus_with_valid_resource_name_success(self, corpus_name):
659+
# Tests regex allowing names starting with uppercase or digits.
660+
rag_corpus = rag.get_corpus(corpus_name)
661+
rag_corpus_eq(rag_corpus, test_rag_constants.TEST_RAG_CORPUS)
662+
663+
@pytest.mark.usefixtures("rag_data_client_mock")
664+
@pytest.mark.parametrize("file_name", ["Capital-File", "123-File"])
665+
def test_get_file_with_valid_resource_name_success(self, file_name):
666+
# This test covers the regex change for RAG file names.
667+
rag_file = rag.get_file(
668+
name=file_name,
669+
corpus_name=test_rag_constants.TEST_RAG_CORPUS_ID,
670+
)
671+
rag_file_eq(rag_file, test_rag_constants.TEST_RAG_FILE)
672+
673+
def test_get_corpus_with_invalid_name_format_failure(self):
674+
# Verify names starting with invalid characters (like underscore) still fail.
675+
with pytest.raises(ValueError) as e:
676+
rag.get_corpus("_invalid-name")
677+
e.match(
678+
"name must be of the format `projects/{project}/locations/{location}/"
679+
"ragCorpora/{rag_corpus}` or `{rag_corpus}`"
680+
)
681+
656682
@pytest.mark.usefixtures("rag_data_client_mock")
657683
def test_get_corpus_success(self):
658684
rag_corpus = rag.get_corpus(test_rag_constants.TEST_RAG_CORPUS_RESOURCE_NAME)

vertexai/rag/utils/_gapic_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
)
6969

7070

71-
_VALID_RESOURCE_NAME_REGEX = "[a-z][a-zA-Z0-9._-]{0,127}"
71+
_VALID_RESOURCE_NAME_REGEX = "[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}"
7272
_VALID_DOCUMENT_AI_PROCESSOR_NAME_REGEX = (
7373
r"projects/[^/]+/locations/[^/]+/processors/[^/]+(?:/processorVersions/[^/]+)?"
7474
)

0 commit comments

Comments
 (0)