feat(agent): enhance suggested questions API with tag scopes

Update the SuggestedQuestionsRequest to include TagScopes for better filtering of knowledge items based on their parent knowledge bases. Modify related API documentation and frontend interfaces to accommodate the new structure. Ensure backend services handle the new tag scope logic correctly, including tests for the updated functionality.
This commit is contained in:
wizardchen
2026-07-17 10:16:58 +08:00
committed by lyingbug
parent c21c34b3c0
commit eedd7d4641
34 changed files with 1041 additions and 338 deletions
@@ -158,8 +158,11 @@ func (s *sessionService) KnowledgeQA(
// rewrite, fallback, FAQ strategy, history turns)
s.applyAgentOverridesToChatManage(ctx, req.CustomAgent, chatManage)
// Determine pipeline based on knowledge bases availability and web search setting
hasKB := len(knowledgeBaseIDs) > 0 || len(knowledgeIDs) > 0
// Determine pipeline based on the effective knowledge retrieval scope and
// web search setting. Tag-only mentions leave the raw KB/knowledge ID slices
// empty but produce SearchTargets, so the unified targets must participate in
// this decision or the request is incorrectly downgraded to pure chat.
hasKB := types.HasKnowledgeRetrievalScope(searchTargets, knowledgeBaseIDs, knowledgeIDs)
needsRAG := hasKB || req.WebSearchEnabled
hasHistory := chatManage.MaxRounds > 0
@@ -541,10 +544,11 @@ func (s *sessionService) buildSearchTargets(
kbTenant = tenantID // fallback
}
targets = append(targets, &types.SearchTarget{
Type: types.SearchTargetTypeKnowledge,
KnowledgeBaseID: kbID,
TenantID: kbTenant,
KnowledgeIDs: kidList,
Type: types.SearchTargetTypeKnowledge,
KnowledgeBaseID: kbID,
TenantID: kbTenant,
KnowledgeIDs: kidList,
DisableRecallThresholds: true,
})
}
}
@@ -574,25 +578,28 @@ func (s *sessionService) buildSearchTargets(
continue
}
targets = append(targets, &types.SearchTarget{
Type: types.SearchTargetTypeKnowledge,
KnowledgeBaseID: kbID,
TenantID: kbTenant,
KnowledgeIDs: tagKnowledgeIDs,
DisableDirectLoad: true,
Type: types.SearchTargetTypeKnowledge,
KnowledgeBaseID: kbID,
TenantID: kbTenant,
KnowledgeIDs: tagKnowledgeIDs,
ScopeTagIDs: append([]string(nil), tagIDs...),
DisableRecallThresholds: true,
})
continue
}
target := &types.SearchTarget{
Type: types.SearchTargetTypeKnowledgeBase,
KnowledgeBaseID: kbID,
TenantID: kbTenant,
TagIDs: append([]string(nil), tagIDs...),
Type: types.SearchTargetTypeKnowledgeBase,
KnowledgeBaseID: kbID,
TenantID: kbTenant,
TagIDs: append([]string(nil), tagIDs...),
ScopeTagIDs: append([]string(nil), tagIDs...),
DisableRecallThresholds: true,
}
if len(explicitKnowledgeIDs) > 0 {
target.Type = types.SearchTargetTypeKnowledge
target.KnowledgeIDs = explicitKnowledgeIDs
target.DisableDirectLoad = true
target.DisableRecallThresholds = true
}
targets = append(targets, target)
}