{"record":{"id":"637c6b365a515dda","repo":"Tencent/WeKnora","slug":"no-search-targets-available","errorCode":null,"errorMessage":"no search targets available","messagePattern":"no search targets available","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/knowledge_search.go","lineNumber":210,"sourceCode":"\t\tvar filteredTargets types.SearchTargets\n\t\tfor _, target := range t.searchTargets {\n\t\t\tif target == nil {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif userKBSet[target.KnowledgeBaseID] {\n\t\t\t\tfilteredTargets = append(filteredTargets, target)\n\t\t\t}\n\t\t}\n\t\tsearchTargets = filteredTargets\n\t}\n\n\t// Validate search targets\n\tif len(searchTargets) == 0 {\n\t\tlogger.Errorf(ctx, \"[Tool][KnowledgeSearch] No search targets available\")\n\t\treturn &types.ToolResult{\n\t\t\tSuccess: false,\n\t\t\tError:   \"no knowledge bases specified and no search targets configured\",\n\t\t}, fmt.Errorf(\"no search targets available\")\n\t}\n\n\tkbIDs := searchTargets.GetAllKnowledgeBaseIDs()\n\tlogger.Infof(ctx, \"[Tool][KnowledgeSearch] Using %d search targets across %d KBs\", len(searchTargets), len(kbIDs))\n\n\t// Parse query parameter\n\tqueries := input.Queries\n\n\t// Validate: query must be provided\n\tif len(queries) == 0 {\n\t\tlogger.Errorf(ctx, \"[Tool][KnowledgeSearch] No queries provided\")\n\t\treturn &types.ToolResult{\n\t\t\tSuccess: false,\n\t\t\tError:   \"queries parameter is required\",\n\t\t}, fmt.Errorf(\"no queries provided\")\n\t}\n\n\tlogger.Infof(ctx, \"[Tool][KnowledgeSearch] Queries: %v\", queries)","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/knowledge_search.go#L192-L228","documentation":"KnowledgeSearch.Execute resolves the effective set of search targets (explicit knowledge_base_ids or the configured defaults). If neither is available it aborts with this error. It means the tool has no knowledge bases to search against at all.","triggerScenarios":"Calling knowledge_search with no knowledge_base_ids input while the tool was constructed with an empty/unset searchTargets configuration.","commonSituations":"Deployment where knowledge-base targets were never configured for the agent/tenant; caller forgets to pass KB IDs on a tool instance that has no defaults; config file section for search targets missing.","solutions":["Pass an explicit non-empty knowledge_base_ids array in the tool input","Configure default search targets on the tool (t.searchTargets) at construction time","Verify tenant/agent config that populates search targets is loaded correctly"],"exampleFix":"// before\nExecute(ctx, map[string]any{\"queries\": []string{\"refund policy\"}}) // no KBs anywhere\n// after\nExecute(ctx, map[string]any{\"queries\": []string{\"refund policy\"}, \"knowledge_base_ids\": []string{\"kb-123\"}})","handlingStrategy":"validation","validationCode":"if len(input.KnowledgeBaseIDs) == 0 && !searchTargetsConfigured {\n    return errors.New(\"knowledge_search requires KB ids or configured search targets\")\n}","typeGuard":"func searchTargetsReady(t *KnowledgeSearchTool) bool {\n    return t != nil && t.searchTargets != nil && len(t.searchTargets.GetAllKnowledgeBaseIDs()) > 0\n}","tryCatchPattern":"res, err := tool.Execute(ctx, input)\nif err != nil && strings.Contains(err.Error(), \"no search targets available\") {\n    log.Printf(\"configure search targets or pass knowledge_base_ids\")\n    return res, nil\n}","preventionTips":["Configure default search targets at tool construction","Always pass explicit knowledge_base_ids in ephemeral setups","Validate tenant/agent config loads search-target definitions","Add a startup check that logs configured KB count"],"tags":["go","agent-tools","knowledge-search","configuration"],"backgroundTag":"no-search-targets-configured","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}