From 4d39563ea4da0e0ad57b7853556705b6384b56d2 Mon Sep 17 00:00:00 2001 From: Xuan Yang Date: Thu, 18 Sep 2025 23:27:01 -0700 Subject: [PATCH] chore: add yaml files to the ADK Vertex AI Search datastore PiperOrigin-RevId: 808895175 --- .../upload_docs_to_vertex_ai_search.py | 17 +++++++++++++++-- .../samples/adk_answering_agent/utils.py | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/contributing/samples/adk_answering_agent/upload_docs_to_vertex_ai_search.py b/contributing/samples/adk_answering_agent/upload_docs_to_vertex_ai_search.py index 9dd7ca6a..945c3179 100644 --- a/contributing/samples/adk_answering_agent/upload_docs_to_vertex_ai_search.py +++ b/contributing/samples/adk_answering_agent/upload_docs_to_vertex_ai_search.py @@ -72,8 +72,8 @@ def upload_directory_to_gcs( # into hidden directories. dirs[:] = [d for d in dirs if not d.startswith(".")] - # Keep only .md and .py files. - files = [f for f in files if f.endswith(".md") or f.endswith(".py")] + # Keep only .md, .py and .yaml files. + files = [f for f in files if f.endswith((".md", ".py", ".yaml"))] for filename in files: local_path = os.path.join(root, filename) @@ -99,6 +99,19 @@ def upload_directory_to_gcs( bucket.blob(gcs_path).upload_from_string( html_content, content_type=content_type ) + elif filename.lower().endswith(".yaml"): + # Vertex AI search doesn't recognize yaml, + # convert it to text and use text/plain instead + content_type = "text/plain" + with open(local_path, "r", encoding="utf-8") as f: + yaml_content = f.read() + if not yaml_content: + print(" - Skipped empty file: " + local_path) + continue + gcs_path = gcs_path.removesuffix(".yaml") + ".txt" + bucket.blob(gcs_path).upload_from_string( + yaml_content, content_type=content_type + ) else: # Python files bucket.blob(gcs_path).upload_from_filename( local_path, content_type=content_type diff --git a/contributing/samples/adk_answering_agent/utils.py b/contributing/samples/adk_answering_agent/utils.py index f4c65fc2..d3d6c264 100644 --- a/contributing/samples/adk_answering_agent/utils.py +++ b/contributing/samples/adk_answering_agent/utils.py @@ -115,6 +115,10 @@ def convert_gcs_to_https(gcs_uri: str) -> Optional[str]: if relative_path.endswith(".html"): relative_path = relative_path.removesuffix(".html") + ".md" + # Replace .txt with .yaml + if relative_path.endswith(".txt"): + relative_path = relative_path.removesuffix(".txt") + ".yaml" + # Convert the links for adk-docs if prefix == "adk-docs" and relative_path.startswith("docs/"): path_after_docs = relative_path[len("docs/") :]