Skip to content

Commit 068fe53

Browse files
authored
fix(genai): defer async client init for embeddings; avoid eager loop creation (#1183)
1 parent f92f1e1 commit 068fe53

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

libs/genai/langchain_google_genai/embeddings.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,10 @@ def validate_environment(self) -> Self:
116116
client_options=self.client_options,
117117
transport=self.transport,
118118
)
119-
# Only initialize async client if there's an event loop running
120-
# to avoid RuntimeError during synchronous initialization
121-
if _is_event_loop_running():
122-
# async clients don't support "rest" transport
123-
transport = self.transport
124-
if transport == "rest":
125-
transport = "grpc_asyncio"
126-
self.async_client = build_generative_async_service(
127-
credentials=self.credentials,
128-
api_key=google_api_key,
129-
client_info=client_info,
130-
client_options=self.client_options,
131-
transport=transport,
132-
)
133-
else:
134-
self.async_client = None
119+
# Always defer async client initialization to first async call.
120+
# Avoids implicit event loop creation and aligns with lazy init
121+
# in chat models.
122+
self.async_client = None
135123
return self
136124

137125
@property

0 commit comments

Comments
 (0)