fix(retrieval): bound automatic graph retrieval
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user