Commit fd7059a
.Net: feat: Add support for dimensions in Vertex AI embedding services (#13612)
### Motivation and Context
**Why is this change required?**
PR #10489 added support for configuring embedding [dimensions]
(outputDimensionality) for the Google AI connector, but the equivalent
Vertex AI connector was not updated. This means specifying [Dimensions]
in [EmbeddingGenerationOptions] or via the constructor has no effect
when using Vertex AI — the API always returns the model's default
dimensionality.
**What problem does it solve?**
When using [VertexAIEmbeddingGenerator] or
[VertexAITextEmbeddingGenerationService]with a [dimensions] value (e.g.
128), the output embedding length is the model default (e.g. 3072)
instead of the requested size.
**What scenario does it contribute to?**
Users who need to control embedding dimensionality for storage
optimization, performance, or compatibility with downstream systems when
using the Vertex AI endpoint.
Fixes: #12988
### Description
This PR adds outputDimensionality support to the Vertex AI embedding
connector, mirroring the existing Google AI implementation from PR
#10489.
The Google connector has two parallel embedding paths — Google AI (uses
API key, calls generativelanguage.googleapis.com) and Vertex AI (uses
bearer token, calls [{location}-aiplatform.googleapis.com]). PR #10489
only wired up dimensions for the Google AI path. This PR applies the
same pattern to every layer of the Vertex AI path.
The key structural difference between the two APIs is where
outputDimensionality goes in the request JSON:
Google AI puts it per-content-item: `{ "requests": [{ "content": {...},
"outputDimensionality": 128 }] }`
Vertex AI puts it in the shared parameters block: `{ "instances": [...],
"parameters": { "autoTruncate": false, "outputDimensionality": 128 } }`
The implementation follows this difference. In
[VertexAIEmbeddingRequest], outputDimensionality is added to the
existing [RequestParameters] class (alongside autoTruncate), rather than
on each instance item.
Dimensions flow through the same chain as Google AI:
1. Extension methods accept int? dimensions = null and pass it to the
generator/service constructor
2. [VertexAIEmbeddingGenerator] passes it to
[VertexAITextEmbeddingGenerationService]
3. The service passes it to [VertexAIEmbeddingClient], which stores it
as a default
4. At request time, the client resolves the final value as
[options?.Dimensions ?? this._dimensions] — runtime
[EmbeddingGenerationOptions] take priority over the constructor default
5. [VertexAIEmbeddingRequest.FromData()] sets it on the parameters
block, and [JsonIgnore(WhenWritingNull)] ensures it's omitted when not
specified
All new parameters default to null, preserving full backward
compatibility.
### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
---------
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: abbottdev <3226335+abbottdev@users.noreply.github.com>
Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>1 parent 14ea2fc commit fd7059a
File tree
9 files changed
+477
-57
lines changed- dotnet/src/Connectors
- Connectors.Google.UnitTests/Services
- Connectors.Google
- Core/VertexAI
- Extensions
- Services
9 files changed
+477
-57
lines changedLines changed: 164 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
3 | 7 | | |
4 | 8 | | |
5 | 9 | | |
6 | 10 | | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
10 | | - | |
| 14 | + | |
11 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
12 | 49 | | |
13 | 50 | | |
14 | 51 | | |
15 | 52 | | |
16 | | - | |
17 | | - | |
| 53 | + | |
18 | 54 | | |
19 | 55 | | |
20 | | - | |
| 56 | + | |
21 | 57 | | |
22 | 58 | | |
23 | 59 | | |
24 | 60 | | |
25 | 61 | | |
26 | 62 | | |
27 | | - | |
28 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
29 | 178 | | |
30 | 179 | | |
31 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
32 | 189 | | |
33 | 190 | | |
0 commit comments