MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / deleteObservations

Method deleteObservations

examples/server/memory/kb.go:299–326  ·  view source on GitHub ↗

deleteObservations removes specific observations from entities.

(deletions []Observation)

Source from the content-addressed store, hash-verified

297
298// deleteObservations removes specific observations from entities.
299func (k knowledgeBase) deleteObservations(deletions []Observation) error {
300 graph, err := k.loadGraph()
301 if err != nil {
302 return err
303 }
304
305 for _, deletion := range deletions {
306 entityIndex := slices.IndexFunc(graph.Entities, func(e Entity) bool {
307 return e.Name == deletion.EntityName
308 })
309 if entityIndex == -1 {
310 continue
311 }
312
313 // Create a map for quick lookup
314 observationsToDelete := make(map[string]bool)
315 for _, observation := range deletion.Observations {
316 observationsToDelete[observation] = true
317 }
318
319 // Filter observations using slices.DeleteFunc
320 graph.Entities[entityIndex].Observations = slices.DeleteFunc(graph.Entities[entityIndex].Observations, func(observation string) bool {
321 return observationsToDelete[observation]
322 })
323 }
324
325 return k.saveGraph(graph)
326}
327
328// deleteRelations removes specific relations from the graph.
329func (k knowledgeBase) deleteRelations(relations []Relation) error {

Callers 2

DeleteObservationsMethod · 0.95

Calls 2

loadGraphMethod · 0.95
saveGraphMethod · 0.95

Tested by 1