Skip to content

Commit 2566498

Browse files
committed
reranking documentation
1 parent db9b73f commit 2566498

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

src/content/docs/ai-search/configuration/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ The table below lists all available configuration options:
2222
| [Query rewrite system prompt](/ai-search/configuration/system-prompt/) | yes | Custom system prompt to guide query rewriting behavior |
2323
| [Match threshold](/ai-search/configuration/retrieval-configuration/) | yes | Minimum similarity score required for a vector match |
2424
| [Maximum number of results](/ai-search/configuration/retrieval-configuration/) | yes | Maximum number of vector matches returned (`top_k`) |
25+
| [Reranking](/ai-search/configuration/reranking/) | yes | Rerank to reorder retrieved results by semantic relevance using a reranking model after initial retrieval |
2526
| [Generation model](/ai-search/configuration/models/) | yes | Model used to generate the final response |
2627
| [Generation system prompt](/ai-search/configuration/system-prompt/) | yes | Custom system prompt to guide response generation |
2728
| [Similarity caching](/ai-search/configuration/cache/) | yes | Enable or disable caching of responses for similar (not just exact) prompts |

src/content/docs/ai-search/configuration/models/supported-models.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ Production models are the actively supported and recommended models that are sta
5050
| **Workers AI** | `@cf/baai/bge-m3` | 1,024 | 512 | cosine |
5151
| | `@cf/baai/bge-large-en-v1.5` | 1,024 | 512 | cosine |
5252

53+
### Reranking
54+
| Provider | Alias | Input tokens |
55+
|---|---|---|
56+
| **Workers AI** | `@cf/baai/bge-reranker-base` | 512 |
57+
5358
## Transition models
5459

5560
There are currently no models marked for end-of-life.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
pcx_content_type: concept
3+
title: Reranking
4+
sidebar:
5+
order: 4
6+
---
7+
8+
Reranking can help improve the quality of AI Search results by reordering retrieved documents based on semantic relevance to the user’s query. It applies a secondary model after retrieval to "rerank" the top results before they are outputted.
9+
10+
## How it works
11+
12+
By default, reranking is **disabled** for all AI Search instances. You can enable it during creation or later from the settings page.
13+
14+
When enabled, AI Search will:
15+
16+
1. Retrieve a set of relevant results from your index, constrained by your `max_num_of_results` and `score_threshold` parameters.
17+
2. Pass those results through a [reranking model](/ai-search/configuration/models/supported-models/)
18+
3. Return the reranked results, which the text generation model can use for answer generation.
19+
20+
Reranking helps improve accuracy, especially for large or noisy datasets where vector similarity alone may not produce the optimal ordering.
21+
22+
## Configuration
23+
24+
You can configure reranking in several ways:
25+
26+
### Configure via API
27+
28+
You can also configure via the API. When you make a `/search` or `/ai-search` request using the [Workers Binding](/ai-search/usage/workers-binding/) or [REST API](/ai-search/usage/rest-api/), you can:
29+
30+
- Enable or disable reranking per request
31+
- Specify the reranking model
32+
33+
For example:
34+
35+
```javascript
36+
const answer = await env.AI.autorag("my-autorag").aiSearch({
37+
query: "How do I train a llama to deliver coffee?",
38+
model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
39+
reranking: {
40+
enabled: true,
41+
model: "@cf/baai/bge-reranker-base"
42+
}
43+
});
44+
```
45+
46+
### Configure in dashboard for new AI Search
47+
48+
When creating a new RAG in the dashboard:
49+
50+
1. In the Retrieval configuration step, open the Reranking dropdown
51+
2. Toggle Reranking on
52+
3. Select the reranking model
53+
54+
### Configure in dashboard for existing AI Search
55+
56+
To update reranking for an existing instance:
57+
58+
1. Go to your AI Search instance
59+
2. Open the Settings tab
60+
3. Enable or disable reranking, and select the reranking model
61+

src/content/docs/ai-search/usage/rest-api.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai-search/rags/{
5252
"rewrite_query": false,
5353
"max_num_results": 10,
5454
"ranking_options": {
55-
"score_threshold": 0.3
55+
"score_threshold": 0.3,
56+
"enabled": true,
57+
"model": "@cf/baai/bge-reranker-base"
5658
},
5759
"stream": true,
5860
}'
@@ -89,7 +91,9 @@ curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai-search/rags/{
8991
"rewrite_query": true,
9092
"max_num_results": 10,
9193
"ranking_options": {
92-
"score_threshold": 0.3
94+
"score_threshold": 0.3,
95+
"enabled": true
96+
"model": "@cf/baai/bge-reranker-base"
9397
},
9498
}'
9599

src/content/docs/ai-search/usage/workers-binding.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const answer = await env.AI.autorag("my-autorag").aiSearch({
4747
max_num_results: 2,
4848
ranking_options: {
4949
score_threshold: 0.3,
50+
enabled: true,
51+
model: "@cf/baai/bge-reranker-base"
5052
},
5153
stream: true,
5254
});
@@ -116,6 +118,8 @@ const answer = await env.AI.autorag("my-autorag").search({
116118
max_num_results: 2,
117119
ranking_options: {
118120
score_threshold: 0.3,
121+
enabled: true,
122+
model: "@cf/baai/bge-reranker-base"
119123
},
120124
});
121125
```

0 commit comments

Comments
 (0)