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

Method KnowledgeGraph

cli/graphview_adapter.go:42–77  ·  view source on GitHub ↗

KnowledgeGraph converts the in-core knowledge graph to renderable data.

()

Source from the content-addressed store, hash-verified

40
41// KnowledgeGraph converts the in-core knowledge graph to renderable data.
42func (a *graphViewPluginAdapter) KnowledgeGraph() (plugins.GraphData, error) {
43 g := a.cli.buildKnowledgeGraph()
44 data := plugins.GraphData{
45 Nodes: make([]plugins.GraphNode, 0, g.Len()),
46 Edges: make([]plugins.GraphEdge, 0, g.Edges()),
47 }
48 for _, n := range g.Nodes() {
49 label := strings.TrimSpace(n.Title)
50 if label == "" {
51 label = n.ID
52 }
53 data.Nodes = append(data.Nodes, plugins.GraphNode{
54 ID: n.ID,
55 Label: label,
56 Kind: string(n.Kind),
57 Summary: n.Summary,
58 Weight: n.Weight,
59 })
60 }
61 seen := make(map[string]bool)
62 for _, n := range g.Nodes() {
63 for _, nb := range g.Neighbors(n.ID) {
64 x, y := n.ID, nb.ID
65 if x > y {
66 x, y = y, x
67 }
68 key := x + "\x00" + y
69 if seen[key] {
70 continue
71 }
72 seen[key] = true
73 data.Edges = append(data.Edges, plugins.GraphEdge{Source: x, Target: y, Weight: nb.Weight})
74 }
75 }
76 return data, nil
77}
78
79// ConversationGraph builds a graph of EVERYTHING in the current session, not
80// just the message thread: a session root hub connects the conversation thread

Callers 1

Calls 5

buildKnowledgeGraphMethod · 0.80
EdgesMethod · 0.80
NodesMethod · 0.80
NeighborsMethod · 0.80
LenMethod · 0.45

Tested by 1