Repository navigation
fix(py/openai): split large embed batches into 2048-input requests - #141
Merged
huangjeff5 merged 2 commits intoDec 1, 2026
Merged
Conversation
# Conflicts: # packages/genkit-openai/src/genkit_openai/_openai_plugin.py
Contributor
Author
|
Merged the latest This comment was drafted with Claude Code. |
huangjeff5
approved these changes
Nov 30, 2026
huangjeff5
left a comment
Collaborator
There was a problem hiding this comment.
Verified unit tests in genkit-openai (49 passed). Cleanly chunks batches larger than OpenAI's 2048-input limit while preserving order and passing dimensions/encoding_format on each chunk. Looks good!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moved from genkit-ai/genkit#7079, as the maintainers asked after the Python SDK moved to this repo. The change is the same, rebased onto the current
main(it now also passesctx.contextto_embed_client).The OpenAI embedder in
genkit-openaipassed every document to a singleembeddings.createcall. The OpenAI embeddings endpoint accepts at most 2048 inputs per request, so embedding a larger batch fails. The Google GenAI embedder already splits requests by a batch size.Fix: send the inputs in chunks of 2048 and concatenate the returned embeddings in order. The
dimensionsandencodingFormatoptions go with every chunk. The four-wayif/elifover those options is replaced by a kwargs dict so the loop does not repeat it.Test:
test_embedder_splits_large_batches_into_chunksembeds 5000 documents and expects calls of 2048, 2048 and 904 inputs, the option on each call, and the embeddings back in order. It fails onmainand passes with the change; the other 48 tests inopenai_plugin_test.pystill pass.The JS
compat-oaiembedder has the same shape and is not touched here.Disclosure: this change was prepared with AI assistance (Claude Code).