Skip to content

feat: support native Gemini text embeddings - #4350

Merged
dgageot merged 1 commit into
docker:mainfrom
dgageot:feat/gemini-text-embeddings
Sep 18, 2026
Merged

dgageot merged 1 commit into
docker:mainfrom
dgageot:feat/gemini-text-embeddings

Conversation

@dgageot

@dgageot dgageot commented Sep 17, 2026

Copy link
Copy Markdown
Member

Google's genai SDK exposes a dedicated embeddings API that is meaningfully different from the generic chat path, and wiring it up properly enables RAG use-cases on Gemini without routing through a chat model or falling back to zero-vectors. This PR adds that native embedding support to the Gemini provider.

The implementation lives in pkg/model/provider/gemini/embed.go and handles both the direct (batchEmbedContents) and gateway (predict/Embedding2) transport paths. Single and batch embedding share the same entry point; responses are reordered to match input order so callers never see shuffled results. Input validation rejects empty slices, cardinality mismatches, and unexpected dimension counts early, and the existing retry/error plumbing from the rest of the Gemini provider is reused unchanged. output_dimensionality is exposed as an optional config field in the schema and the latest config package. A worked RAG example (examples/rag/gemini_embeddings.yaml) and updated provider and RAG docs show how to wire it together.

Embeddings are only invoked when the configured backend supplies them; nothing changes for chat, multimodal, default model selection, or task-type prefixes. Switching embedding model or dimensions requires a full reindex — this is called out in the docs. No live paid API calls are made in tests; coverage is via targeted unit and race tests against the Gemini and RAG packages.

@aheritier aheritier added area/docs Documentation changes area/providers For features/issues/fixes related to LLM providers (Bedrock, LiteLLM, Qwen, custom, etc.) area/providers/gemini Google Gemini provider support kind/feat PR adds a new feature (maps to feat:). Use on PRs only. labels Sep 17, 2026

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🔴 CRITICAL

if !ok || dims <= 0 || dims > math.MaxInt32 {
return nil, fmt.Errorf("provider_opts.%s must be a positive integer, got %v", outputDimensionalityOpt, c.ModelConfig.ProviderOpts[outputDimensionalityOpt])
}
config.OutputDimensionality = new(int32(dims))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[high] new(int32(dims)) is a Go compilation error — new requires a type, not a value expression

The embedConfig() function passes a type-conversion expression to new, which Go's type system rejects at compile time. new(T) requires T to be a type literal; int32(dims) is a value expression, not a type. The Go compiler confirms this: int32(dims) is not a type. This prevents the entire gemini package from building, so any attempt to use output_dimensionality in provider_opts will result in a build failure.

Suggested change
config.OutputDimensionality = new(int32(dims))
v := int32(dims)
config.OutputDimensionality = &v
Confidence Score
🟢 strong 100/100

@dgageot
dgageot marked this pull request as ready for review September 17, 2026 17:06
@dgageot
dgageot requested a review from a team as a code owner September 17, 2026 17:06

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

Implements CreateEmbedding/CreateBatchEmbedding via batchEmbedContents
(Vertex single-input path), output_dimensionality provider_opt, and
ordering/cardinality/dimension validation. Adds docs, schema update,
and examples/rag/gemini_embeddings.yaml.

Assisted-By: docker-agent
Signed-off-by: David Gageot <david.gageot@docker.com>
@dgageot
dgageot force-pushed the feat/gemini-text-embeddings branch from c543b6f to d3ae193 Compare September 18, 2026 08:29
@dgageot
dgageot added this pull request to the merge queue Sep 18, 2026
Merged via the queue into docker:main with commit 2e0650e Sep 18, 2026
21 checks passed
@dgageot
dgageot deleted the feat/gemini-text-embeddings branch September 18, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs Documentation changes area/providers/gemini Google Gemini provider support area/providers For features/issues/fixes related to LLM providers (Bedrock, LiteLLM, Qwen, custom, etc.) kind/feat PR adds a new feature (maps to feat:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants