prepare_vis_graph()

Prepare a knowledge graph for visualization.

Usage

Source

prepare_vis_graph(
    kg,
    *,
    max_nodes=200,
    node_type=None,
    color_by="type",
    title="Knowledge Graph"
)

Converts nodes and edges into visualization-ready dataclasses with computed colors, sizes, and labels.

Parameters

kg: KnowledgeGraph

The knowledge graph to visualize.

max_nodes: int = 200

Maximum number of nodes to include.

node_type: NodeType | None = None

If provided, only include nodes of this type.

color_by: str = "type"

Color scheme: "type" (by node type) or "freshness" (by update recency).

title: str = "Knowledge Graph"
Title for the visualization.

Returns

VisGraph
A visualization-ready graph.

Examples

import talk_box as tb

kg = tb.KnowledgeGraph(":memory:")
# ... add nodes and edges ...
graph = tb.prepare_vis_graph(kg, color_by="freshness")
graph.node_count