b
bge-reranker-base
Text Classification • baaiDifferent from embedding model, reranker uses question and document as input and directly output similarity instead of embedding. You can get a relevance score by inputting query and passage to the reranker. And the score can be mapped to a float value in [0,1] by sigmoid function.
Usage
Workers - TypeScript
export interface Env { AI: Ai;}
export default { async fetch(request, env): Promise<Response> {
const response = await env.AI.run( "@cf/baai/bge-reranker-base", { text: "This pizza is great!", } );
return Response.json(response); },} satisfies ExportedHandler<Env>;
Python
API_BASE_URL = "https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/run/"headers = {"Authorization": "Bearer {API_KEY}"}
def run(model, input): response = requests.post(f"{API_BASE_URL}{model}", headers=headers, json=input) return response.json()
output = run("@cf/baai/bge-reranker-base", { "text": "This pizza is great!" })print(output)
curl
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/@cf/baai/bge-reranker-base \ -X POST \ -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ -d '{ "text": "This pizza is great!" }'
Parameters
* indicates a required field
Input
-
query *
string min 1A query you wish to perform against the provided contexts.
-
top_k
integer min 1Number of returned results starting with the best score.
-
contexts *
arrayList of provided contexts. Note that the index in this array is important, as the response will refer to it.
-
items
object-
text
string min 1One of the provided context content
-
-
Output
-
response
array-
items
object-
id
integerIndex of the context in the request
-
score
numberScore of the context under the index.
-
-
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." }, "top_k": { "type": "integer", "default": null, "minimum": 1, "description": "Number of returned results starting with the best score." }, "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": [ "query", "contexts" ]}
{ "type": "object", "contentType": "application/json", "properties": { "response": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "integer", "description": "Index of the context in the request" }, "score": { "type": "number", "description": "Score of the context under the index." } } } } }}
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark