IndexWithProvenance 使用指定的 Provenance 索引文本。 derivedFromIDs 表示该记忆派生自哪些其他记忆。
(ctx context.Context, docID string, text string, meta map[string]any, provenance *MemoryProvenance, derivedFromIDs []string)
| 113 | // IndexWithProvenance 使用指定的 Provenance 索引文本。 |
| 114 | // derivedFromIDs 表示该记忆派生自哪些其他记忆。 |
| 115 | func (sm *SemanticMemory) IndexWithProvenance(ctx context.Context, docID string, text string, meta map[string]any, provenance *MemoryProvenance, derivedFromIDs []string) error { |
| 116 | if sm == nil || sm.cfg.Store == nil || sm.cfg.Embedder == nil { |
| 117 | return nil |
| 118 | } |
| 119 | if !sm.cfg.EnableProvenance { |
| 120 | return errors.New("provenance not enabled") |
| 121 | } |
| 122 | if provenance == nil { |
| 123 | return errors.New("provenance is required") |
| 124 | } |
| 125 | |
| 126 | // 追踪谱系 |
| 127 | if sm.cfg.LineageManager != nil { |
| 128 | err := sm.cfg.LineageManager.TrackMemoryCreation(docID, provenance, derivedFromIDs) |
| 129 | if err != nil { |
| 130 | return fmt.Errorf("track lineage: %w", err) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | return sm.indexInternal(ctx, docID, text, meta, provenance) |
| 135 | } |
| 136 | |
| 137 | // indexInternal 内部索引方法。 |
| 138 | func (sm *SemanticMemory) indexInternal(ctx context.Context, docID string, text string, meta map[string]any, provenance *MemoryProvenance) error { |
no test coverage detected