Skip to content

VertexAiRagRetrieval.run_async() blocks the event loop with synchronous gRPC call #5033

Closed

Description

@loic-combis

Description

VertexAiRagRetrieval.run_async() calls rag.retrieval_query() directly, which uses synchronous gRPC under the hood (grpc._channel._blocking → call.next_event()). Despite being an async def method, the entire call blocks the event loop for 1-2 seconds on every invocation.

This is particularly problematic in real-time/streaming applications (e.g. StreamingMode.BIDI with gemini-live-* models) where blocking the event loop causes audio/video desync and dropped frames.

Stack trace captured via event loop watchdog

File "google/adk/tools/retrieval/vertex_ai_rag_retrieval.py", line 95, in run_async
response = rag.retrieval_query(
File "vertexai/preview/rag/rag_retrieval.py", line 270, in retrieval_query
response = client.retrieve_contexts(request=request)
File "grpc/_channel.py", line 1150, in _blocking
event = call.next_event()
Event loop blocked for 1.2s+ on every RAG tool call — not just the first.

Affected code

https://github.com/google/adk-python/blob/main/src/google/adk/tools/retrieval/vertex_ai_rag_retrieval.py#L87-L109

@override
async def run_async(self, *, args, tool_context) -> Any:
    from ...dependencies.vertexai import rag

    # This is a synchronous gRPC call that blocks the event loop
    response = rag.retrieval_query(...)

Suggested fix

Wrap the synchronous call with asyncio.to_thread():

import asyncio

@override
async def run_async(self, *, args, tool_context) -> Any:
    from ...dependencies.vertexai import rag

    response = await asyncio.to_thread(
        rag.retrieval_query,
        text=args['query'],
        rag_resources=self.vertex_rag_store.rag_resources,
        rag_corpora=self.vertex_rag_store.rag_corpora,
        similarity_top_k=self.vertex_rag_store.similarity_top_k,
        vector_distance_threshold=self.vertex_rag_store.vector_distance_threshold,
    )

This is the same pattern used to fix the equivalent issue in GCS artifact storage (#1346 / PR #1347).

Environment

google-adk==1.23.0 (also verified on main — still present)
google-cloud-aiplatform==1.135.0
Python 3.13
Using StreamingMode.BIDI with gemini-live-2.5-flash-native-audio

Activity

  1. added
    tools[Component] This issue is related to tools
    on Mar 28, 2026
  2. added theissue type on Mar 28, 2026
  3. sanketpatil06 commented on Mar 31, 2026

    @sanketpatil06

    Hi @loic-combis , thanks for the raising this. To help us get a full understanding of the issue, would you mind sharing minimal reproduction code? Thanks!

  4. added a commit that references this issue on May 14, 2026
    c01f8ee
  5. sanketpatil06 commented on May 22, 2026

    @sanketpatil06

    Hi @loic-combis , We are closing this issue because it has been inactive for a while without the requested details. If you still need help, please feel free to reach out.
    Thanks.

  6. added a commit that references this issue on Jun 18, 2026
    5898f37
  7. added a commit that references this issue on Aug 11, 2026
    b6ca6ee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

request clarification[Status] The maintainer need clarification or more information from the authortools[Component] This issue is related to tools

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions