Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/unit/vertex_rag/test_rag_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,32 @@ def test_update_corpus_failure(self):
)
e.match("Failed in RagCorpus update due to")

@pytest.mark.usefixtures("rag_data_client_mock")
@pytest.mark.parametrize("corpus_name", ["Capital-Corpus", "123-Corpus"])
def test_get_corpus_with_valid_resource_name_success(self, corpus_name):
# Tests regex allowing names starting with uppercase or digits.
rag_corpus = rag.get_corpus(corpus_name)
rag_corpus_eq(rag_corpus, test_rag_constants.TEST_RAG_CORPUS)

@pytest.mark.usefixtures("rag_data_client_mock")
@pytest.mark.parametrize("file_name", ["Capital-File", "123-File"])
def test_get_file_with_valid_resource_name_success(self, file_name):
# This test covers the regex change for RAG file names.
rag_file = rag.get_file(
name=file_name,
corpus_name=test_rag_constants.TEST_RAG_CORPUS_ID,
)
rag_file_eq(rag_file, test_rag_constants.TEST_RAG_FILE)

def test_get_corpus_with_invalid_name_format_failure(self):
# Verify names starting with invalid characters (like underscore) still fail.
with pytest.raises(ValueError) as e:
rag.get_corpus("_invalid-name")
e.match(
"name must be of the format `projects/{project}/locations/{location}/"
"ragCorpora/{rag_corpus}` or `{rag_corpus}`"
)

@pytest.mark.usefixtures("rag_data_client_mock")
def test_get_corpus_success(self):
rag_corpus = rag.get_corpus(test_rag_constants.TEST_RAG_CORPUS_RESOURCE_NAME)
Expand Down
2 changes: 1 addition & 1 deletion vertexai/rag/utils/_gapic_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
)


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