Skip to content

complete implementation of open ai text embedding with test #new #34700

Merged
jrmccluskey merged 28 commits intoapache:masterfrom
aditya0yadav:master
May 15, 2025
Merged

complete implementation of open ai text embedding with test #new #34700
jrmccluskey merged 28 commits intoapache:masterfrom
aditya0yadav:master

Conversation

@aditya0yadav
Copy link
Contributor

@aditya0yadav aditya0yadav commented Apr 21, 2025

complete implementation of open ai text embedding with test


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@github-actions
Copy link
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@aditya0yadav
Copy link
Contributor Author

assign set of reviewers

@github-actions
Copy link
Contributor

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @jrmccluskey for label python.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@jrmccluskey
Copy link
Contributor

Hey there! I'll try to get a thorough review pass on your PR this afternoon; however, at a quick glance, this seems like a good candidate for inheriting from the new RemoteModelHandler base class I introduced a few weeks ago. Would you be interested in tweaking your implementation to use this class? It'll streamline your code since it handles the client-side throttling work in the parent class.

@aditya0yadav
Copy link
Contributor Author

Let me check first

Copy link
Contributor

@jrmccluskey jrmccluskey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good starting point for this, just needs some polish and a few additions.

def load_model(self):
# Create the client just before it's needed during pipeline execution
if self.api_key:
client = open_ai.OpenAI(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is missing. the package is also openai based on the official library docs - https://platform.openai.com/docs/libraries?language=python

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as below it is fixed
it will be shown in upcoming commit

boolean indication whether or not the exception is a Server Error (5xx) or
a RateLimitError (429) error.
"""
return isinstance(exception, (RateLimitError, APIError))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need an import for these exceptions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because of the unknown reason some of the import is missing i just add those import
it will be shown in a upcoming update commit

MLTransformOutputT = TypeVar('MLTransformOutputT')

# Default batch size for OpenAI calls
_BATCH_SIZE = 20 # OpenAI can handle larger batches than Vertex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could likely be handled in the model handler instead of being hard-coded here

@aditya0yadav
Copy link
Contributor Author

@jrmccluskey i dont know why some of the import statement is missing
even though place i store the code for backup have the import statement but in pull request it is missing

is it because of the formating ?

@aditya0yadav
Copy link
Contributor Author

aditya0yadav commented Apr 23, 2025

@jrmccluskey
nearly all the changes is completed according to your
but i am facing some problem in the lint and formating
i need your help on this one please

@jrmccluskey
Copy link
Contributor

For the linting you should be able to pip install yapf==0.29.0 in the virtual environment you're working in and just run it from the command line:

yapf --in-place --recursive . in the inference directory would do it.

The formatting check can catch other things but the failure in this case is just yapf again.

@aditya0yadav
Copy link
Contributor Author

@jrmccluskey I'm trying to fix the linting error, but I'm not having any luck.
I checked run_lint.sh and tried a few other things, but the error still persists.
What should I do next?

@jrmccluskey
Copy link
Contributor

Here's the list of specific failures:
image
For the unused imports/vars you should just remove them, running yapf as i described above should fix the line-too-long errors. You can also add # pylint: disable=line-too-long to the end of the too-long lines if yapf cannot format them down for whatever reason

@aditya0yadav
Copy link
Contributor Author

aditya0yadav commented Apr 25, 2025

@jrmccluskey The lint error is fixed, but now there's an error in the Prism runner that's unrelated to OpenAI. What should I do next?

before that this error is not coming

@aditya0yadav
Copy link
Contributor Author

Hi @jrmccluskey,
I was going through the remote handler and was wondering — would it also support the embedding handler?
From what I saw, your implementation seems focused on the model handler. Just wanted to clarify.

@aditya0yadav
Copy link
Contributor Author

Hi @jrmccluskey,
i have one concern about embedding handler as you know openai does not provide any model for embedding generation for image
then what to do about this ?

@jrmccluskey
Copy link
Contributor

You should be able to ignore prism and yaml failures, those are generally flaky and not impacted by anything here.

The EmbeddingsManager class is effectively a composite PTransform that produces a RunInference transform with a more traditional model handler, I cannot see a reason why that wouldn't work with the remote handler implementation.

Not having a model for image embeddings is fine since you've clearly labeled the class as a text embedding model, we can always add images / multimodal implementations later as APIs become available.

@aditya0yadav
Copy link
Contributor Author

@jrmccluskey all important test is completed
model handler is changes into a remote model handler
please check this out

thanks

@aditya0yadav
Copy link
Contributor Author

aditya0yadav commented Apr 30, 2025

@jrmccluskey

You should be able to ignore prism and yaml failures, those are generally flaky and not impacted by anything here.
thanks for letting me know

The EmbeddingsManager class is effectively a composite PTransform that produces a RunInference transform with a more traditional model handler, I cannot see a reason why that wouldn't work with the remote handler implementation.

sorry , now it is working

Not having a model for image embeddings is fine since you've clearly labeled the class as a text embedding model, we can always add images / multimodal implementations later as APIs become available.

okay

@aditya0yadav
Copy link
Contributor Author

@jrmccluskey
Hope can you please clarify this
what should we do with feast
there is only enrichment handler for the feast
should be create io handler for feast or something else

thanks

organization: Optional[str] = None,
dimensions: Optional[int] = None,
user: Optional[str] = None,
batch_size: Optional[int] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is misleading since you're setting a single batch size value then take it as the max. I'd recommend exposing the min and max batch sizes separately (or just taking them as kwargs)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrmccluskey
Copy link
Contributor

I'm not sure what you're asking about for enrichment. Can you clarify?

@aditya0yadav
Copy link
Contributor Author

actually i wanna is there any need of feast io connector
or improvement in enrichmnet handler like inserting feature
@jrmccluskey

@aditya0yadav
Copy link
Contributor Author

@jrmccluskey
if you are free , please check this out

Copy link
Contributor

@jrmccluskey jrmccluskey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the delay getting back to this, I think you've gotten it to a good place to merge! Thank you

@jrmccluskey jrmccluskey merged commit d5e3766 into apache:master May 15, 2025
90 checks passed
@aditya0yadav
Copy link
Contributor Author

my pleasure

@jrmccluskey

can i ask what else is needed in case of open ai
or can i change the model handler of the vertex ai to the remote model handler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants