-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Reranking documentation #25867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: production
Are you sure you want to change the base?
Reranking documentation #25867
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
pcx_content_type: concept | ||
title: Reranking | ||
sidebar: | ||
order: 4 | ||
--- | ||
|
||
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. | ||
|
||
## How it works | ||
|
||
By default, reranking is **disabled** for all AI Search instances. You can enable it during creation or later from the settings page. | ||
|
||
When enabled, AI Search will: | ||
|
||
1. Retrieve a set of relevant results from your index, constrained by your `max_num_of_results` and `score_threshold` parameters. | ||
2. Pass those results through a [reranking model](/ai-search/configuration/models/supported-models/) | ||
3. Return the reranked results, which the text generation model can use for answer generation. | ||
|
||
Reranking helps improve accuracy, especially for large or noisy datasets where vector similarity alone may not produce the optimal ordering. | ||
|
||
## Configuration | ||
|
||
You can configure reranking in several ways: | ||
|
||
### Configure via API | ||
|
||
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: | ||
|
||
- Enable or disable reranking per request | ||
- Specify the reranking model | ||
|
||
For example: | ||
|
||
```javascript | ||
const answer = await env.AI.autorag("my-autorag").aiSearch({ | ||
query: "How do I train a llama to deliver coffee?", | ||
model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast", | ||
reranking: { | ||
enabled: true, | ||
model: "@cf/baai/bge-reranker-base" | ||
} | ||
}); | ||
``` | ||
|
||
### Configure in dashboard for new AI Search | ||
|
||
When creating a new RAG in the dashboard: | ||
|
||
1. In the Retrieval configuration step, open the Reranking dropdown | ||
2. Toggle Reranking on | ||
3. Select the reranking model | ||
|
||
### Configure in dashboard for existing AI Search | ||
|
||
To update reranking for an existing instance: | ||
|
||
1. Go to your AI Search instance | ||
2. Open the Settings tab | ||
3. Enable or disable reranking, and select the reranking model | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,9 @@ curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai-search/rags/{ | |
"rewrite_query": false, | ||
"max_num_results": 10, | ||
"ranking_options": { | ||
"score_threshold": 0.3 | ||
"score_threshold": 0.3, | ||
"enabled": true, | ||
"model": "@cf/baai/bge-reranker-base" | ||
Comment on lines
+56
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These attributes don't go in this object. They are exposed through a new object, |
||
}, | ||
"stream": true, | ||
}' | ||
|
@@ -89,7 +91,9 @@ curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai-search/rags/{ | |
"rewrite_query": true, | ||
"max_num_results": 10, | ||
"ranking_options": { | ||
"score_threshold": 0.3 | ||
"score_threshold": 0.3, | ||
"enabled": true | ||
"model": "@cf/baai/bge-reranker-base" | ||
Comment on lines
+95
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
}, | ||
}' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,8 @@ const answer = await env.AI.autorag("my-autorag").aiSearch({ | |
max_num_results: 2, | ||
ranking_options: { | ||
score_threshold: 0.3, | ||
enabled: true, | ||
model: "@cf/baai/bge-reranker-base" | ||
Comment on lines
+50
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
}, | ||
stream: true, | ||
}); | ||
|
@@ -116,6 +118,8 @@ const answer = await env.AI.autorag("my-autorag").search({ | |
max_num_results: 2, | ||
ranking_options: { | ||
score_threshold: 0.3, | ||
enabled: true, | ||
model: "@cf/baai/bge-reranker-base" | ||
Comment on lines
+121
to
+122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
}, | ||
}); | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,12 @@ Configurations for customizing result ranking. Defaults to `{}`. | |
- `score_threshold` <Type text="number" /> <MetaInfo text="optional" /> | ||
- The minimum match score required for a result to be considered a match. Defaults to `0`. Must be between `0` and `1`. | ||
|
||
- `enabled` <Type text="boolean" /> <MetaInfo text="optional" /> | ||
- Enables or disables reranking, which reorders retrieved results based on semantic relevance using a reranking model. Defaults to `false`. | ||
|
||
- `model` <Type text="string" /> <MetaInfo text="optional" /> | ||
- The reranking model to use when reranking is enabled. | ||
|
||
Comment on lines
+30
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, these should be placed under a new object called |
||
`stream` <Type text="boolean" /> <MetaInfo text="optional" /> | ||
|
||
Returns a stream of results as they are available. Defaults to `false`. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,12 @@ Configurations for customizing result ranking. Defaults to `{}`. | |
- `score_threshold` <Type text="number" /> <MetaInfo text="optional" /> | ||
- The minimum match score required for a result to be considered a match. Defaults to `0`. Must be between `0` and `1`. | ||
|
||
- `enabled` <Type text="boolean" /> <MetaInfo text="optional" /> | ||
- Enables or disables reranking, which reorders retrieved results based on semantic relevance using a reranking model. Defaults to `false`. | ||
|
||
- `model` <Type text="string" /> <MetaInfo text="optional" /> | ||
- The reranking model to use when reranking is enabled. | ||
|
||
Comment on lines
+26
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
`filters` <Type text="object" /> <MetaInfo text="optional" /> | ||
|
||
Narrow down search results based on metadata, like folder and date, so only relevant content is retrieved. For more details, refer to [Metadata filtering](/ai-search/configuration/metadata). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: it sounds a bit weird saying
also
here when this is the first example.