Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
42 lines
911 B
Go
42 lines
911 B
Go
package metric
|
|
|
|
import (
|
|
"academy/internal/types"
|
|
)
|
|
|
|
// RecallMetric calculates recall for retrieval evaluation
|
|
type RecallMetric struct{}
|
|
|
|
// NewRecallMetric creates a new RecallMetric instance
|
|
func NewRecallMetric() *RecallMetric {
|
|
return &RecallMetric{}
|
|
}
|
|
|
|
// Compute calculates the recall score
|
|
func (r *RecallMetric) Compute(metricInput *types.MetricInput) float64 {
|
|
// Get ground truth and predicted IDs
|
|
gts := metricInput.RetrievalGT
|
|
ids := metricInput.RetrievalIDs
|
|
|
|
// Convert ground truth to sets for efficient lookup
|
|
gtSets := SliceMap(gts, ToSet)
|
|
if len(gtSets) == 0 {
|
|
return 0.0
|
|
}
|
|
|
|
if len(ids) == 0 {
|
|
return 0.0
|
|
}
|
|
|
|
var totalRecall float64
|
|
for _, gtSet := range gtSets {
|
|
hits := Hit(ids, gtSet)
|
|
if len(gtSet) > 0 {
|
|
totalRecall += float64(hits) / float64(len(gtSet))
|
|
}
|
|
}
|
|
|
|
// Recall = average recall across all ground truth sets
|
|
return totalRecall / float64(len(gtSets))
|
|
}
|