GetStats 获取统计信息
(ctx context.Context, namespace string)
| 181 | |
| 182 | // GetStats 获取统计信息 |
| 183 | func (s *InMemoryStore) GetStats(ctx context.Context, namespace string) (*MemoryStats, error) { |
| 184 | s.mu.RLock() |
| 185 | defer s.mu.RUnlock() |
| 186 | |
| 187 | if s.closed { |
| 188 | return nil, ErrStoreClosed |
| 189 | } |
| 190 | |
| 191 | stats := &MemoryStats{ |
| 192 | CountByType: make(map[string]int), |
| 193 | CountByScope: make(map[MemoryScope]int), |
| 194 | } |
| 195 | |
| 196 | var totalConfidence float64 |
| 197 | var lastUpdated time.Time |
| 198 | |
| 199 | for _, memory := range s.memories { |
| 200 | if namespace != "" && memory.Namespace != namespace { |
| 201 | continue |
| 202 | } |
| 203 | |
| 204 | stats.TotalCount++ |
| 205 | stats.CountByType[memory.Type]++ |
| 206 | stats.CountByScope[memory.Scope]++ |
| 207 | |
| 208 | if memory.Provenance != nil { |
| 209 | totalConfidence += memory.Provenance.Confidence |
| 210 | } |
| 211 | |
| 212 | if memory.UpdatedAt.After(lastUpdated) { |
| 213 | lastUpdated = memory.UpdatedAt |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | if stats.TotalCount > 0 { |
| 218 | stats.AverageConfidence = totalConfidence / float64(stats.TotalCount) |
| 219 | } |
| 220 | stats.LastUpdated = lastUpdated |
| 221 | |
| 222 | return stats, nil |
| 223 | } |
| 224 | |
| 225 | // Prune 清理低价值 Memory |
| 226 | func (s *InMemoryStore) Prune(ctx context.Context, criteria PruneCriteria) (int, error) { |
no outgoing calls