Repository navigation
Commit 87eadc7
authored
Python: Batch Google AI embedding requests to the 100-input limit (#14700)
### Motivation and Context
`GoogleAITextEmbedding.generate_raw_embeddings` sent every input text in
a single `embed_content` request. The Gemini `batchEmbedContents`
endpoint accepts at most 100 inputs per request (the same limit
`langchain-google-genai` batches around), so calling
`generate_embeddings` with more than 100 texts, e.g. when indexing a
document set into a vector store, fails with a 400 instead of returning
the embeddings.
### Description
Split `texts` into chunks of at most 100 (`MAX_EMBEDDING_BATCH_SIZE`),
call `embed_content` once per chunk and concatenate the embeddings in
input order. The three client paths (user-supplied client, Vertex AI,
API key) share the same helper. Requests with 100 or fewer texts are
unchanged (a single call). The Vertex AI embedding service
(`vertex_ai_text_embedding.py`) is left untouched: its limit was not
verified.
### Tests
New `test_raw_embedding_batches_large_inputs`: 250 texts produce calls
of 100/100/50 and the results come back in order. It fails on main and
passes with the fix; the rest of the file still passes.
### Contribution Checklist
- [x] The code builds clean without any errors or warnings
- [x] The PR follows the SK Contribution Guidelines
- [x] All unit tests pass, and I have added new tests where possible
This change was prepared with the assistance of an AI coding tool
(Claude Code) and reviewed before submission.1 parent 356acb6 commit 87eadc7
2 files changed
Lines changed: 41 additions & 13 deletions
File tree
- python
- semantic_kernel/connectors/ai/google/google_ai/services
- tests/unit/connectors/ai/google/google_ai/services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
| |||
119 | 122 | | |
120 | 123 | | |
121 | 124 | | |
122 | | - | |
| 125 | + | |
123 | 126 | | |
124 | 127 | | |
125 | | - | |
| 128 | + | |
126 | 129 | | |
127 | 130 | | |
128 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
129 | 140 | | |
130 | | - | |
131 | | - | |
| 141 | + | |
| 142 | + | |
132 | 143 | | |
133 | 144 | | |
134 | 145 | | |
135 | 146 | | |
136 | 147 | | |
137 | 148 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
147 | 155 | | |
148 | 156 | | |
149 | 157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
0 commit comments