Skip to content

API Reference parrot.knowledge.graphindex.export_html

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.knowledge.graphindex.export_html

View source

GraphIndex HTML export — interactive, self-contained knowledge-graph map.

Emits two sibling artefacts from an assembled :class:rustworkx.PyDiGraph:

  • graph.json — the serialized graph (nodes, edges, communities) for programmatic reuse, mirroring Graphify's graph.json artefact.
  • graph.html — a fully offline, clickable force-directed visualization. Every node is a concept, its colour is the detected community, and its size scales with centrality so "god nodes" (the most-connected concepts) stand out. Clicking a node opens a detail panel; the legend toggles communities; a search box filters nodes by title.

Design goals mirror the rest of GraphIndex:

  • Deterministic — no LLM calls; community colours come from a fixed palette keyed by display order, so the same graph renders identically.
  • Local-first — the ECharts runtime is inlined from the vendored asset shipped by ai-parrot-visualizations (parrot.outputs.formats.assets), so the produced page works with no network access ("nothing leaves your machine"). A CDN <script> fallback is emitted only when the asset cannot be located, accompanied by a logged warning.

The public surface is intentionally decoupled from the analytics/communities models: :func:build_export_payload accepts plain dicts/lists so it can be unit-tested without those modules, while :func:export_graph adapts a CommunitiesResult / AnalyticsResult into that payload and writes both files in one call (used by the builder and the agent toolkit).

Attribute ECHARTS_CDN_URL

Class GraphExportCategory

A community category (an ECharts legend entry + colour).

Fields:

Field Type Default Description
index int
community_id str | None
label str
color str
size int

Class GraphExportEdge

A single directed edge in the export payload / ECharts links.

Fields:

Field Type Default Description
source str
target str
kind str 'references'
provenance str 'extracted'
confidence float | None None

Class GraphExportNode

A single node in the export payload / ECharts graph series.

Field names id/name/category/symbolSize/value match the ECharts graph-series schema so the payload can be handed to ECharts with no remapping. The remaining fields feed the click-through detail panel.

Fields:

Field Type Default Description
id str
name str
kind str
category int
symbolSize float
value float 0.0
community_id str | None None
community_label str | None None
source_uri str ''
summary str | None None
provenance str 'extracted'
degree int 0
is_god bool False

Class GraphExportPayload

The complete, serializable graph export.

Serialized verbatim to graph.json and embedded into graph.html.

Fields:

Field Type Default Description
title str 'GraphIndex Knowledge Map'
nodes list[GraphExportNode]
edges list[GraphExportEdge]
categories list[GraphExportCategory]
god_node_ids list[str]
modularity float | None None
meta dict[str, Any]
inter_community_relations list[dict]
inter_community_density float | None None

Attribute HTML_FILENAME

Attribute JSON_FILENAME

Function build_export_payload

Build a :class:GraphExportPayload from an assembled graph.

Pure and deterministic: it reads only the node/edge payload dicts stored on the rustworkx.PyDiGraph plus the plain community/god-node lookups, so it needs neither the analytics nor the communities modules. :func:export_graph supplies these lookups from the richer result objects.

build_export_payload(graph: rustworkx.PyDiGraph, *, node_to_community: dict[str, str] | None = None, community_order: list[str] | None = None, community_labels: dict[str, str] | None = None, community_sizes: dict[str, int] | None = None, god_scores: dict[str, float] | None = None, god_node_ids: list[str] | None = None, title: str = 'GraphIndex Knowledge Map', modularity: float | None = None, inter_community_relations: list[dict] | None = None, inter_community_density: float | None = None) -> GraphExportPayload

Parameter Type Default Description
graph rustworkx.PyDiGraph The assembled rustworkx.PyDiGraph. Node payloads must be dicts carrying at least node_id, kind and title; edge payloads carry source_id/target_id/kind.
node_to_community dict[str, str] | None None Map node_id → community_id. Nodes absent from this map are placed in the Unclustered category.
community_order list[str] | None None Community ids in display order (largest first). Defines the colour assignment. Ids missing here are appended in first-seen order.
community_labels dict[str, str] | None None Map community_id → human-readable label.
community_sizes dict[str, int] | None None Map community_id → member count (for the legend).
god_scores dict[str, float] | None None Map node_id → centrality score used for node sizing.
god_node_ids list[str] | None None Ids to flag as god nodes (highlighted + size boost).
title str 'GraphIndex Knowledge Map' Graph title for the page header.
modularity float | None None Global modularity Q, recorded in metadata.
inter_community_relations list[dict] | None None FEAT-401 pre-serialized community-pair relation dicts (see :func:export_graph for how these are adapted from an InterCommunityGraph). Passed through verbatim — this function stays pure and does not import inter_community.
inter_community_density float | None None FEAT-401 meta-graph density, passed through verbatim.

Returns: GraphExportPayload — A fully populated :class:GraphExportPayload.

Function community_color

Return the deterministic colour for a community display index.

community_color(index: int) -> str

Parameter Type Default Description
index int Zero-based position of the community in display order.

Returns: str — A hex colour string. Indices beyond the palette wrap around.

Function export_graph

Build the payload and write both graph.json and graph.html.

Adapts a CommunitiesResult, an AnalyticsResult, and (FEAT-401) an InterCommunityGraph into the plain lookups :func:build_export_payload consumes, then writes both artefacts.

export_graph(graph: rustworkx.PyDiGraph, output_dir: Path, *, communities: Any | None = None, analytics: Any | None = None, inter_community: Any | None = None, god_top_k: int = 15, title: str = 'GraphIndex Knowledge Map', echarts_js: str | None = None, allow_cdn_fallback: bool = True) -> tuple[Path, Path]

Parameter Type Default Description
graph rustworkx.PyDiGraph The assembled rustworkx.PyDiGraph.
output_dir Path Destination directory.
communities Any | None None Optional CommunitiesResult for node colouring/labels.
analytics Any | None None Optional AnalyticsResult whose god_nodes drive node sizing and highlighting.
inter_community Any | None None Optional FEAT-401 InterCommunityGraph — its relations populate the graph.html inter-community table panel and the graph.json inter_community_relations array. Adapted via getattr duck-typing (not imported at module level) so this module stays usable without the inter_community module.
god_top_k int 15 Number of top god nodes to highlight.
title str 'GraphIndex Knowledge Map' Graph title for the page header.
echarts_js str | None None Explicit ECharts runtime to inline (else auto-located).
allow_cdn_fallback bool True See :func:write_graph_html.

Returns: tuple[Path, Path] — (html_path, json_path).

Attribute logger

Function write_graph_html

Write a self-contained graph.html to output_dir.

write_graph_html(payload: GraphExportPayload, output_dir: Path, *, echarts_js: str | None = None, allow_cdn_fallback: bool = True) -> Path

Parameter Type Default Description
payload GraphExportPayload The export payload.
output_dir Path Destination directory (created if missing).
echarts_js str | None None Explicit ECharts runtime JavaScript to inline. When None, the vendored asset is located automatically.
allow_cdn_fallback bool True When the asset cannot be located and this is True, reference the ECharts CDN and log a warning (the page then needs network access). When False, raise instead.

Returns: Path — The path to the written graph.html.

Raises:

  • RuntimeError — When no ECharts runtime is available and CDN fallback is disabled.

Function write_graph_json

Write graph.json to output_dir.

write_graph_json(payload: GraphExportPayload, output_dir: Path) -> Path

Parameter Type Default Description
payload GraphExportPayload The export payload.
output_dir Path Destination directory (created if missing).

Returns: Path — The path to the written graph.json.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally