Cloudflare Docs
Workers AI
Edit this page
Report an issue with this page
Log into the Cloudflare dashboard
Set theme to dark (⇧+D)

bge-base-en-v1.5

Model ID: @cf/baai/bge-base-en-v1.5

BAAI general embedding (bge) models transform any given text into a compact vector

More Information  

​​ Properties

Task Type: Text Embeddings

Max input tokens: 512

Output dimensions: 768

​​ Code Examples

Worker - TypeScript
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-base-en-v1.5",
{
text: stories,
}
);
return Response.json(embeddings);
},
} satisfies ExportedHandler<Env>;
Python
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-base-en-v1.5",
headers={"Authorization": f"Bearer {AUTH_TOKEN}"},
json={"text": stories}
)
print(response.json())
curl
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/@cf/baai/bge-base-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"] }'

​​ Responses

Single string:

{
"shape":[1,768],
"data": [
[0.03190500661730766, 0.006071353796869516, 0.025971125811338425,...]
]
}

Batch of two strings:

{
"shape":[2,768],
"data":[
[0.03190416097640991, 0.006062490865588188, 0.025968171656131744,...],
[0.002439928939566016, -0.021352028474211693, 0.06229676678776741,...],
[-0.02154572866857052,0.09098546206951141,0.006273532286286354,...]
]
}

​​ API Schema

The following schema is based on JSON Schema

Input JSON Schema
{
"type": "object",
"properties": {
"text": {
"oneOf": [
{
"type": "string",
"minLength": 1
},
{
"type": "array",
"items": {
"type": "string",
"minLength": 1
},
"maxItems": 100
}
]
}
},
"required": [
"text"
]
}
Output JSON Schema
{
"type": "object",
"contentType": "application/json",
"properties": {
"shape": {
"type": "array",
"items": {
"type": "number"
}
},
"data": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "number"
}
}
}
}
}

​​ More resources