feat: add topk

This commit is contained in:
WangCham
2025-07-16 17:20:13 +08:00
parent 87f626f3cc
commit 246eb71b75
7 changed files with 37 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ export interface IKnowledgeBaseVO {
name: string;
description: string;
embeddingModelUUID: string;
top_k: number;
lastUpdatedTimeAgo: string;
}
@@ -11,6 +12,7 @@ export class KnowledgeBaseVO implements IKnowledgeBaseVO {
name: string;
description: string;
embeddingModelUUID: string;
top_k: number;
lastUpdatedTimeAgo: string;
constructor(props: IKnowledgeBaseVO) {
@@ -18,6 +20,7 @@ export class KnowledgeBaseVO implements IKnowledgeBaseVO {
this.name = props.name;
this.description = props.description;
this.embeddingModelUUID = props.embeddingModelUUID;
this.top_k = props.top_k;
this.lastUpdatedTimeAgo = props.lastUpdatedTimeAgo;
}
}

View File

@@ -35,6 +35,10 @@ const getFormSchema = (t: (key: string) => string) =>
embeddingModelUUID: z
.string()
.min(1, { message: t('knowledge.embeddingModelUUIDRequired') }),
top_k: z
.number()
.min(1, { message: t('knowledge.topKRequired') })
.max(30, { message: t('knowledge.topKMax') }),
});
export default function KBForm({
@@ -55,6 +59,7 @@ export default function KBForm({
name: '',
description: t('knowledge.defaultDescription'),
embeddingModelUUID: '',
top_k: 5,
},
});
@@ -69,6 +74,7 @@ export default function KBForm({
form.setValue('name', val.name);
form.setValue('description', val.description);
form.setValue('embeddingModelUUID', val.embeddingModelUUID);
form.setValue('top_k', val.top_k || 5);
});
}
});
@@ -83,6 +89,7 @@ export default function KBForm({
name: res.base.name,
description: res.base.description,
embeddingModelUUID: res.base.embedding_model_uuid,
top_k: res.base.top_k || 5,
});
});
});
@@ -109,6 +116,7 @@ export default function KBForm({
name: data.name,
description: data.description,
embedding_model_uuid: data.embeddingModelUUID,
top_k: data.top_k,
};
httpClient
.updateKnowledgeBase(initKbId, updateKb)
@@ -127,6 +135,7 @@ export default function KBForm({
name: data.name,
description: data.description,
embedding_model_uuid: data.embeddingModelUUID,
top_k: data.top_k,
};
httpClient
.createKnowledgeBase(newKb)
@@ -226,6 +235,26 @@ export default function KBForm({
</FormItem>
)}
/>
<FormField
control={form.control}
name="top_k"
render={({ field }) => (
<FormItem>
<FormLabel>
{t('knowledge.topK')}
<span className="text-red-500">*</span>
</FormLabel>
<FormControl>
<Input
type="number"
{...field}
onChange={(e) => field.onChange(Number(e.target.value))}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
</form>
</Form>

View File

@@ -46,6 +46,7 @@ export default function KnowledgePage() {
name: kb.name,
description: kb.description,
embeddingModelUUID: kb.embedding_model_uuid,
top_k: kb.top_k,
lastUpdatedTimeAgo: lastUpdatedTimeAgoText,
});
}),

View File

@@ -155,6 +155,7 @@ export interface KnowledgeBase {
name: string;
description: string;
embedding_model_uuid: string;
top_k: number;
created_at?: string;
updated_at?: string;
}

View File

@@ -252,6 +252,7 @@ const enUS = {
today: 'Today',
kbName: 'Knowledge Base Name',
kbDescription: 'Knowledge Base Description',
topK: 'Top K',
defaultDescription: 'A knowledge base',
embeddingModelUUID: 'Embedding Model',
selectEmbeddingModel: 'Select Embedding Model',

View File

@@ -254,6 +254,7 @@ const jaJP = {
today: '今日',
kbName: '知識ベース名',
kbDescription: '知識ベースの説明',
topK: '上位K件',
defaultDescription: '知識ベース',
embeddingModelUUID: '埋め込みモデル',
selectEmbeddingModel: '埋め込みモデルを選択',

View File

@@ -247,6 +247,7 @@ const zhHans = {
today: '今天',
kbName: '知识库名称',
kbDescription: '知识库描述',
topK: '召回数量',
defaultDescription: '一个知识库',
embeddingModelUUID: '嵌入模型',
selectEmbeddingModel: '选择嵌入模型',