feat: add openai to gcp embedding translations for gemini embedding 2 - #2114
Conversation
Signed-off-by: yxia216 <yxia216@bloomberg.net>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2114 +/- ##
==========================================
- Coverage 84.52% 84.50% -0.03%
==========================================
Files 144 144
Lines 20901 21055 +154
==========================================
+ Hits 17667 17792 +125
- Misses 2168 2188 +20
- Partials 1066 1075 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
7e1585a to
0d8b2f5
Compare
Signed-off-by: yxia216 <yxia216@bloomberg.net>
0d8b2f5 to
a5929ab
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for multimodal embeddings and the newer Gemini embedContent endpoint. It refactors the OpenAI EmbeddingRequest into a discriminated union to accommodate both classic text-only inputs and chat-style message inputs. The GCP Vertex AI translator is updated to automatically select between predict and embedContent endpoints based on the model name. Feedback focuses on ensuring OpenAI API compliance for batch processing in the embedContent path and improving the handling of the AutoTruncate vendor field by using a pointer to distinguish between explicit false values and omitted fields.
Signed-off-by: yxia216 <yxia216@bloomberg.net>
Co-authored-by: Aaron Choo <achoo30@bloomberg.net> Signed-off-by: hustxiayang <yangxiast@gmail.com>
Signed-off-by: yxia216 <yxia216@bloomberg.net>
aabchoo
left a comment
There was a problem hiding this comment.
Thank you for the changes!
|
/retest |
2 similar comments
|
/retest |
|
/retest |
…envoyproxy#2114) **Description** ### 1. Extend OpenAI embedding API to support multimodal embeddings Gemini Embedding 2 is a multimodal embedding model, but the OpenAI embedding API only supports strings or token arrays as input. To support multimodal inputs (images, audio, video, PDF), we extended the `/v1/embeddings` endpoint with a `messages` field, following the https://github.com/vllm-project/vllm/blob/2a16ece2d342c0c154a4949ad317b521f8c04ec4/vllm/entrypoints/pooling/embed/protocol.py#L113 ### 2. Gemini Embedding 2 `embedContent` endpoint support Gemini Embedding 2 models (`gemini-embedding-2-*`) use the `embedContent` endpoint: https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/get-multimodal-embeddings, unlike older models (`text-embedding-004`, `gemini-embedding-001`) which use the `predict` endpoint. The translator auto-detects the endpoint based on model name. **`EmbeddingInputItem` is only supported with the predict endpoint.** The predict endpoint supports per-instance `task_type` and `title`: ```json { "instances": [ {"content": "query text", "task_type": "RETRIEVAL_QUERY"}, {"content": "doc text", "task_type": "RETRIEVAL_DOCUMENT", "title": "My Doc"} ] } ``` The `embedContent` endpoint does not support per-item task types — it accepts a single `content` with one global `taskType` via `embedContentConfig`. Accepting `EmbeddingInputItem` for `embedContent` would be misleading (users would expect per-item behavior), so we reject it with a clear error. Users should set `task_type` at the request level instead. **`task_type` limitation for `gemini-embedding-2`.** Per the doc: https://docs.cloud.google.com/vertex-ai/generative-ai/docs/embeddings/get-multimodal-embeddings, `gemini-embedding-2` does not support the `task_type` field — the task must be included as a prompt instruction instead (e.g. `"task: search result | query: how to reset password"`). The API silently ignores `taskType` in `embedContentConfig`. We still send it if the user provides it, in case future `embedContent` models support it. **`embedContentConfig` vs deprecated top-level fields.** The REST API reference documents `taskType`, `outputDimensionality`, `autoTruncate` as deprecated top-level fields. The genai SDK v1.54+: https://github.com/googleapis/go-genai/blob/v1.54.0/models.go#L727 sends them via `embedContentConfig` instead. ### Batch processing limitation The Vertex AI REST API does not support batch embedding for `embedContent` models. Experimentally verified: 1. **`batchEmbedContents`** — 404 on all Vertex AI endpoints. This endpoint only exists on the Gemini API (`generativelanguage.googleapis.com`), not Vertex AI (`aiplatform.googleapis.com`). 2. **`embedContent` with `content` (singular)** — works, returns one embedding per request. 3. **`embedContent` with `contents` (plural)** — rejected. 4. **`embedContent` with multiple `parts`** — returns one aggregated embedding, not separate embeddings per part. `parts` are designed for combining modalities, not for batching. A possible workaround is fan-out (splitting batch inputs into multiple `embedContent` calls), but this is out of scope for the gateway. We expect Vertex AI to add `batchEmbedContents` support in the future. There should be little impact on performance: the inference engine is a batch processing engine regardless. Whether it receives a single request or batch requests, the engine batches internally. The only difference is whether the requests arrive in one HTTP call or multiple. --------- Signed-off-by: yxia216 <yxia216@bloomberg.net> Signed-off-by: hustxiayang <yangxiast@gmail.com> Co-authored-by: Dan Sun <dsun20@bloomberg.net> Co-authored-by: Ignasi Barrera <ignasi@tetrate.io> Co-authored-by: Aaron Choo <achoo30@bloomberg.net> Signed-off-by: saixso <sai.soundararajan@spoton.com>
Description
1. Extend OpenAI embedding API to support multimodal embeddings
Gemini Embedding 2 is a multimodal embedding model, but the OpenAI embedding API only supports strings or token arrays as input. To support multimodal inputs (images, audio, video, PDF), we extended the
/v1/embeddingsendpoint with amessagesfield, following the https://github.com/vllm-project/vllm/blob/2a16ece2d342c0c154a4949ad317b521f8c04ec4/vllm/entrypoints/pooling/embed/protocol.py#L1132. Gemini Embedding 2
embedContentendpoint supportGemini Embedding 2 models (
gemini-embedding-2-*) use theembedContentendpoint: https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/get-multimodal-embeddings, unlike older models (text-embedding-004,gemini-embedding-001) which use thepredictendpoint. The translator auto-detects the endpoint based on model name.EmbeddingInputItemis only supported with the predict endpoint. The predict endpoint supports per-instancetask_typeandtitle:{ "instances": [ {"content": "query text", "task_type": "RETRIEVAL_QUERY"}, {"content": "doc text", "task_type": "RETRIEVAL_DOCUMENT", "title": "My Doc"} ] }The
embedContentendpoint does not support per-item task types — it accepts a singlecontentwith one globaltaskTypeviaembedContentConfig. AcceptingEmbeddingInputItemforembedContentwould be misleading (users would expect per-item behavior), so we reject it with a clear error. Users should settask_typeat the request level instead.task_typelimitation forgemini-embedding-2. Per the doc: https://docs.cloud.google.com/vertex-ai/generative-ai/docs/embeddings/get-multimodal-embeddings,gemini-embedding-2does not support thetask_typefield — the task must be included as a prompt instruction instead (e.g."task: search result | query: how to reset password"). The API silently ignorestaskTypeinembedContentConfig. We still send it if the user provides it, in case futureembedContentmodels support it.embedContentConfigvs deprecated top-level fields. The REST API reference documentstaskType,outputDimensionality,autoTruncateas deprecated top-level fields. The genai SDK v1.54+: https://github.com/googleapis/go-genai/blob/v1.54.0/models.go#L727 sends them viaembedContentConfiginstead.Batch processing limitation
The Vertex AI REST API does not support batch embedding for
embedContentmodels. Experimentally verified:batchEmbedContents— 404 on all Vertex AI endpoints. This endpoint only exists on the Gemini API (generativelanguage.googleapis.com), not Vertex AI (aiplatform.googleapis.com).embedContentwithcontent(singular) — works, returns one embedding per request.embedContentwithcontents(plural) — rejected.embedContentwith multipleparts— returns one aggregated embedding, not separate embeddings per part.partsare designed for combining modalities, not for batching.A possible workaround is fan-out (splitting batch inputs into multiple
embedContentcalls), but this is out of scope for the gateway. We expect Vertex AI to addbatchEmbedContentssupport in the future.There should be little impact on performance: the inference engine is a batch processing engine regardless. Whether it receives a single request or batch requests, the engine batches internally. The only difference is whether the requests arrive in one HTTP call or multiple.