apache / apache/flink-agents

[Feature] Add OpenAI embedding model (Java)

Open
#1,103 1 comment 0 reactions 1 assignee Claimed by @purushah View on GitHub
Dominant language
Java
Stars
452
Forks
167
Avg merge
5d 9h
Merged PRs (30d)
49

Description

### Search before asking

- [x] I searched in the [issues](https://github.com/apache/flink-agents/issues) and found nothing similar.

### Description

**Motivation**

Python has `OpenAIEmbeddingModelConnection` and `OpenAIEmbeddingModelSetup`; Java has only Ollama and Bedrock. A Java agent that needs an OpenAI embedding today must go through the Python wrapper, which requires a Python environment on the task managers for a plain HTTPS call. This is a Java/Python parity gap. The Java OpenAI chat model already depends on `com.openai:openai-java`, so no new third-party dependency is needed.

**Proposed changes**

- New module `integrations/embedding-models/openai` with `OpenAIEmbeddingModelConnection` and `OpenAIEmbeddingModelSetup`, built the same way `OpenAICompletionsConnection` builds its client.
- Arguments mirror the Python classes one for one: connection `api_key`, `base_url`, `request_timeout`, `max_retries`, `organization`, `project`; setup `connection`, `model`, `encoding_format`, `dimensions`, `user`, `additional_kwargs`.
- `embedWithUsage` reports prompt and total tokens so the embedding token metrics from #870 cover this provider.
- `ResourceName` constants, YAML aliases, `dist` registration, and a Java tab in the OpenAI section of `embedding_models.md`.
- Unit tests with a mocked client, following `BedrockEmbeddingModelTest`.

One naming question: the Java OpenAI chat connection uses `api_base_url` and `timeout`, while the Python embedding connection uses `base_url` and `request_timeout`. I propose the Python embedding names so the two embedding implementations align across languages. Happy to follow the chat-model names instead if preferred.

### Are you willing to submit a PR?

- [x] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.