fix: route vertex_ai gemini-embedding-* models to embedContent endpoint

When get_model_info() fails to find uses_embed_content for a model
(e.g. due to missing/stale model cost map), fall back to checking the
model name prefix. All gemini-embedding-* models require the
embedContent endpoint, not the legacy :predict endpoint which returns
400 FAILED_PRECONDITION for gemini-embedding-2-preview.

Fixes #23508

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
gambletan 2026-03-13 13:34:10 +08:00
parent 92d39c308c
commit 3e8bbdeefe
2 changed files with 10 additions and 0 deletions

View file

@ -263,6 +263,11 @@ def _get_embedding_url(
except Exception:
uses_embed_content = False
# Fallback: all gemini-embedding-* models require the
# embedContent endpoint, not the legacy :predict endpoint.
if not uses_embed_content and model.startswith("gemini-embedding"):
uses_embed_content = True
endpoint = "embedContent" if uses_embed_content else "predict"
base_url = get_vertex_base_url(vertex_location)

View file

@ -5204,6 +5204,11 @@ def embedding( # noqa: PLR0915
except Exception:
uses_embed_content = False
# Fallback: all gemini-embedding-* models require the
# embedContent endpoint, not the legacy :predict endpoint.
if not uses_embed_content and model.startswith("gemini-embedding"):
uses_embed_content = True
if uses_embed_content:
response = google_batch_embeddings.batch_embeddings( # type: ignore
model=model,