- Cloudflare-hosted
- Batch
BAAI general embedding (Small) model that transforms any given text into a 384-dimensional vector
| Model Info | |
|---|---|
| More information | link ↗ |
| Maximum Input Tokens | 512 |
| Output Dimensions | 384 |
| Batch | Yes |
| Unit Pricing | $0.02 per M input tokens |
Usage
export interface Env {
AI: Ai;
}
export default {
async fetch(request, env): Promise<Response> {
// Can be a string or array of strings]
const stories = [
"This is a story about an orange cloud",
"This is a story about a llama",
"This is a story about a hugging emoji",
];
const embeddings = await env.AI.run(
"@cf/baai/bge-small-en-v1.5",
{
text: stories,
}
);
return Response.json(embeddings);
},
} satisfies ExportedHandler<Env>;
import os
import requests
ACCOUNT_ID = "your-account-id"
AUTH_TOKEN = os.environ.get("CLOUDFLARE_AUTH_TOKEN")
stories = [
'This is a story about an orange cloud',
'This is a story about a llama',
'This is a story about a hugging emoji'
]
response = requests.post(
f"https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/run/@cf/baai/bge-small-en-v1.5",
headers={"Authorization": f"Bearer {AUTH_TOKEN}"},
json={"text": stories}
)
print(response.json())
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/@cf/baai/bge-small-en-v1.5 \
-X POST \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-d '{ "text": ["This is a story about an orange cloud", "This is a story about a llama", "This is a story about a hugging emoji"] }'Parameters
Synchronous — Send a request and receive a complete response
▶text
one ofrequiredpooling
stringdefault: meanenum: mean, clsThe pooling method used in the embedding process. `cls` pooling will generate more accurate embeddings on larger inputs - however, embeddings created with cls pooling are not compatible with embeddings generated with mean pooling. The default pooling method is `mean` in order for this to not be a breaking change, but we highly suggest using the new `cls` pooling for better accuracy.▶shape[]
array▶data[]
arrayEmbeddings of the requested text valuespooling
stringenum: mean, clsThe pooling method used in the embedding process.Batch — Send multiple requests in a single API call
▶requests[]
arrayrequiredBatch of the embeddings requests to run using async-queue▶shape[]
array▶data[]
arrayEmbeddings of the requested text valuespooling
stringenum: mean, clsThe pooling method used in the embedding process.