后端: 1. 阶段 1.5/1.6 收口 llm-service / rag-service,统一模型出口与检索基础设施入口,清退 backend/infra/llm 与 backend/infra/rag 旧实现; 2. 同步更新相关调用链与微服务迁移计划文档
31 lines
713 B
Go
31 lines
713 B
Go
package rerank
|
|
|
|
import (
|
|
"context"
|
|
"sort"
|
|
|
|
"github.com/LoveLosita/smartflow/backend/services/rag/core"
|
|
)
|
|
|
|
// NoopReranker 是默认重排器(仅按原 score 排序)。
|
|
type NoopReranker struct{}
|
|
|
|
func NewNoopReranker() *NoopReranker {
|
|
return &NoopReranker{}
|
|
}
|
|
|
|
func (r *NoopReranker) Rerank(_ context.Context, _ string, candidates []core.ScoredChunk, topK int) ([]core.ScoredChunk, error) {
|
|
if len(candidates) == 0 {
|
|
return nil, nil
|
|
}
|
|
sorted := make([]core.ScoredChunk, len(candidates))
|
|
copy(sorted, candidates)
|
|
sort.SliceStable(sorted, func(i, j int) bool {
|
|
return sorted[i].Score > sorted[j].Score
|
|
})
|
|
if topK <= 0 || topK >= len(sorted) {
|
|
return sorted, nil
|
|
}
|
|
return sorted[:topK], nil
|
|
}
|