Skip to content

Python: Allow output_dimensionality above 768 in GoogleAIEmbeddingPromptExecutionSettings - #14742

Open
Qiming Bao (14H034160212) wants to merge 1 commit into
microsoft:mainfrom
14H034160212:fix-google-embedding-dimensionality
Open

Qiming Bao (14H034160212) wants to merge 1 commit into
microsoft:mainfrom
14H034160212:fix-google-embedding-dimensionality

Conversation

@14H034160212

Copy link
Copy Markdown

Motivation and Context

GoogleAIEmbeddingPromptExecutionSettings.output_dimensionality is declared as Field(le=768) (source). 768 was the size of the older text-embedding-004 vectors. The current Gemini embedding models support larger outputs, so common values are rejected before any request is sent:

from semantic_kernel.connectors.ai.google.google_ai import GoogleAIEmbeddingPromptExecutionSettings

GoogleAIEmbeddingPromptExecutionSettings(output_dimensionality=768)   # OK
GoogleAIEmbeddingPromptExecutionSettings(output_dimensionality=1536)  # ValidationError: less than or equal to 768
GoogleAIEmbeddingPromptExecutionSettings(output_dimensionality=3072)  # ValidationError: less than or equal to 768

Sources:

  • Gemini API embeddings guide: both gemini-embedding-001 and gemini-embedding-2 list "Output dimension size: Flexible, supports: 128 - 3072, Recommended: 768, 1536, 3072". The guide also notes that gemini-embedding-001 embeddings need manual normalization "for dimensions other than 3072", so 3072 is the full-size output.
  • Gemini API reference, embedContent: outputDimensionality is an optional integer, "Reduced dimension for the output embedding. If set, excessive values in the output embedding are truncated from the end." No maximum is given.
  • google-genai (1.75.0, the version the google extra resolves to): EmbedContentConfig.output_dimensionality is Optional[int] with no bounds.

Description

  • output_dimensionality: Field(le=768) changed to Field(gt=0).

    I chose not to replace 768 with a 3072 cap. The limit depends on the model, so a hard-coded maximum goes stale with the next model, which is what happened to 768. Neither the API reference nor the SDK defines a global maximum, and the service already returns a clear error for unsupported sizes. gt=0 still rejects nonsensical values locally. It also matches VertexAIEmbeddingPromptExecutionSettings.output_dimensionality (source), which has no cap.

  • Tests added to tests/unit/connectors/ai/google/google_ai/test_google_ai_request_settings.py:

    • 128, 768, 1536 and 3072 are accepted and reach prepare_settings_dict();
    • 0 and -1 are rejected.

    4 of the new cases fail on main: 1536 and 3072 are rejected, and 0 and -1 are accepted.

Verification (from python/):

uv run --no-sync pytest tests/unit/connectors/ai/google     # 176 passed
uv run --no-sync ruff check <changed files> && uv run --no-sync ruff format --check <changed files>
uv run --no-sync mypy -p semantic_kernel.connectors.ai.google --config-file mypy.ini   # Success: no issues found
uv run --no-sync pre-commit run -c python/.pre-commit-config.yaml --files <changed files>  # all hooks passed

Contribution Checklist

…mptExecutionSettings

output_dimensionality was capped with Field(le=768), the maximum of the
older text-embedding-004 model. gemini-embedding-001 and gemini-embedding-2
support output dimensions from 128 to 3072 (recommended 768, 1536 and
3072), so 1536 and 3072 were rejected before any request was sent.

The supported range depends on the model, and neither the Gemini API
reference nor google-genai's EmbedContentConfig defines an upper bound, so
require only a positive value and leave the model-specific limit to the
service. This matches VertexAIEmbeddingPromptExecutionSettings, which has
no cap.
@14H034160212
Qiming Bao (14H034160212) requested a review from a team as a code owner November 7, 2026 11:16
Copilot AI balanced review requested due to automatic review settings November 7, 2026 11:16
@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Nov 7, 2026

Copilot AI 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.

🟢 Approval recommended

There are no active review issues blocking the embedding-dimension validation change.

No open issues 🎉

What changed in this PR

Updates Google AI embedding settings to accept output dimensions above 768, supporting newer Gemini embedding models without imposing a model-specific upper limit.

Changes:

  • Replaces the 768 maximum with validation requiring positive dimensions.
  • Adds tests confirming accepted values reach prepare_settings_dict() and rejecting zero and negative values.
File Description
python/​tests/​unit/​connectors/​ai/​google/​google_ai/​test_google_ai_request_settings.py Adds parameterized tests for accepted and invalid dimensions.
python/​semantic_kernel/​connectors/​ai/​google/​google_ai/​google_ai_prompt_execution_settings.py Changes dimension validation from le=768 to gt=0.

Review effort: Balanced

This branch was previously deployed

1 inactive deployment
github-app-auth — 83518a1c Deployed Nov 7, 2026 by 14H034160212 via add_label #29623
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants