Skip to content

Comments

SDK rejects valid numeric RAG Corpus IDs due to _VALID_RESOURCE_NAME_…#6355

Open
Mauratay wants to merge 1 commit intogoogleapis:mainfrom
Mauratay:patch-1
Open

SDK rejects valid numeric RAG Corpus IDs due to _VALID_RESOURCE_NAME_…#6355
Mauratay wants to merge 1 commit intogoogleapis:mainfrom
Mauratay:patch-1

Conversation

@Mauratay
Copy link

…REGEX in _gapic_utils.py

the SDK validates {rag_corpus} names against the following regex: VALID_RESOURCE_NAME_REGEX = "[a-z][a-zA-Z0-9.-]{0,127}"

Because this regex strictly requires the first character to be a lowercase letter [a-z], it fails for any numeric IDs generated by Google Cloud, causing functions like get_corpus_name to throw a confusing ValueError instructing the user to provide the correct format.

Steps to reproduce:

import vertexai
from vertexai.rag.utils import _gapic_utils

# 1. Initialize Vertex AI 
vertexai.init(project="PROJECT_NAME", location="us-central1")

# 2. Attempt to use a numeric rag_corpus ID
try:
    formatted_name = _gapic_utils.get_corpus_name("123456789")
    print(f"Success: {formatted_name}")
except ValueError as e:
    print(e) 
    # Output: name must be of the format `projects/{project}/locations/{location}/ragCorpora/{rag_corpus}` or `{rag_corpus}`

BEFORE

VALID_RESOURCE_NAME_REGEX = "[a-z][a-zA-Z0-9.-]{0,127}"

AFTER

VALID_RESOURCE_NAME_REGEX = "[a-zA-Z0-9][a-zA-Z0-9.-]{0,127}"

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Get the necessary approvals
  • Once the last commit on the PR has been approved, add the "ready to pull" label to the Pull Request

Note: do not merge your PR from GitHub. Adding the "ready to pull" label is the final step in the review process.
After approvals, the changes in your PR will be committed to the main branch and this PR will be closed.

Fixes #<issue_number_goes_here> 🦕

…REGEX in _gapic_utils.py

 the SDK validates {rag_corpus} names against the following regex: _VALID_RESOURCE_NAME_REGEX = "[a-z][a-zA-Z0-9._-]{0,127}"

Because this regex strictly requires the first character to be a lowercase letter [a-z], it fails for any numeric IDs generated by Google Cloud, causing functions like get_corpus_name to throw a confusing ValueError instructing the user to provide the correct format.

Steps to reproduce:
~~~
import vertexai
from vertexai.rag.utils import _gapic_utils

# 1. Initialize Vertex AI 
vertexai.init(project="PROJECT_NAME", location="us-central1")

# 2. Attempt to use a numeric rag_corpus ID
try:
    formatted_name = _gapic_utils.get_corpus_name("123456789")
    print(f"Success: {formatted_name}")
except ValueError as e:
    print(e) 
    # Output: name must be of the format `projects/{project}/locations/{location}/ragCorpora/{rag_corpus}` or `{rag_corpus}`
~~~

# BEFORE
_VALID_RESOURCE_NAME_REGEX = "[a-z][a-zA-Z0-9._-]{0,127}"

# AFTER
_VALID_RESOURCE_NAME_REGEX = "[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}"
@product-auto-label product-auto-label bot added size: xs Pull request size is extra small. api: vertex-ai Issues related to the googleapis/python-aiplatform API. labels Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: vertex-ai Issues related to the googleapis/python-aiplatform API. size: xs Pull request size is extra small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant