Skip to content

Commit 8f45454

Browse files
committed
changelog and system prompt changes
1 parent 9ba1b42 commit 8f45454

File tree

8 files changed

+105
-17
lines changed

8 files changed

+105
-17
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: Reranking and API-based system prompt configuration in AI Search
3+
description: Improve result accuracy with reranking and dynamically control AI Search responses by setting system prompts in API requests.
4+
products:
5+
- ai-search
6+
date: 2025-10-28
7+
---
8+
9+
[AI Search](/ai-search/) now supports reranking for improved retrieval quality and allows you to set the system prompt directly in your API requests.
10+
11+
## Reranking for more relevant results
12+
13+
You can now enable [reranking](/ai-search/configuration/reranking/) to reorder retrieved documents based on their semantic relevance to the user’s query. Reranking helps improve accuracy, especially for large or noisy datasets where vector similarity alone may not produce the optimal ordering.
14+
15+
You can enable and configure reranking in the dashboard or directly in your API requests:
16+
17+
```javascript
18+
const answer = await env.AI.autorag("my-autorag").aiSearch({
19+
query: "How do I train a llama to deliver coffee?",
20+
model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
21+
reranking: {
22+
enabled: true,
23+
model: "@cf/baai/bge-reranker-base"
24+
}
25+
});
26+
```
27+
28+
## Set system prompts in API
29+
30+
Previously, [system prompts](/ai-search/configuration/system-prompt/) could only be configured in the dashboard. You can now define them directly in your API requests, giving you per-query control over behavior. For example:
31+
32+
```javascript
33+
// Dynamically set query and system prompt in AI Search
34+
async function getAnswer(query, tone) {
35+
const systemPrompt = `You are a ${tone} assistant.`;
36+
37+
const response = await env.AI.autorag("my-autorag").aiSearch({
38+
query: query,
39+
system_prompt: systemPrompt
40+
});
41+
42+
return response;
43+
}
44+
45+
// Example usage
46+
const query = "What is Cloudflare?";
47+
const tone = "friendly";
48+
49+
const answer = await getAnswer(query, tone);
50+
console.log(answer);
51+
```
52+
53+
Learn more about [Reranking](/ai-search/configuration/reranking/) and [System Prompt](/ai-search/configuration/system-prompt/) in AI Search.
54+

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ You can configure reranking in several ways:
2525

2626
### Configure via API
2727

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:
28+
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:
2929

3030
- Enable or disable reranking per request
3131
- Specify the reranking model

src/content/docs/ai-search/configuration/system-prompt.mdx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ System prompts are particularly useful for:
2121
- Applying domain-specific tone or terminology
2222
- Encouraging consistent, high-quality output
2323

24-
## How to set your system prompt
25-
26-
The system prompt for your AI Search can be set after it has been created by:
27-
28-
1. Navigating to the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/ai/autorag), and go to AI > AI Search
29-
2. Select your AI Search
30-
3. Go to Settings page and find the System prompt setting for either Query rewrite or Generation
24+
## System prompt configuration
3125

3226
### Default system prompt
3327

@@ -39,6 +33,27 @@ You can view the effective system prompt used for any AI Search's model call thr
3933
The default system prompt can change and evolve over time to improve performance and quality.
4034
:::
4135

36+
### Configure via API
37+
38+
When you make a `/ai-search` request using the [Workers Binding](/ai-search/usage/workers-binding/) or [REST API](/ai-search/usage/rest-api/), you can set the system prompt programmatically.
39+
40+
For example:
41+
42+
```javascript
43+
const answer = await env.AI.autorag("my-autorag").aiSearch({
44+
query: "How do I train a llama to deliver coffee?",
45+
model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
46+
system_prompt: "You are a helpful assistant."
47+
});
48+
```
49+
50+
### Configure via Dashboard
51+
The system prompt for your AI Search can be set after it has been created by:
52+
53+
1. Navigating to the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/ai/autorag), and go to AI > AI Search
54+
2. Select your AI Search
55+
3. Go to Settings page and find the System prompt setting for either Query rewrite or Generation
56+
4257
## Query rewriting system prompt
4358

