fix(retrieval): bound automatic graph retrieval

This commit is contained in:
姚章浩
2026-09-10 16:24:56 +08:00
parent c64a48647c
commit e1092f84a4
11 changed files with 231 additions and 13 deletions
@@ -20,6 +20,16 @@ type PluginRerank struct {
modelService interfaces.ModelService // Service to access rerank models
}
func boundedRerankFallback(candidates []*types.SearchResult, topK int) []*types.SearchResult {
if topK <= 0 {
topK = 1
}
if len(candidates) > topK {
candidates = candidates[:topK]
}
return append([]*types.SearchResult(nil), candidates...)
}
// NewPluginRerank creates a new rerank plugin instance
func NewPluginRerank(eventManager *EventManager, modelService interfaces.ModelService) *PluginRerank {
res := &PluginRerank{
@@ -134,7 +144,7 @@ func (p *PluginRerank) OnEvent(ctx context.Context,
"error": rerankErr.Error(),
"candidate_cnt": len(candidatesToRerank),
})
chatManage.SearchResult = candidatesToRerank
chatManage.SearchResult = boundedRerankFallback(candidatesToRerank, chatManage.RerankTopK)
spanOutput = map[string]interface{}{
"stage": "api_error_fallback",
"candidate_count": len(candidatesToRerank),
@@ -166,7 +176,7 @@ func (p *PluginRerank) OnEvent(ctx context.Context,
"error": rerankErr.Error(),
"candidate_cnt": len(candidatesToRerank),
})
chatManage.SearchResult = candidatesToRerank
chatManage.SearchResult = boundedRerankFallback(candidatesToRerank, chatManage.RerankTopK)
spanOutput = map[string]interface{}{
"stage": "api_error_fallback",
"candidate_count": len(candidatesToRerank),