Skip to content
Closed
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
4 changes: 3 additions & 1 deletion src/google/adk/dependencies/vertexai.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@

import vertexai as vertexai
from vertexai.preview import example_stores as example_stores
from vertexai.preview import rag as rag

# vertexai.preview.rag is not imported here: loading it emits a UserWarning
# on google-cloud-aiplatform 1.163+, and evaluation only needs vertexai itself.
6 changes: 4 additions & 2 deletions src/google/adk/tools/retrieval/vertex_ai_rag_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .base_retrieval_tool import BaseRetrievalTool

if TYPE_CHECKING:
from ...dependencies.vertexai import rag
from vertexai.preview import rag

logger = logging.getLogger('google_adk.' + __name__)

Expand Down Expand Up @@ -100,7 +100,9 @@ async def run_async(
args: dict[str, Any],
tool_context: ToolContext,
) -> Any:
from ...dependencies.vertexai import rag
# Load inside the call: vertexai.preview.rag is deprecated and warns on
# import, so evaluation and other Vertex helpers must not pull it in.
from vertexai.preview import rag

query = args.get('query')
if not isinstance(query, str):
Expand Down
60 changes: 60 additions & 0 deletions tests/unittests/dependencies/test_vertexai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import importlib
import subprocess
import sys
import warnings


def test_importing_eval_facade_does_not_warn_about_preview_rag():
"""Importing the Vertex AI eval facade does not emit the preview.rag deprecation."""
script = """
import warnings

warnings.simplefilter('always', UserWarning)
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter('always', UserWarning)
import google.adk.evaluation.vertex_ai_eval_facade

rag_warnings = [w for w in caught if 'preview.rag' in str(w.message)]
raise SystemExit(1 if rag_warnings else 0)
"""
result = subprocess.run(
[sys.executable, '-c', script],
capture_output=True,
text=True,
check=False,
)
assert result.returncode == 0, result.stderr or result.stdout


def test_vertexai_dependency_does_not_load_preview_rag():
"""Importing google.adk.dependencies.vertexai does not load vertexai.preview.rag."""
sys.modules.pop('google.adk.dependencies.vertexai', None)
sys.modules.pop('vertexai.preview.rag', None)

with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter('always', UserWarning)
module = importlib.import_module('google.adk.dependencies.vertexai')
importlib.reload(module)

rag_warnings = [
warning for warning in caught if 'preview.rag' in str(warning.message)
]
assert rag_warnings == []
assert 'vertexai.preview.rag' not in sys.modules
assert 'rag' not in module.__dict__
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ async def test_retrieval_query_gets_the_original_rag_resources(mocker):
description='rag_retrieval',
rag_resources=[resource],
)
retrieval_query = mocker.patch(
'google.adk.dependencies.vertexai.rag.retrieval_query'
)
retrieval_query = mocker.patch('vertexai.preview.rag.retrieval_query')
retrieval_query.return_value.contexts.contexts = []

await retrieval.run_async(args={'query': 'q'}, tool_context=mocker.Mock())
Expand Down
Loading