detectContradictions 检测矛盾信息
(memories []MemoryWithScore)
| 72 | |
| 73 | // detectContradictions 检测矛盾信息 |
| 74 | func (qa *QualityAnalyzer) detectContradictions(memories []MemoryWithScore) []Inconsistency { |
| 75 | inconsistencies := []Inconsistency{} |
| 76 | |
| 77 | // 简化版:检查内容中的否定关系 |
| 78 | for i := range memories { |
| 79 | for j := i + 1; j < len(memories); j++ { |
| 80 | if qa.areContradictory(memories[i], memories[j]) { |
| 81 | severity := qa.calculateContradictionSeverity(memories[i], memories[j]) |
| 82 | inconsistencies = append(inconsistencies, Inconsistency{ |
| 83 | Type: InconsistencyContradiction, |
| 84 | MemoryID1: memories[i].DocID, |
| 85 | MemoryID2: memories[j].DocID, |
| 86 | Description: fmt.Sprintf("记忆存在矛盾:'%s' vs '%s'", |
| 87 | truncate(memories[i].Text, 50), |
| 88 | truncate(memories[j].Text, 50)), |
| 89 | Severity: severity, |
| 90 | DetectedAt: time.Now(), |
| 91 | }) |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return inconsistencies |
| 97 | } |
| 98 | |
| 99 | // areContradictory 检查两个记忆是否矛盾 |
| 100 | func (qa *QualityAnalyzer) areContradictory(mem1, mem2 MemoryWithScore) bool { |