-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ENH] Add Cloudflare Worker AI Embedding Function #4389
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
Conversation
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
fe8bef0
to
08d65ed
Compare
c14ea0c
to
7d01a2b
Compare
if not self.api_key: | ||
raise ValueError(f"The {api_key_env_var} environment variable is not set.") | ||
|
||
self._api_url = f"https://api.cloudflare.com/client/v4/accounts/{self.account_id}/ai/run/{self.model_name}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit move base url to a const at top of file
return "cloudflare_workers_ai" | ||
|
||
def default_space(self) -> Space: | ||
return "l2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the best default space?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://huggingface.co/BAAI/bge-large-en-v1.5
I think the BAAI models being used prefer others https://developers.cloudflare.com/workers-ai/models/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea youre right, they use cosine, updated
api_key_env_var: str = "CHROMA_CLOUDFLARE_API_KEY", | ||
): | ||
""" | ||
Initialize the CloudflareWorkersAIEmbeddingFunction. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be useful to link to CF docs - https://developers.cloudflare.com/workers-ai/models/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see minor comments before merge
if not self.api_key: | ||
raise ValueError(f"The {api_key_env_var} environment variable is not set.") | ||
|
||
self._api_url = f"https://api.cloudflare.com/client/v4/accounts/{self.account_id}/ai/run/{self.model_name}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cloudflare also supports AI Gateway, which allows for higher limits and more control - https://developers.cloudflare.com/ai-gateway/
Might be a good idea to also include that for completeness. The difference between the two is the endpoint composition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, added a gateway_id
08d65ed
to
3ce0000
Compare
Description of changes
This PR adds support for cloudflare worker embedding function across both python and typescript, adds docs, and schema validation
Test plan
How are these changes tested?
pytest
for python,yarn test
for js,cargo test
for rustDocumentation Changes
Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs section?