Skip to content

Commit e528749

Browse files
seanzhougooglecopybara-github
authored andcommitted
fix: lazy import VertexAiRagRetrieval
original codes try to eagerly import VertexAiRagRetrieval while it doesn't want to raise error if client try to import other names in this package and dependencies of VertexAiRagRetrieval is missing. so it swallow the import error which doesn't make sense, given vertex sdk is a must have for VertexAiRagRetrieval, we should fail fast. this fix achieve the same purpose but fail fast if client try to import VertexAiRagRetrieval from this package and miss certain dependencies (e.g. vertex sdk) PiperOrigin-RevId: 791759776
1 parent 1686cc5 commit e528749

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/google/adk/tools/retrieval/__init__.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,13 @@
2020
'BaseRetrievalTool',
2121
'FilesRetrieval',
2222
'LlamaIndexRetrieval',
23+
'VertexAiRagRetrieval',
2324
]
2425

25-
try:
26-
from .vertex_ai_rag_retrieval import VertexAiRagRetrieval
2726

28-
__all__.append('VertexAiRagRetrieval')
29-
except ImportError:
30-
import logging
27+
def __getattr__(name: str):
28+
if name == 'VertexAiRagRetrieval':
29+
from .vertex_ai_rag_retrieval import VertexAiRagRetrieval
3130

32-
logger = logging.getLogger('google_adk.' + __name__)
33-
logger.debug(
34-
'The Vertex sdk is not installed. If you want to use the Vertex RAG with'
35-
' agents, please install it. If not, you can ignore this warning.'
36-
)
31+
return VertexAiRagRetrieval
32+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")

0 commit comments

Comments
 (0)