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

Method deleteRelations

examples/server/memory/kb.go:329–344  ·  view source on GitHub ↗

deleteRelations removes specific relations from the graph.

(relations []Relation)

Source from the content-addressed store, hash-verified

327
328// deleteRelations removes specific relations from the graph.
329func (k knowledgeBase) deleteRelations(relations []Relation) error {
330 graph, err := k.loadGraph()
331 if err != nil {
332 return err
333 }
334
335 // Filter relations using slices.DeleteFunc and slices.ContainsFunc
336 graph.Relations = slices.DeleteFunc(graph.Relations, func(existingRelation Relation) bool {
337 return slices.ContainsFunc(relations, func(relationToDelete Relation) bool {
338 return existingRelation.From == relationToDelete.From &&
339 existingRelation.To == relationToDelete.To &&
340 existingRelation.RelationType == relationToDelete.RelationType
341 })
342 })
343 return k.saveGraph(graph)
344}
345
346// searchNodes filters entities and relations matching the query string.
347func (k knowledgeBase) searchNodes(query string) (KnowledgeGraph, error) {

Callers 2

DeleteRelationsMethod · 0.95

Calls 2

loadGraphMethod · 0.95
saveGraphMethod · 0.95

Tested by 1