Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

feat(agent): prefill default rerank model on agent creation

MidoriKurage1431e9414e9b
diff --git a/frontend/src/utils/modelDefaults.ts b/frontend/src/utils/modelDefaults.ts
new file mode 100644
index 000000000..203c0fbaa
--- /dev/null
+++ b/frontend/src/utils/modelDefaults.ts
@@ -0,0 +1,22 @@
+export interface ModelDefaultCandidate {
+ id?: string
+ type: string
+ status?: string
+ is_default?: boolean
+}
+
+/**
+ * Pick a creation-time model: prefer the declared default, fall back to the
+ * first active model.
+ */
+export function selectInitialModelId(
+ models: readonly ModelDefaultCandidate[],
+ modelType: string,
+): string | null {
+ const active = models.filter(
+ model => Boolean(model.id?.trim())
+ && model.type === modelType
+ && (!model.status || model.status === 'active'),
+ )
+ return active.find(model => model.is_default)?.id?.trim() ?? active[0]?.id?.trim() ?? null
+}
diff --git a/frontend/src/views/agent/AgentEditorModal.vue b/frontend/src/views/agent/AgentEditorModal.vue
index 2561e9c89..c16671392 100644
--- a/frontend/src/views/agent/AgentEditorModal.vue
+++ b/frontend/src/views/agent/AgentEditorModal.vue
@@ -1648,6 +1648,7 @@ import {
markContextualGuideDone,
} from '@/config/contextualGuides';
import { useI18n } from 'vue-i18n';
+import { selectInitialModelId } from '@/utils/modelDefaults';
import { MessagePlugin } from 'tdesign-vue-next';
import {
createAgent,
@@ -2417,13 +2418,15 @@ const removeStarterSuggestion = (index: number) => {
formData.value.config.question_suggestions.starters.items.splice(index, 1);
};
-const applyDefaultChatModelIfEmpty = () => {
+const applyDefaultModelsIfEmpty = () => {
if (props.mode !== 'create' || !formData.value) return
- const chat =
- allModels.value.find((m) => m.type === 'KnowledgeQA' && m.is_default)
- || allModels.value.find((m) => m.type === 'KnowledgeQA')
- if (!formData.value.config.model_id && chat?.id) {
- formData.value.config.model_id = chat.id
+ const chatModelId = selectInitialModelId(allModels.value, 'KnowledgeQA')
+ const rerankModelId = selectInitialModelId(allModels.value, 'Rerank')
+ if (!formData.value.config.model_id && chatModelId) {
+ formData.value.config.model_id = chatModelId
+ }
+ if (!formData.value.config.rerank_model_id && rerankModelId) {
+ formData.value.config.rerank_model_id = rerankModelId
}
}
@@ -3043,7 +3046,7 @@ watch(() => props.visible, async (val) => {
formData.value.description = getPresetDefaultDescription(preset);
}
}
- applyDefaultChatModelIfEmpty()
+ applyDefaultModelsIfEmpty()
}
if (props.initialHighlightField) {
diff --git a/frontend/src/views/knowledge/KnowledgeBaseEditorModal.vue b/frontend/src/views/knowledge/KnowledgeBaseEditorModal.vue
index 825609c55..ef976d847 100644
--- a/frontend/src/views/knowledge/KnowledgeBaseEditorModal.vue
+++ b/frontend/src/views/knowledge/KnowledgeBaseEditorModal.vue
@@ -468,8 +468,8 @@ import { KB_EDITOR_FOCUS_SECTION_EVENT, markContextualGuideDone } from '@/config
import { MessagePlugin, DialogPlugin } from 'tdesign-vue-next'
import { createKnowledgeBase, getKnowledgeBaseById, listKnowledgeFiles, updateKnowledgeBase, rebuildKBIndex } from '@/api/knowledge-base'
import { updateKBConfig, type KBModelConfigRequest } from '@/api/initialization'
-import { type ModelConfig } from '@/api/model'
import { useChatResourcesStore } from '@/stores/chatResources'
+import { selectInitialModelId } from '@/utils/modelDefaults'
import { useEditorResourcesStore } from '@/stores/editorResources'
import { useUIStore } from '@/stores/ui'
import { useAuthStore } from '@/stores/auth'
@@ -699,17 +699,13 @@ const kbCreateNeedsEmbedding = computed(() => {
const applyDefaultModelsIfEmpty = () => {
if (!formData.value || editorMode.value !== 'create') return
- const pick = (type: ModelConfig['type']) => {
- const list = allModels.value.filter((m) => m.type === type)
- return list.find((m) => m.is_default) || list[0]
+ const chatModelId = selectInitialModelId(allModels.value, 'KnowledgeQA')
+ const embeddingModelId = selectInitialModelId(allModels.value, 'Embedding')
+ if (!formData.value.modelConfig.llmModelId && chatModelId) {
+ formData.value.modelConfig.llmModelId = chatModelId
}
- const chat = pick('KnowledgeQA')
- const embedding = pick('Embedding')
- if (!formData.value.modelConfig.llmModelId && chat?.id) {
- formData.value.modelConfig.llmModelId = chat.id
- }
- if (!formData.value.modelConfig.embeddingModelId && embedding?.id) {
- formData.value.modelConfig.embeddingModelId = embedding.id
+ if (!formData.value.modelConfig.embeddingModelId && embeddingModelId) {
+ formData.value.modelConfig.embeddingModelId = embeddingModelId
}
}