Skip to content
Cloudflare Docs
b

bge-base-en-v1.5

Text Embeddingsbaai
@cf/baai/bge-base-en-v1.5

BAAI general embedding (Base) model that transforms any given text into a 768-dimensional vector

Features
More informationlink
Maximum Input Tokens512
Output Dimensions768
BetaYes

Usage

Workers - 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

Terminal window
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"] }'

Parameters

* indicates a required field

Input

  • text * one of

    • 0 string min 1

      The text to embed

    • 1 array

      Batch of text values to embed

      • items string min 1

        The text to embed

Output

  • shape array

    • items number

  • data array

    Embeddings of the requested text values

    • items array

      Floating point embedding representation shaped by the embedding model

      • items number

API Schemas

The following schemas are based on JSON Schema

{
"type": "object",
"properties": {
"text": {
"oneOf": [
{
"type": "string",
"description": "The text to embed",
"minLength": 1
},
{
"type": "array",
"description": "Batch of text values to embed",
"items": {
"type": "string",
"description": "The text to embed",
"minLength": 1
},
"maxItems": 100
}
]
}
},
"required": [
"text"
]
}