Cloudflare, Inc. (Wikipedia) is an American company that provides content delivery network services, cloud cybersecurity, DDoS mitigation, and ICANN-accredited domain registration services.
Cloudflare Workers AI allows you to run machine learning models, on the
Cloudflare
network, from your code via REST API.
Setting upWorkers AI Developer Docs lists all text embeddings models available.
Both a Cloudflare Account ID and Workers AI API token are required. Find how to obtain them from this document.
You can pass these parameters explicitly or define as environmental variables.
import os
from dotenv import load_dotenv
load_dotenv(".env")
cf_acct_id = os.getenv("CF_ACCOUNT_ID")
cf_ai_token = os.getenv("CF_AI_API_TOKEN")
Example
from langchain_cloudflare.embeddings import (
CloudflareWorkersAIEmbeddings,
)
embeddings = CloudflareWorkersAIEmbeddings(
account_id=cf_acct_id,
api_token=cf_ai_token,
model_name="@cf/baai/bge-small-en-v1.5",
)
query_result = embeddings.embed_query("test")
len(query_result), query_result[:3]
(384, [-0.033660888671875, 0.039764404296875, 0.03558349609375])
batch_query_result = embeddings.embed_documents(["test1", "test2", "test3"])
len(batch_query_result), len(batch_query_result[0])
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4