Pular para o conteúdo
BAAI logo

bge-reranker-base

Text Classification • BAAI

Ver como Markdown
  • Cloudflare-hosted

Different 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.

Model Info
Unit Pricing$0.0031 per M input tokens

Usage


export interface Env {
	AI: Ai;
}

export default {
	async fetch(request, env): Promise<Response> {
		const query = 'Which one is cooler?'
		const contexts = [
			{
				text: 'a cyberpunk lizzard'
			},
			{
				text: 'a cyberpunk cat'
			}
		];

		const response = await env.AI.run('@cf/baai/bge-reranker-base', { query, contexts });

		return Response.json(response);
	},
} satisfies ExportedHandler<Env>;

import os
import requests

ACCOUNT_ID = "your-account-id"
AUTH_TOKEN = os.environ.get("CLOUDFLARE_AUTH_TOKEN")

response = requests.post(
  f"https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/run/@cf/baai/bge-reranker-base",
    headers={"Authorization": f"Bearer {AUTH_TOKEN}"},
    json={
	  "query": "Which one is better?",
      "contexts": [
        {"text": "a cyberpunk lizzard"},
		    {"text": "a cyberpunk car"},
      ]
    }
)
result = response.json()
print(result)

curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/@cf/baai/bge-reranker-base \
  -X POST \
  -H "Authorization: Bearer $CLOUDFLARE_AUTH_TOKEN" \
  -d '{ "query": "Which one is better?", "contexts": [{ "text": "a cyberpunk lizzard" }, {"text": "a cyberpunk cat"}]}'

Parameters

query
stringrequiredminLength: 1A query you wish to perform against the provided contexts.
top_k
integerminimum: 1Number of returned results starting with the best score.

API Schemas (Raw)

Input
Output