MCPcopy Create free account
hub / github.com/diillson/chatcli / AddNode

Method AddNode

pkg/knowledge/graph.go:72–91  ·  view source on GitHub ↗

AddNode upserts a node by ID. Re-adding an existing ID updates its display fields and keeps the larger Weight, never dropping edges. Empty IDs and titles are ignored. Returns the stored node.

(n Node)

Source from the content-addressed store, hash-verified

70// fields and keeps the larger Weight, never dropping edges. Empty IDs and
71// titles are ignored. Returns the stored node.
72func (g *Graph) AddNode(n Node) *Node {
73 if strings.TrimSpace(n.ID) == "" {
74 return nil
75 }
76 if existing, ok := g.nodes[n.ID]; ok {
77 if n.Title != "" {
78 existing.Title = n.Title
79 }
80 if n.Summary != "" {
81 existing.Summary = n.Summary
82 }
83 if n.Weight > existing.Weight {
84 existing.Weight = n.Weight
85 }
86 return existing
87 }
88 cp := n
89 g.nodes[n.ID] = &cp
90 return &cp
91}
92
93// AddEdge adds (or reinforces) an undirected edge. It is a no-op when either
94// endpoint is missing or when a == b, so callers can wire edges optimistically

Callers 6

sampleGraphFunction · 0.80
dotSampleGraphFunction · 0.80
addMemoryNodesMethod · 0.80
addSkillNodesMethod · 0.80
addTagFunction · 0.80

Calls

no outgoing calls

Tested by 3

sampleGraphFunction · 0.64
dotSampleGraphFunction · 0.64