Skip to content

Commit 5898f37

Browse files
loic-combisharanrk
authored andcommitted
fix: prevent VertexAiRagRetrieval from blocking the event loop
VertexAiRagRetrieval.run_async() called rag.retrieval_query() directly. That call issues a synchronous, blocking gRPC request which freezes the asyncio event loop for ~1-2s on every invocation, even though run_async is an async method. This is especially harmful for real-time/streaming use cases (StreamingMode.BIDI with gemini-live models), causing audio/video desync and dropped frames. Defer the blocking call to a worker thread via asyncio.to_thread, matching the established pattern already used across ADK (e.g. the GCS/file artifact services and the Spanner/BigQuery tools). Closes #5033 Co-authored-by: Haran Rajkumar <haranrk@google.com> PiperOrigin-RevId: 934014525
1 parent 7443bfa commit 5898f37

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from __future__ import annotations
1818

19+
import asyncio
1920
import logging
2021
from typing import Any
2122
from typing import TYPE_CHECKING
@@ -94,7 +95,8 @@ async def run_async(
9495
) -> Any:
9596
from ...dependencies.vertexai import rag
9697

97-
response = rag.retrieval_query(
98+
response = await asyncio.to_thread(
99+
rag.retrieval_query,
98100
text=args['query'],
99101
rag_resources=self.vertex_rag_store.rag_resources,
100102
rag_corpora=self.vertex_rag_store.rag_corpora,

0 commit comments

Comments
 (0)