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:
@@ -559,14 +559,19 @@ func (t *KnowledgeSearchTool) concurrentSearchByTargets(
|
||||
innerWg.Add(1)
|
||||
go func() {
|
||||
defer innerWg.Done()
|
||||
stVectorThreshold, stKeywordThreshold := st.RecallThresholds(
|
||||
vectorThreshold,
|
||||
keywordThreshold,
|
||||
)
|
||||
searchParams := types.SearchParams{
|
||||
QueryText: q,
|
||||
QueryEmbedding: queryEmbedding,
|
||||
MatchCount: topK,
|
||||
VectorThreshold: vectorThreshold,
|
||||
KeywordThreshold: keywordThreshold,
|
||||
VectorThreshold: stVectorThreshold,
|
||||
KeywordThreshold: stKeywordThreshold,
|
||||
KnowledgeIDs: st.KnowledgeIDs,
|
||||
TagIDs: st.TagIDs,
|
||||
ScopeTagIDs: st.ScopeTagIDs,
|
||||
}
|
||||
kbResults, err := t.knowledgeBaseService.HybridSearch(ctx, st.KnowledgeBaseID, searchParams)
|
||||
if err != nil {
|
||||
@@ -837,7 +842,12 @@ Output only the scores, no explanations or additional text.`,
|
||||
return rankResults[i].RelevanceScore > rankResults[j].RelevanceScore
|
||||
})
|
||||
|
||||
ranked := t.applyModelRerankScores(results, rankResults, t.rerankThreshold())
|
||||
ranked := t.applyModelRerankScores(
|
||||
results,
|
||||
rankResults,
|
||||
t.rerankThreshold(),
|
||||
t.searchTargets.HasRecallThresholdOverride(),
|
||||
)
|
||||
logger.Infof(ctx, "[Tool][KnowledgeSearch] LLM reranked %d/%d results above threshold %.2f",
|
||||
len(ranked), len(results), t.rerankThreshold())
|
||||
return ranked, nil
|
||||
@@ -929,7 +939,12 @@ func (t *KnowledgeSearchTool) rerankWithModel(
|
||||
return nil, fmt.Errorf("rerank call failed: %w", err)
|
||||
}
|
||||
|
||||
ranked := t.applyModelRerankScores(results, rerankResp, t.rerankThreshold())
|
||||
ranked := t.applyModelRerankScores(
|
||||
results,
|
||||
rerankResp,
|
||||
t.rerankThreshold(),
|
||||
t.searchTargets.HasRecallThresholdOverride(),
|
||||
)
|
||||
logger.Infof(
|
||||
ctx,
|
||||
"[Tool][KnowledgeSearch] Reranked %d/%d results above threshold %.2f",
|
||||
@@ -949,7 +964,11 @@ func (t *KnowledgeSearchTool) rerankThreshold() float64 {
|
||||
|
||||
const agentRerankFallbackMinScore = 0.15
|
||||
|
||||
func filterRerankRankResults(rankResults []rerank.RankResult, threshold float64) []rerank.RankResult {
|
||||
func filterRerankRankResults(
|
||||
rankResults []rerank.RankResult,
|
||||
threshold float64,
|
||||
preserveTop bool,
|
||||
) []rerank.RankResult {
|
||||
if len(rankResults) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -966,7 +985,7 @@ func filterRerankRankResults(rankResults []rerank.RankResult, threshold float64)
|
||||
top = r
|
||||
}
|
||||
}
|
||||
if top.RelevanceScore >= agentRerankFallbackMinScore {
|
||||
if preserveTop || top.RelevanceScore >= agentRerankFallbackMinScore {
|
||||
return []rerank.RankResult{top}
|
||||
}
|
||||
}
|
||||
@@ -977,8 +996,9 @@ func (t *KnowledgeSearchTool) applyModelRerankScores(
|
||||
originals []*searchResultWithMeta,
|
||||
rankResults []rerank.RankResult,
|
||||
threshold float64,
|
||||
preserveTop bool,
|
||||
) []*searchResultWithMeta {
|
||||
filtered := filterRerankRankResults(rankResults, threshold)
|
||||
filtered := filterRerankRankResults(rankResults, threshold, preserveTop)
|
||||
out := make([]*searchResultWithMeta, 0, len(filtered))
|
||||
for _, rr := range filtered {
|
||||
if rr.Index < 0 || rr.Index >= len(originals) {
|
||||
|
||||
Reference in New Issue
Block a user