{"record":{"id":"4d521d2000c1ac64","repo":"Tencent/WeKnora","slug":"kb-hybrid-search-failed-w","errorCode":null,"errorMessage":"KB hybrid search failed: %w","messagePattern":"KB hybrid search failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/message.go","lineNumber":642,"sourceCode":"\tcfg := s.getChatHistoryConfig(ctx)\n\tif cfg == nil {\n\t\treturn nil, nil // Chat history KB not configured, skip vector search\n\t}\n\n\t// Read global retrieval config for search parameters\n\trc := s.getRetrievalConfig(ctx)\n\n\t// Use KB HybridSearch with vector-only mode (keyword search is done separately on the messages table)\n\tsearchParams := types.SearchParams{\n\t\tQueryText:            params.Query,\n\t\tMatchCount:           rc.GetEffectiveEmbeddingTopK(),\n\t\tVectorThreshold:      rc.GetEffectiveVectorThreshold(),\n\t\tDisableKeywordsMatch: true, // We handle keyword search separately on the messages table\n\t}\n\n\tkbResults, err := s.kbService.HybridSearch(ctx, cfg.KnowledgeBaseID, searchParams)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"KB hybrid search failed: %w\", err)\n\t}\n\n\tif len(kbResults) == 0 {\n\t\treturn nil, nil\n\t}\n\n\t// Rerank results if a rerank model is configured\n\tkbResults = s.rerankResults(ctx, rc, params.Query, kbResults)\n\tif len(kbResults) == 0 {\n\t\treturn nil, nil\n\t}\n\n\t// Map KB search results back to messages via knowledge_id\n\tknowledgeIDs := make([]string, 0, len(kbResults))\n\tscoreByKnowledgeID := make(map[string]float64)\n\tfor _, r := range kbResults {\n\t\tknowledgeIDs = append(knowledgeIDs, r.KnowledgeID)\n\t\tscoreByKnowledgeID[r.KnowledgeID] = r.Score","sourceCodeStart":624,"sourceCodeEnd":660,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/message.go#L624-L660","documentation":"vectorSearchViaKB delegates the vector part of message search to the knowledge base service's HybridSearch. If that call fails, the whole KB-backed vector search fails with this wrapper. It indicates a problem inside the KB service (index unavailable, bad KB config, embedding provider failure), not in the message query itself.","triggerScenarios":"Calling SearchMessages with vector/KB search enabled when kbService.HybridSearch errors: knowledge base ID missing or deleted, embedding provider unreachable, vector index down, or invalid searchParams (bad threshold).","commonSituations":"KB not provisioned for the tenant (cfg.KnowledgeBaseID points at a removed KB); embedding API quota/key issues; vector DB outage; misconfigured effective vector threshold after settings change.","solutions":["Check the wrapped HybridSearch error to see whether it is config, embedding-provider, or index related.","Verify cfg.KnowledgeBaseID exists and is enabled for the tenant.","Confirm the embedding provider credentials/quotas and vector store health.","Add a fallback to pure keyword search on messages table when KB vector search fails."],"exampleFix":"// before\nkbResults, err := s.kbService.HybridSearch(ctx, cfg.KnowledgeBaseID, searchParams)\nif err != nil {\n    return nil, fmt.Errorf(\"KB hybrid search failed: %w\", err)\n}\n// after\nkbResults, err := s.kbService.HybridSearch(ctx, cfg.KnowledgeBaseID, searchParams)\nif err != nil {\n    logger.Warnf(ctx, \"KB hybrid search failed, falling back to keyword: %v\", err)\n    return s.keywordSearchFallback(ctx, params)\n}","handlingStrategy":"fallback","validationCode":"if cfg == nil || !cfg.Enabled || cfg.KnowledgeBaseID == \"\" {\n    // skip KB vector search, go straight to keyword search\n}","typeGuard":"func kbReady(cfg *types.ChatHistoryConfig) bool {\n    return cfg != nil && cfg.Enabled && cfg.KnowledgeBaseID != \"\"\n}","tryCatchPattern":"msgs, err := svc.SearchMessages(ctx, params)\nif err != nil && strings.Contains(err.Error(), \"KB hybrid search failed\") {\n    msgs, err = keywordOnlySearch(ctx, params) // graceful degradation\n}","preventionTips":["Verify KB provisioning and KnowledgeBaseID on tenant config before enabling vector search","Monitor embedding provider and vector store health","Set sane vector thresholds; validate config changes before rollout"],"tags":["knowledge-base","vector-search","search"],"backgroundTag":"kb-hybrid-search-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}