Osama Malik
Home / Open source / Genkit #6346
Merged

Genkit pull request 6346 stops the Python OpenAI plugin from failing when an embedder is asked for encodingFormat: 'base64'. I wrote it, and it was merged on 23 Sep 2026.

Fixing base64 embeddings in Genkit's OpenAI plugin

The pull request is genkit-ai/genkit #6346, titled fix(py/plugins/openai): encodingFormat 'base64' no longer fails embedding validation. It fixes issue #6317.

The problem

Genkit's Python OpenAI plugin lets you pass encodingFormat to an embedder. Issue #6317 reported that this call failed:

await ai.embed(
    embedder='openai/text-embedding-3-small',
    content='hi',
    options={'encodingFormat': 'base64'},
)

The error was a pydantic validation failure, 1 validation error for Embedding. Embeddings are the input to retrieval in a RAG system, so a broken option here breaks the step before search.

Root cause

The embedder passed encodingFormat straight through to embeddings.create() in the OpenAI Python SDK. The issue explains what the SDK does with it. When encoding_format is omitted, the SDK still requests base64 on the wire and decodes the response to a list of floats itself. When encoding_format is given explicitly, the SDK returns the response unmodified. Each item.embedding was then the raw base64 string, and Embedding(embedding=item.embedding) rejected it, because it expects a list of floats.

The fix

My first version of the pull request added a decoder that turned the base64 string into 32 bit floats inside the plugin. In review, a maintainer pointed out that the SDK already does that decoding when the parameter is omitted, so mapping the user's 'base64' to "omit" sends the same request on the wire with no decoder to maintain. I agreed and removed the decoder in commit 96248e4, which the reviewer confirmed in the thread. The merged fix is the smaller change.

The merged change is in py/packages/genkit-openai/src/genkit_openai/openai_plugin.py. 'base64' is no longer forwarded. 'float' is still forwarded, because it is a genuinely different request:

-                enc_val = request.options.get('encodingFormat')
-                if enc_val in ('float', 'base64'):
-                    encoding_format = cast(Literal['base64', 'float'], enc_val)
+                # 'base64' is deliberately not forwarded: the SDK sends base64 either
+                # way and only decodes the response when it was not asked explicitly.
+                if request.options.get('encodingFormat') == 'float':
+                    encoding_format = 'float'

The type annotation narrowed with it, from Literal['base64', 'float'] | None to Literal['float'] | None. GitHub records 2 files changed, 34 additions and 9 deletions.

How it was tested and reviewed

Two tests were added in py/packages/genkit-openai/tests/openai_plugin_test.py:

  • test_embedder_requesting_base64_omits_the_parameter checks that a base64 request calls embeddings.create with only model and input, and that the returned vector is the list of floats.
  • test_embedder_forwards_float_encoding_format checks that a float request still sends encoding_format='float'.

The pull request also reran the repro from the issue through the real SDK against a mock transport that returns [0.1, -0.25, 0.5] as float32 base64. Before the change it failed with 1 validation error for Embedding. After it, the result was [0.10000000149011612, -0.25, 0.5]. That is a mock transport, not a live OpenAI call.

Review had several rounds. An automated reviewer commented on the first decoder version. A reviewer, who had also opened issue #6317, asked for assert_awaited_once_with in a test, because the original assertion failed the type check, and suggested dropping the decoder. After those changes another reviewer approved with "lgtm" and merged the pull request on 23 Sep 2026. I also signed the Google CLA so the CLA check passed.

What this shows if you are hiring an AI agent engineer

  • I read the SDK underneath a framework, not only the framework. The bug was in how two libraries agreed on one parameter.
  • I take review well. The reviewer's simpler approach was better than my decoder, so the merged fix is the smaller one.
  • I test the contract both ways: the option that changed and the option that must not change.
  • Embeddings are the base of RAG. If you need retrieval built or debugged, see hire a RAG developer and AI chatbot developer.

I did not start Genkit and I am not a maintainer. This is one merged fix. The other merged fixes are on the open source page, including Strands #4313 and Pipecat #5760.

Working with a team abroad? See United States, United Kingdom, Europe or UAE and Saudi Arabia. More writing is on the blog.