Skip to content
Cloudflare Docs
b

bge-m3

Text Embeddingsbaai
@cf/baai/bge-m3

Multi-Functionality, Multi-Linguality, and Multi-Granularity embeddings model.

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-m3",
{
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-m3",
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-m3 \
-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

  • query string min 1

    A query you wish to perform against the provided contexts. If no query is provided the model with respond with embeddings for contexts

  • contexts * array

    List of provided contexts. Note that the index in this array is important, as the response will refer to it.

    • items object

      • text string min 1

        One of the provided context content

Output

  • Query object

    • response array

      • items object

        • id integer

          Index of the context in the request

        • score number

          Score of the context under the index.

  • Embedding object

    • response array

      • items array

        • items number

API Schemas

The following schemas are based on JSON Schema

{
"type": "object",
"properties": {
"query": {
"type": "string",
"minLength": 1,
"description": "A query you wish to perform against the provided contexts. If no query is provided the model with respond with embeddings for contexts"
},
"contexts": {
"type": "array",
"items": {
"type": "object",
"properties": {
"text": {
"type": "string",
"minLength": 1,
"description": "One of the provided context content"
}
}
},
"description": "List of provided contexts. Note that the index in this array is important, as the response will refer to it."
}
},
"required": [
"contexts"
]
}