Delete 删除知识项
(ctx context.Context, id string)
| 410 | |
| 411 | // Delete 删除知识项 |
| 412 | func (m *manager) Delete(ctx context.Context, id string) error { |
| 413 | m.mu.Lock() |
| 414 | defer m.mu.Unlock() |
| 415 | |
| 416 | // 获取项目信息用于审计 |
| 417 | item, err := m.getItemFromMemory(ctx, id) |
| 418 | if err != nil { |
| 419 | return fmt.Errorf("knowledge: item not found: %w", err) |
| 420 | } |
| 421 | |
| 422 | // 从内存删除 |
| 423 | if err := m.removeItemFromMemory(ctx, id); err != nil { |
| 424 | return fmt.Errorf("knowledge: failed to remove item from memory: %w", err) |
| 425 | } |
| 426 | |
| 427 | // 从向量存储删除 |
| 428 | if err := m.vectorStore.Delete(ctx, []string{id}); err != nil { |
| 429 | // 记录警告但不失败 |
| 430 | fmt.Printf("knowledge: warning - failed to remove embedding for item %s: %v\n", id, err) |
| 431 | } |
| 432 | |
| 433 | // 清理缓存 |
| 434 | if m.config.CacheEnabled { |
| 435 | delete(m.cache, id) |
| 436 | } |
| 437 | |
| 438 | // 更新统计 |
| 439 | m.updateStats(item.Namespace) |
| 440 | |
| 441 | // 记录审计 |
| 442 | if m.config.EnableAudit { |
| 443 | m.audit("delete", "", id, "Deleted knowledge item: "+item.Title) |
| 444 | } |
| 445 | |
| 446 | return nil |
| 447 | } |
| 448 | |
| 449 | // Search 搜索知识 |
| 450 | func (m *manager) Search(ctx context.Context, query *SearchQuery) ([]*SearchResult, error) { |
nothing calls this directly
no test coverage detected