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

View File

@@ -35,6 +35,10 @@ const getFormSchema = (t: (key: string) => string) =>
embeddingModelUUID: z embeddingModelUUID: z
.string() .string()
.min(1, { message: t('knowledge.embeddingModelUUIDRequired') }), .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({ export default function KBForm({
@@ -55,6 +59,7 @@ export default function KBForm({
name: '', name: '',
description: t('knowledge.defaultDescription'), description: t('knowledge.defaultDescription'),
embeddingModelUUID: '', embeddingModelUUID: '',
top_k: 5,
}, },
}); });
@@ -69,6 +74,7 @@ export default function KBForm({
form.setValue('name', val.name); form.setValue('name', val.name);
form.setValue('description', val.description); form.setValue('description', val.description);
form.setValue('embeddingModelUUID', val.embeddingModelUUID); 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, name: res.base.name,
description: res.base.description, description: res.base.description,
embeddingModelUUID: res.base.embedding_model_uuid, embeddingModelUUID: res.base.embedding_model_uuid,
top_k: res.base.top_k || 5,
}); });
}); });
}); });
@@ -109,6 +116,7 @@ export default function KBForm({
name: data.name, name: data.name,
description: data.description, description: data.description,
embedding_model_uuid: data.embeddingModelUUID, embedding_model_uuid: data.embeddingModelUUID,
top_k: data.top_k,
}; };
httpClient httpClient
.updateKnowledgeBase(initKbId, updateKb) .updateKnowledgeBase(initKbId, updateKb)
@@ -127,6 +135,7 @@ export default function KBForm({
name: data.name, name: data.name,
description: data.description, description: data.description,
embedding_model_uuid: data.embeddingModelUUID, embedding_model_uuid: data.embeddingModelUUID,
top_k: data.top_k,
}; };
httpClient httpClient
.createKnowledgeBase(newKb) .createKnowledgeBase(newKb)
@@ -226,6 +235,26 @@ export default function KBForm({
</FormItem> </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> </div>
</form> </form>
</Form> </Form>

View File

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

View File

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

View File

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

View File

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

View File

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