4459
If query rewriting is enabled, you can provide a custom system prompt to control how the model rewrites user queries. In this step, the model receives:

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai-search/rags/{
5353
"max_num_results": 10,
5454
"ranking_options": {
5555
"score_threshold": 0.3,
56+
},
57+
"reranking": {
5658
"enabled": true,
57-
"model": "@cf/baai/bge-reranker-base"
59+
"model": "@cf/baai/bge-reranker-base"}
5860
},
5961
"stream": true,
6062
}'
@@ -92,10 +94,11 @@ curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai-search/rags/{
9294
"max_num_results": 10,
9395
"ranking_options": {
9496
"score_threshold": 0.3,
95-
"enabled": true
96-
"model": "@cf/baai/bge-reranker-base"
9797
},
98-
}'
98+
"reranking": {
99+
"enabled": true,
100+
"model": "@cf/baai/bge-reranker-base"}
101+
}'
99102

100103
```
101104

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ const answer = await env.AI.autorag("my-autorag").aiSearch({
4646
rewrite_query: true,
4747
max_num_results: 2,
4848
ranking_options: {
49-
score_threshold: 0.3,
49+
score_threshold: 0.3
50+
},
51+
reranking: {
5052
enabled: true,
5153
model: "@cf/baai/bge-reranker-base"
52-
},
54+
},
5355
stream: true,
5456
});
5557
```
@@ -117,10 +119,12 @@ const answer = await env.AI.autorag("my-autorag").search({
117119
rewrite_query: true,
118120
max_num_results: 2,
119121
ranking_options: {
120-
score_threshold: 0.3,
122+
score_threshold: 0.3
123+
},
124+
reranking: {
121125
enabled: true,
122126
model: "@cf/baai/bge-reranker-base"
123-
},
127+
}
124128
});
125129
```
126130

src/content/docs/r2/api/tokens.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ To create an API token:
2020
1. In the Cloudflare dashboard, go to the **R2 object storage** page.
2121

2222
<DashButton url="/?to=/:account/r2/overview" />
23-
2. Select **Manage API tokens**.
23+
2. Select **Manage in API tokens**.
2424
3. Choose to create either:
2525
- **Create Account API token** - These tokens are tied to the Cloudflare account itself and can be used by any authorized system or user. Only users with the Super Administrator role can view or create them. These tokens remain valid until manually revoked.
2626
- **Create User API token** - These tokens are tied to your individual Cloudflare user. They inherit your personal permissions and become inactive if your user is removed from the account.

src/content/partials/ai-search/ai-search-api-params.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ The input query.
1212

1313
The text-generation model that is used to generate the response for the query. For a list of valid options, check the AI Search Generation model Settings. Defaults to the generation model selected in the AI Search Settings.
1414

15+
`system_prompt` <Type text="string" /> <MetaInfo text="optional" />
16+
17+
The system prompt for generating the answer.
18+
1519
`rewrite_query` <Type text="boolean" /> <MetaInfo text="optional" />
1620

1721
Rewrites the original query into a search optimized query to improve retrieval accuracy. Defaults to `false`.
@@ -27,6 +31,10 @@ Configurations for customizing result ranking. Defaults to `{}`.
2731
- `score_threshold` <Type text="number" /> <MetaInfo text="optional" />
2832
- The minimum match score required for a result to be considered a match. Defaults to `0`. Must be between `0` and `1`.
2933

34+
`reranking` <Type text="object" /> <MetaInfo text="optional" />
35+
36+
Configurations for customizing reranking. Defaults to `{}`.
37+
3038
- `enabled` <Type text="boolean" /> <MetaInfo text="optional" />
3139
- Enables or disables reranking, which reorders retrieved results based on semantic relevance using a reranking model. Defaults to `false`.
3240

src/content/partials/ai-search/search-api-params.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Configurations for customizing result ranking. Defaults to `{}`.
2323
- `score_threshold` <Type text="number" /> <MetaInfo text="optional" />
2424
- The minimum match score required for a result to be considered a match. Defaults to `0`. Must be between `0` and `1`.
2525

26+
`reranking` <Type text="object" /> <MetaInfo text="optional" />
27+
28+
Configurations for customizing reranking. Defaults to `{}`.
29+
2630
- `enabled` <Type text="boolean" /> <MetaInfo text="optional" />
2731
- Enables or disables reranking, which reorders retrieved results based on semantic relevance using a reranking model. Defaults to `false`.
2832

0 commit comments

Comments
 (0)