Skip to content

Comments

Fix event loop blocking in Vertex AI embedder with asyncio.to_thread#59

Draft
Copilot wants to merge 3 commits intoadkfrom
copilot/sub-pr-35-please-work
Draft

Fix event loop blocking in Vertex AI embedder with asyncio.to_thread#59
Copilot wants to merge 3 commits intoadkfrom
copilot/sub-pr-35-please-work

Conversation

Copy link

Copilot AI commented Feb 6, 2026

The Vertex AI embedder's embed() and embed_batch() methods were calling synchronous SDK methods directly from async functions, blocking the event loop during I/O operations.

Changes

  • Non-blocking I/O: Wrap model.get_embeddings() calls with asyncio.to_thread() to offload synchronous API calls to thread pool
  • Correct API usage: Use TextEmbeddingInput objects to pass task_type parameter (the SDK requires wrapping strings with task metadata)
  • Test updates: Verify TextEmbeddingInput objects are constructed correctly with task_type
# Before - blocks event loop
embeddings = model.get_embeddings([text], task_type=self._task_type)

# After - runs in thread pool
input_obj = TextEmbeddingInput(text, task_type=self._task_type)
embeddings = await asyncio.to_thread(model.get_embeddings, [input_obj])

The task_type parameter is not accepted by get_embeddings() directly - it must be passed via TextEmbeddingInput wrapper objects per the Vertex AI SDK API design.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link

vercel bot commented Feb 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agent-memory Ready Ready Preview, Comment Feb 6, 2026 5:34pm

- Implement asyncio.to_thread() in embed() and embed_batch() methods
- Use TextEmbeddingInput to properly pass task_type parameter
- Update unit tests to verify TextEmbeddingInput usage
- Remove blocking synchronous API calls from async methods
- Add proper type annotations to satisfy mypy

Co-authored-by: johnymontana <1222454+johnymontana@users.noreply.github.com>
- Remove redundant type annotation on input_objs
- Add type: ignore comment for mypy false positive on list variance

Co-authored-by: johnymontana <1222454+johnymontana@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on ADK and Vertex AI integrations PR Fix event loop blocking in Vertex AI embedder with asyncio.to_thread Feb 6, 2026
Copilot AI requested a review from johnymontana February 6, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants