spring-projects / spring-projects/spring-ai
Add Support for OpenAI based64 format embedding responses
@sunyuhan1998 is already working on this.
Since Jul 11, 2025.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
OpenAI supports returning embedding responses as base64 encoded which can save a lot of resources see this excellent blog post Speed Up OpenAI Embedding By 4x With This Simple Trick!
Currently Spring AI assumes that the response from OpenAI is coming back as an array of floats see https://github.com/spring-projects/spring-ai/blob/6a1f982203a1de3f1021a7b2279d366cf45afa93/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiEmbeddingModel.java#L181
The embedding class constructor assumes a float[] https://github.com/spring-projects/spring-ai/blob/6a1f982203a1de3f1021a7b2279d366cf45afa93/spring-ai-model/src/main/java/org/springframework/ai/embedding/Embedding.java#L40
You can find info about how the offical python SDK decodes the response at https://github.com/openai/openai-python/blob/db5c35049accb05f5fb03791ef9c12547fd309a7/src/openai/resources/embeddings.py#L204
The offical python SDK uses base64 encoding as of version 1.62 and other sdks are turning on base64 as the default.
Please add support for base64 embeddings to spring AI.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.