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

Method deleteEntities

examples/server/memory/kb.go:273–296  ·  view source on GitHub ↗

deleteEntities removes entities and their associated relations.

(entityNames []string)

Source from the content-addressed store, hash-verified

271
272// deleteEntities removes entities and their associated relations.
273func (k knowledgeBase) deleteEntities(entityNames []string) error {
274 graph, err := k.loadGraph()
275 if err != nil {
276 return err
277 }
278
279 // Create map for quick lookup
280 entitiesToDelete := make(map[string]bool)
281 for _, name := range entityNames {
282 entitiesToDelete[name] = true
283 }
284
285 // Filter entities using slices.DeleteFunc
286 graph.Entities = slices.DeleteFunc(graph.Entities, func(entity Entity) bool {
287 return entitiesToDelete[entity.Name]
288 })
289
290 // Filter relations using slices.DeleteFunc
291 graph.Relations = slices.DeleteFunc(graph.Relations, func(relation Relation) bool {
292 return entitiesToDelete[relation.From] || entitiesToDelete[relation.To]
293 })
294
295 return k.saveGraph(graph)
296}
297
298// deleteObservations removes specific observations from entities.
299func (k knowledgeBase) deleteObservations(deletions []Observation) error {

Callers 2

DeleteEntitiesMethod · 0.95

Calls 2

loadGraphMethod · 0.95
saveGraphMethod · 0.95

Tested by 1