Skip to content

GH-3786: Provide encodingFormat=base64 support for the OpenAI embedding model #3804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sunyuhan1998
Copy link
Contributor

As mentioned in the issue #3786 , when using embedding models, we need to support the encodingFormat=base64 parameter. When this format is used, the model returns the embedding field as a base64-encoded string representing a float array. This PR adds support for handling that format.

Changes in this PR:

  1. Introduced a custom JSON deserializer, OpenAiEmbeddingDeserializer, for the embedding field in org.springframework.ai.openai.api.OpenAiApi.Embedding. This deserializer automatically converts the base64-encoded string back into a float array when parsing the API response.
  2. Added corresponding unit tests.

Fixes: #3786

…Api.Embedding`

Introduce `OpenAiEmbeddingDeserializer` to handle base64-encoded embeddings
returned by the model when encodingFormat=base64 is specified.

Signed-off-by: Sun Yuhan <[email protected]>
@sunyuhan1998 sunyuhan1998 changed the title feat: GH-3786 Provide encodingFormat=base64 support for the OpenAI embedding model GH-3786 Provide encodingFormat=base64 support for the OpenAI embedding model Jul 13, 2025
@sunyuhan1998 sunyuhan1998 changed the title GH-3786 Provide encodingFormat=base64 support for the OpenAI embedding model GH-3786: Provide encodingFormat=base64 support for the OpenAI embedding model Jul 13, 2025
@sunyuhan1998
Copy link
Contributor Author

Hi @ilayaperumalg can you help review this PR ? Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Support for OpenAI based64 format embedding responses
1 participant