Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
45628a02
authored
May 08, 2026
by
YeYuheng
Committed by
GitHub
May 08, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rerank config (#6892)
parent
2dcb754f
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
103 additions
and
17 deletions
+103
-17
packages/global/core/ai/model.schema.ts
+2
-1
packages/service/core/ai/rerank/index.ts
+11
-10
packages/service/test/core/ai/rerank/index.test.ts
+77
-0
packages/web/i18n/en/account.json
+1
-0
packages/web/i18n/zh-CN/account.json
+1
-0
packages/web/i18n/zh-Hant/account.json
+1
-0
pro
+1
-1
projects/app/src/pageComponents/account/model/AddModelBox.tsx
+9
-5
No files found.
packages/global/core/ai/model.schema.ts
View file @
45628a02
...
@@ -110,7 +110,8 @@ export type EmbeddingModelItemType = z.infer<typeof EmbeddingModelItemSchema>;
...
@@ -110,7 +110,8 @@ export type EmbeddingModelItemType = z.infer<typeof EmbeddingModelItemSchema>;
export
const
RerankModelItemSchema
=
PriceTypeSchema
.
extend
(
BaseModelItemSchema
.
shape
).
extend
({
export
const
RerankModelItemSchema
=
PriceTypeSchema
.
extend
(
BaseModelItemSchema
.
shape
).
extend
({
type
:
z
.
literal
(
ModelTypeEnum
.
rerank
),
type
:
z
.
literal
(
ModelTypeEnum
.
rerank
),
maxToken
:
z
.
number
().
optional
()
// max input token for rerank query + one document
maxToken
:
z
.
number
().
optional
(),
// max input token for rerank query + one document
defaultConfig
:
z
.
record
(
z
.
string
(),
z
.
any
()).
optional
()
// post request config
});
});
export
type
RerankModelItemType
=
z
.
infer
<
typeof
RerankModelItemSchema
>
;
export
type
RerankModelItemType
=
z
.
infer
<
typeof
RerankModelItemSchema
>
;
...
...
packages/service/core/ai/rerank/index.ts
View file @
45628a02
...
@@ -95,22 +95,21 @@ export async function reRankRecall({
...
@@ -95,22 +95,21 @@ export async function reRankRecall({
// 模型的请求 url,允许是内网
// 模型的请求 url,允许是内网
const
requestUrl
=
model
.
requestUrl
?
model
.
requestUrl
:
`
${
baseUrl
}
/rerank`
;
const
requestUrl
=
model
.
requestUrl
?
model
.
requestUrl
:
`
${
baseUrl
}
/rerank`
;
const
apiResult
=
await
axiosWithoutSSRF
const
requestBody
=
{
.
post
<
PostReRankResponse
>
(
requestUrl
,
{
model
:
model
.
model
,
model
:
model
.
model
,
query
,
query
,
documents
:
documentsTextArray
documents
:
documentsTextArray
,
},
...
model
.
defaultConfig
{
};
const
apiResult
=
await
axiosWithoutSSRF
.
post
<
PostReRankResponse
>
(
requestUrl
,
requestBody
,
{
headers
:
{
headers
:
{
Authorization
:
model
.
requestAuth
?
`Bearer
${
model
.
requestAuth
}
`
:
authorization
,
Authorization
:
model
.
requestAuth
?
`Bearer
${
model
.
requestAuth
}
`
:
authorization
,
...
headers
...
headers
},
},
timeout
:
30000
timeout
:
30000
}
})
)
.
then
((
res
)
=>
res
.
data
)
.
then
((
res
)
=>
res
.
data
)
.
then
(
async
(
data
)
=>
{
.
then
(
async
(
data
)
=>
{
if
(
!
data
?.
results
||
data
?.
results
?.
length
===
0
)
{
if
(
!
data
?.
results
||
data
?.
results
?.
length
===
0
)
{
...
@@ -126,13 +125,15 @@ export async function reRankRecall({
...
@@ -126,13 +125,15 @@ export async function reRankRecall({
logger
.
info
(
'Rerank completed'
,
{
durationMs
:
time
});
logger
.
info
(
'Rerank completed'
,
{
durationMs
:
time
});
}
}
const
providerResults
=
data
.
results
??
[];
const
existsId
=
new
Set
<
string
>
();
const
existsId
=
new
Set
<
string
>
();
const
results
:
{
const
results
:
{
id
:
string
;
id
:
string
;
score
:
number
;
score
:
number
;
}[]
=
[];
}[]
=
[];
data
.
r
esults
.
forEach
((
item
)
=>
{
providerR
esults
.
forEach
((
item
)
=>
{
const
chunkId
=
expandedDocuments
[
item
.
index
].
id
;
const
chunkId
=
expandedDocuments
[
item
.
index
].
id
;
const
docId
=
chunkIdToDocIdMap
.
get
(
chunkId
);
const
docId
=
chunkIdToDocIdMap
.
get
(
chunkId
);
// 因为 data.results 是从高到低的,如果高分的同一个docId,则低分的不用处理
// 因为 data.results 是从高到低的,如果高分的同一个docId,则低分的不用处理
...
...
packages/service/test/core/ai/rerank/index.test.ts
View file @
45628a02
...
@@ -264,6 +264,83 @@ describe('reRankRecall', () => {
...
@@ -264,6 +264,83 @@ describe('reRankRecall', () => {
expect
(
url
.
endsWith
(
'/rerank'
)).
toBe
(
true
);
expect
(
url
.
endsWith
(
'/rerank'
)).
toBe
(
true
);
});
});
it
(
'合并 defaultConfig 到请求体,透传 top_k 参数'
,
async
()
=>
{
mockAxiosPost
.
mockResolvedValueOnce
({
id
:
'r1'
,
results
:
[{
index
:
0
,
relevance_score
:
0.8
}],
meta
:
{
tokens
:
{
input_tokens
:
5
,
output_tokens
:
0
}
}
});
const
result
=
await
reRankRecall
({
model
:
{
...
mockModel
,
defaultConfig
:
{
top_k
:
1
}
},
query
:
'q'
,
documents
:
[
{
id
:
'doc1'
,
text
:
'hello'
},
{
id
:
'doc2'
,
text
:
'world'
}
]
});
expect
(
mockAxiosPost
).
toHaveBeenCalledWith
(
expect
.
any
(
String
),
expect
.
objectContaining
({
model
:
mockModel
.
model
,
query
:
'q'
,
documents
:
[
'hello'
,
'world'
],
top_k
:
1
}),
expect
.
any
(
Object
)
);
expect
(
result
.
results
).
toEqual
([{
id
:
'doc1'
,
score
:
0.8
}]);
});
it
(
'透传 topn,不在本地做截断'
,
async
()
=>
{
mockAxiosPost
.
mockResolvedValueOnce
({
id
:
'r1'
,
results
:
[
{
index
:
2
,
relevance_score
:
0.9
},
{
index
:
1
,
relevance_score
:
0.8
},
{
index
:
0
,
relevance_score
:
0.7
}
],
meta
:
{
tokens
:
{
input_tokens
:
5
,
output_tokens
:
0
}
}
});
const
result
=
await
reRankRecall
({
model
:
{
...
mockModel
,
defaultConfig
:
{
topn
:
1
}
},
query
:
'q'
,
documents
:
[
{
id
:
'doc1'
,
text
:
'hello'
},
{
id
:
'doc2'
,
text
:
'world'
},
{
id
:
'doc3'
,
text
:
'fastgpt'
}
]
});
expect
(
mockAxiosPost
).
toHaveBeenCalledWith
(
expect
.
any
(
String
),
expect
.
objectContaining
({
model
:
mockModel
.
model
,
query
:
'q'
,
documents
:
[
'hello'
,
'world'
,
'fastgpt'
],
topn
:
1
}),
expect
.
any
(
Object
)
);
expect
(
result
.
results
).
toEqual
([
{
id
:
'doc3'
,
score
:
0.9
},
{
id
:
'doc2'
,
score
:
0.8
},
{
id
:
'doc1'
,
score
:
0.7
}
]);
});
// ── 异常场景 ──────────────────────────────────────────────────────────────
// ── 异常场景 ──────────────────────────────────────────────────────────────
it
(
'model 为 undefined 时 reject'
,
async
()
=>
{
it
(
'model 为 undefined 时 reject'
,
async
()
=>
{
...
...
packages/web/i18n/en/account.json
View file @
45628a02
...
@@ -39,6 +39,7 @@
...
@@ -39,6 +39,7 @@
"model.defaultConfig_tip"
:
"Each request will carry this additional Body parameter."
,
"model.defaultConfig_tip"
:
"Each request will carry this additional Body parameter."
,
"model.default_config"
:
"Body extra fields"
,
"model.default_config"
:
"Body extra fields"
,
"model.default_config_tip"
:
"When initiating a conversation request, merge this configuration.
\n
For example:
\n\"\"\"\n
{
\n
\"
temperature
\"
: 1,
\n
\"
max_tokens
\"
: null
\n
}
\n\"\"\"
"
,
"model.default_config_tip"
:
"When initiating a conversation request, merge this configuration.
\n
For example:
\n\"\"\"\n
{
\n
\"
temperature
\"
: 1,
\n
\"
max_tokens
\"
: null
\n
}
\n\"\"\"
"
,
"model.rerank_default_config_tip"
:
"Merge this config when sending rerank requests.
\n
For example:
\n\"\"\"\n
{
\n
\"
topn
\"
: 5
\n
}
\n\"\"\"
"
,
"model.default_model"
:
"Default model"
,
"model.default_model"
:
"Default model"
,
"model.default_system_chat_prompt"
:
"Default prompt"
,
"model.default_system_chat_prompt"
:
"Default prompt"
,
"model.default_system_chat_prompt_tip"
:
"When the model talks, it will carry this default prompt word."
,
"model.default_system_chat_prompt_tip"
:
"When the model talks, it will carry this default prompt word."
,
...
...
packages/web/i18n/zh-CN/account.json
View file @
45628a02
...
@@ -39,6 +39,7 @@
...
@@ -39,6 +39,7 @@
"model.defaultConfig_tip"
:
"每次请求时候,都会携带该额外 Body 参数"
,
"model.defaultConfig_tip"
:
"每次请求时候,都会携带该额外 Body 参数"
,
"model.default_config"
:
"Body 额外字段"
,
"model.default_config"
:
"Body 额外字段"
,
"model.default_config_tip"
:
"发起对话请求时候,合并该配置。例如:
\n\"\"\"\n
{
\n
\"
temperature
\"
: 1,
\n
\"
max_tokens
\"
: null
\n
}
\n\"\"\"
"
,
"model.default_config_tip"
:
"发起对话请求时候,合并该配置。例如:
\n\"\"\"\n
{
\n
\"
temperature
\"
: 1,
\n
\"
max_tokens
\"
: null
\n
}
\n\"\"\"
"
,
"model.rerank_default_config_tip"
:
"发起重排请求时候,合并该配置。例如:
\n\"\"\"\n
{
\n
\"
topn
\"
: 5
\n
}
\n\"\"\"
"
,
"model.default_model"
:
"默认模型"
,
"model.default_model"
:
"默认模型"
,
"model.default_system_chat_prompt"
:
"默认提示词"
,
"model.default_system_chat_prompt"
:
"默认提示词"
,
"model.default_system_chat_prompt_tip"
:
"模型对话时,都会携带该默认提示词"
,
"model.default_system_chat_prompt_tip"
:
"模型对话时,都会携带该默认提示词"
,
...
...
packages/web/i18n/zh-Hant/account.json
View file @
45628a02
...
@@ -39,6 +39,7 @@
...
@@ -39,6 +39,7 @@
"model.defaultConfig_tip"
:
"每次請求時候,都會攜帶該額外 Body 參數"
,
"model.defaultConfig_tip"
:
"每次請求時候,都會攜帶該額外 Body 參數"
,
"model.default_config"
:
"Body 額外欄位"
,
"model.default_config"
:
"Body 額外欄位"
,
"model.default_config_tip"
:
"發起對話請求時候,合併該設定。例如:
\n\"\"\"\n
{
\n
\"
temperature
\"
: 1,
\n
\"
max_tokens
\"
: null
\n
}
\n\"\"\"
"
,
"model.default_config_tip"
:
"發起對話請求時候,合併該設定。例如:
\n\"\"\"\n
{
\n
\"
temperature
\"
: 1,
\n
\"
max_tokens
\"
: null
\n
}
\n\"\"\"
"
,
"model.rerank_default_config_tip"
:
"發起重排請求時候,合併該設定。例如:
\n\"\"\"\n
{
\n
\"
topn
\"
: 5
\n
}
\n\"\"\"
"
,
"model.default_model"
:
"預設模型"
,
"model.default_model"
:
"預設模型"
,
"model.default_system_chat_prompt"
:
"預設提示詞"
,
"model.default_system_chat_prompt"
:
"預設提示詞"
,
"model.default_system_chat_prompt_tip"
:
"模型對話時,都會攜帶該預設提示詞"
,
"model.default_system_chat_prompt_tip"
:
"模型對話時,都會攜帶該預設提示詞"
,
...
...
pro
@
ee1b1d77
Subproject commit
1dc6ead607f6b519226d79fcbc95dfe219e6606e
Subproject commit
ee1b1d779dfa90b36503d0693c97437fd9ba7b6a
projects/app/src/pageComponents/account/model/AddModelBox.tsx
View file @
45628a02
...
@@ -1149,17 +1149,21 @@ export const ModelEditModal = ({
...
@@ -1149,17 +1149,21 @@ export const ModelEditModal = ({
/>
/>
</
Field
>
</
Field
>
)
}
)
}
{
(
isLLMModel
||
isEmbeddingModel
)
&&
(
{
(
isLLMModel
||
isEmbeddingModel
||
isRerankModel
)
&&
(
<
DefaultConfigField
<
DefaultConfigField
control=
{
control
}
control=
{
control
}
setValue=
{
setValue
}
setValue=
{
setValue
}
label=
{
label=
{
isLLMModel
?
t
(
'account:model.default_config'
)
:
t
(
'account:model.defaultConfig'
)
isEmbeddingModel
?
t
(
'account:model.defaultConfig'
)
:
t
(
'account:model.default_config'
)
}
}
tip=
{
tip=
{
isLLMModel
isEmbeddingModel
?
t
(
'account:model.default_config_tip'
)
?
t
(
'account:model.defaultConfig_tip'
)
:
t
(
'account:model.defaultConfig_tip'
)
:
isRerankModel
?
t
(
'account:model.rerank_default_config_tip'
)
:
t
(
'account:model.default_config_tip'
)
}
}
/>
/>
)
}
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment