{"record":{"id":"a092b9ae9e0380ca","repo":"Tencent/WeKnora","slug":"rerank-model-is-not-configured-please-set-rerank","errorCode":null,"errorMessage":"rerank model is not configured: please set rerank_model_id on the agent","messagePattern":"rerank model is not configured: please set rerank_model_id on the agent","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/session_agent_qa.go","lineNumber":111,"sourceCode":"\n\t// Get rerank model from custom agent config only when knowledge_search can\n\t// actually run. A disabled KB scope makes all KB tools ineffective, so it\n\t// must not force users to configure an otherwise-unused rerank model.\n\tvar rerankModel rerank.Reranker\n\tif agentRequiresRerankModel(req.CustomAgent) {\n\t\t// Rerank model is resolved purely from the agent config now.\n\t\t// We used to fall back to ConversationConfig.RerankModelID at\n\t\t// the tenant level, but that path encouraged \"leave rerank\n\t\t// blank on the agent and inherit silently\" which made debugging\n\t\t// retrieval quality a guessing game across tenant settings vs\n\t\t// agent settings. Forcing the agent to declare its own rerank\n\t\t// model puts the configuration where the user actually edits\n\t\t// the agent. If a Wiki-only agent doesn't need reranking,\n\t\t// agentRequiresRerankModel() below already lets it pass.\n\t\trerankModelID := req.CustomAgent.Config.RerankModelID\n\t\tif rerankModelID == \"\" {\n\t\t\tlogger.Warnf(ctx, \"No rerank model configured for custom agent %s, but knowledge_search tool is enabled\", req.CustomAgent.ID)\n\t\t\treturn errors.New(\"rerank model is not configured: please set rerank_model_id on the agent\")\n\t\t}\n\n\t\trerankModel, err = s.modelService.GetRerankModel(ctx, rerankModelID)\n\t\tif err != nil {\n\t\t\tlogger.Warnf(ctx, \"Failed to get rerank model: %v\", err)\n\t\t\treturn fmt.Errorf(\"failed to get rerank model: %w\", err)\n\t\t}\n\t} else {\n\t\tlogger.Infof(ctx, \"knowledge_search is unavailable for the effective agent scope, skipping rerank model initialization\")\n\t}\n\n\t// Load multi-turn history directly from DB (the single source of truth).\n\t// AgentSteps on each historical assistant message are expanded into proper\n\t// assistant_with_tool_calls + tool messages so the model can see what was\n\t// tried last turn — except final_answer, which is replayed as the trailing\n\t// canonical assistant message.\n\tvar llmContext []chat.Message\n\tif agentConfig.MultiTurnEnabled {","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/session_agent_qa.go#L93-L129","documentation":"When the agent has the knowledge_search tool enabled, AgentQA requires a rerank model. It reads req.CustomAgent.Config.RerankModelID; if the agent needs reranking (agentRequiresRerankModel) and the field is empty, this error is returned before retrieval. Wiki-only agents that don't need reranking are exempt.","triggerScenarios":"Calling AgentQA with a CustomAgent that enables the knowledge_search tool but leaves Config.RerankModelID empty.","commonSituations":"Agents enabled for knowledge search after creation without adding a rerank model, cloned agents whose rerank_model_id was not copied, or rerank model removed from the registry while the field was cleared.","solutions":["Set rerank_model_id on the agent's config to a valid rerank model ID.","Alternatively disable the knowledge_search tool if reranking is not needed.","Validate via modelService.GetRerankModel that the configured rerank model exists."],"exampleFix":"// before\ncfg := &types.AgentConfig{Tools: []string{\"knowledge_search\"}} // no RerankModelID\n// after\ncfg := &types.AgentConfig{Tools: []string{\"knowledge_search\"}, RerankModelID: \"bge-reranker-v2-m3\"}","handlingStrategy":"validation","validationCode":"if slices.Contains(agent.Config.Tools, \"knowledge_search\") && agent.Config.RerankModelID == \"\" {\n    return fmt.Errorf(\"agent %s enables knowledge_search but has no rerank_model_id\", agent.ID)\n}","typeGuard":"func needsRerankModel(a *types.CustomAgent) bool {\n    return slices.Contains(a.Config.Tools, \"knowledge_search\") && a.Config.RerankModelID == \"\"\n}","tryCatchPattern":null,"preventionTips":["Enforce rerank_model_id when knowledge_search is enabled, at save time.","Verify the rerank model exists via GetRerankModel after cloning/importing agents.","Disable knowledge_search instead of leaving rerank unconfigured."],"tags":["configuration","rerank","agent","go"],"backgroundTag":"missing-required-config","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}