# knowledge_graph URL: /api/analysis/knowledge_graph/ Section: analysis -------------------------------------------------------------------------------- knowledge_graph - Bengal window.BENGAL_THEME_DEFAULTS = { appearance: 'dark', palette: 'snow-lynx' }; // Progressive Enhancement System Configuration window.Bengal = window.Bengal || {}; window.Bengal.enhanceBaseUrl = '/bengal/assets/js/enhancements'; window.Bengal.watchDom = true; window.Bengal.debug = false; (function () { try { var defaults = window.BENGAL_THEME_DEFAULTS || { appearance: 'system', palette: '' }; var defaultAppearance = defaults.appearance; if (defaultAppearance === 'system') { defaultAppearance = (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ? 'dark' : 'light'; } var storedTheme = localStorage.getItem('bengal-theme'); var storedPalette = localStorage.getItem('bengal-palette'); var theme = storedTheme ? (storedTheme === 'system' ? defaultAppearance : storedTheme) : defaultAppearance; var palette = storedPalette ?? defaults.palette; document.documentElement.setAttribute('data-theme', theme); if (palette) { document.documentElement.setAttribute('data-palette', palette); } } catch (e) { document.documentElement.setAttribute('data-theme', 'light'); } })(); Skip to main content Magnifying Glass ESC Recent Clear Magnifying Glass No results for "" Try different keywords or check your spelling Start typing to search... ↑↓ Navigate ↵ Open ESC Close Powered by Lunr ᓚᘏᗢ Documentation Info About Arrow Clockwise Get Started Note Tutorials File Text Content Palette Theming Settings Building Starburst Extending Bookmark Reference Learning Tracks Releases Dev GitHub API Reference bengal CLI Magnifying Glass Search ⌘K Palette Appearance Chevron Down Mode Monitor System Sun Light Moon Dark Palette Snow Lynx Brown Bengal Silver Bengal Charcoal Bengal Blue Bengal List ᓚᘏᗢ Magnifying Glass Search X Close Documentation Info About Arrow Clockwise Get Started Note Tutorials File Text Content Palette Theming Settings Building Starburst Extending Bookmark Reference Learning Tracks Releases Dev GitHub API Reference bengal CLI Palette Appearance Chevron Down Mode Monitor System Sun Light Moon Dark Palette Snow Lynx Brown Bengal Silver Bengal Charcoal Bengal Blue Bengal API Reference __main__ bengal Caret Right Folder Analysis community_detection graph_analysis graph_reporting graph_visualizer knowledge_graph link_suggestions link_types page_rank path_analysis performance_advisor results Caret Right Folder Assets manifest pipeline Caret Right Folder Autodoc base config docstring_parser utils virtual_orchestrator Caret Right Folder Extractors cli openapi python Caret Right Folder Models cli common openapi python Caret Right Folder Cache asset_dependency_map cache_store cacheable compression dependency_tracker page_discovery_cache query_index query_index_registry taxonomy_index utils Caret Right Folder Build Cache autodoc_tracking core file_tracking fingerprint parsed_content_cache rendered_output_cache taxonomy_index_mixin validation_cache Caret Right Folder Indexes author_index category_index date_range_index section_index Caret Right Folder Cli __main__ base site_templates utils Caret Right Folder Commands assets build clean collections config debug explain fix health init perf project serve site skeleton sources theme utils validate Caret Right Folder Graph __main__ bridges communities orphans pagerank report suggest Caret Right Folder New config presets scaffolds site wizard Caret Right Folder Helpers cli_app_loader cli_output config_validation error_handling menu_config metadata progress site_loader traceback validation Caret Right Folder Skeleton hydrator schema Caret Right Folder Templates base registry Caret Right Folder Blog template Caret Right Folder Changelog template Caret Right Folder Default template Caret Right Folder Docs template Caret Right Folder Landing template Caret Right Folder Portfolio template Caret Right Folder Resume template Caret Right Folder Collections errors loader schemas validator Caret Right Folder Config defaults deprecation directory_loader env_overrides environment feature_mappings hash loader merge origin_tracker validators Caret Right Folder Content Layer entry loaders manager source Caret Right Folder Sources github local notion rest Caret Right Folder Content Types base registry strategies Caret Right Folder Core build_context cascade_engine menu section theme Caret Right Folder Asset asset_core css_transforms Caret Right Folder Page computed content metadata navigation operations page_core proxy relationships utils Caret Right Folder Site core data discovery factories page_caches properties section_registry theme Caret Right Folder Debug base config_inspector content_migrator delta_analyzer dependency_visualizer explainer incremental_debugger models reporter shortcode_sandbox Caret Right Folder Discovery asset_discovery content_discovery Caret Right Folder Fonts downloader generator Caret Right Folder Health autofix base health_check report Caret Right Folder Linkcheck async_checker ignore_policy internal_checker models orchestrator Caret Right Folder Validators anchors assets cache config connectivity cross_ref fonts links menu navigation output performance rendering rss sitemap taxonomy tracks Caret Right Folder Directives analysis checkers constants Caret Right Folder Orchestration asset content full_to_incremental incremental menu postprocess related_posts render section static streaming taxonomy Caret Right Folder Postprocess html_output redirects rss sitemap special_pages Caret Right Folder Output Formats index_generator json_generator llm_generator lunr_index_generator txt_generator utils Caret Right Folder Rendering api_doc_enhancer asset_extractor errors jinja_utils link_transformer link_validator pygments_cache renderer template_context template_profiler validator Caret Right Folder Parsers base factory mistune native_html pygments_patch python_markdown Caret Right Folder Pipeline core output thread_local toc transforms Caret Right Folder Plugins badges cross_references inline_icon term variable_substitution Caret Right Folder Directives _icons admonitions badge base button cache cards checklist code_tabs container contracts data_table dropdown embed errors example_label fenced figure glossary icon include list_table literalinclude marimo navigation options rubric steps tabs target term terminal tokens utils validator video Caret Right Folder Template Engine asset_url core environment manifest menu url_helpers Caret Right Folder Template Functions advanced_collections advanced_strings autodoc collections content crossref data dates debug files get_page i18n icons images math_functions navigation pagination_helpers seo strings tables taxonomies theme urls Caret Right Folder Server build_handler component_preview constants dev_server live_reload pid_manager reload_controller request_handler request_logger resource_manager utils Caret Right Folder Services validation Caret Right Folder Themes config Caret Right Folder Utils atomic_write autodoc build_context build_stats build_summary cli_output css_minifier dates dotdict error_handlers file_io file_lock hashing incremental_constants js_bundler live_progress logger metadata observability page_initializer pagination path_resolver paths performance_collector performance_report profile progress retry rich_console sections swizzle text theme_registry theme_resolution thread_local traceback_config traceback_renderer url_normalization url_strategy API Reference Analysis ᗢ Caret Down Link Copy URL External Open LLM text Copy Copy LLM text Share with AI Ask Claude Ask ChatGPT Ask Gemini Ask Copilot Module analysis.knowledge_graph Knowledge Graph Analysis for Bengal SSG. Analyzes page connectivity, identifies hubs and leaves, finds orphaned pages, and provides insights for optimization and content strategy. View source 3 Classes Classes GraphMetrics dataclass Metrics about the knowledge graph structure. 0 Caret Right Metrics about the knowledge graph structure. Attributes Name Type Description total_pages int Total number of pages analyzed total_links int Total number of links between pages avg_connectivity float Average connectivity score per page hub_count int Number of hub pages (highly connected) leaf_count int Number of leaf pages (low connectivity) orphan_count int Number of orphaned pages (no connections at all) PageConnectivity dataclass Connectivity information for a single page. 0 Caret Right Connectivity information for a single page. Attributes Name Type Description page Page The page object incoming_refs int Number of incoming references outgoing_refs int Number of outgoing references connectivity_score int Total connectivity (incoming + outgoing) is_hub bool True if page has many incoming references is_leaf bool True if page has few connections is_orphan bool True if page has no connections at all KnowledgeGraph Analyzes the connectivity structure of a Bengal site. Builds a graph of all pages and their connec… 37 Caret Right Analyzes the connectivity structure of a Bengal site. Builds a graph of all pages and their connections through: Internal links (cross-references) Taxonomies (tags, categories) Related posts Menu items Provides insights for: Content strategy (find orphaned pages) Performance optimization (hub-first streaming) Navigation design (understand structure) SEO improvements (link structure) Methods 26 build Build the knowledge graph by analyzing all page connections. This analyzes: 1.… 0 None Caret Right def build(self) -> None Build the knowledge graph by analyzing all page connections. This analyzes: Cross-references (internal links between pages) Taxonomy references (pages grouped by tags/categories) Related posts (pre-computed relationships) Menu items (navigation references) Call this before using any analysis methods. get_analysis_pages Get list of pages to analyze, excluding autodoc pages if configured. 0 list[Page] Caret Right def get_analysis_pages(self) -> list[Page] Get list of pages to analyze, excluding autodoc pages if configured. Returns list[Page] — List of pages to include in graph analysis get_connectivity Get connectivity information for a specific page. 1 PageConnectivity Caret Right def get_connectivity(self, page: Page) -> PageConnectivity Get connectivity information for a specific page. Parameters 1 page Page Page to analyze Returns PageConnectivity — PageConnectivity with detailed metrics get_hubs Get hub pages (highly connected pages). Hubs are pages with many incoming refe… 1 list[Page] Caret Right def get_hubs(self, threshold: int | None = None) -> list[Page] Get hub pages (highly connected pages). Hubs are pages with many incoming references. These are typically: Index pages Popular articles Core documentation Parameters 1 threshold int | None Minimum incoming refs (defaults to self.hub_threshold) Returns list[Page] — List of hub pages sorted by incoming references (descending) get_leaves Get leaf pages (low connectivity pages). Leaves are pages with few connections… 1 list[Page] Caret Right def get_leaves(self, threshold: int | None = None) -> list[Page] Get leaf pages (low connectivity pages). Leaves are pages with few connections. These are typically: One-off blog posts Changelog entries Niche content Parameters 1 threshold int | None Maximum connectivity (defaults to self.leaf_threshold) Returns list[Page] — List of leaf pages sorted by connectivity (ascending) get_orphans Get orphaned pages (no connections at all). Orphans are pages with no incoming… 0 list[Page] Caret Right def get_orphans(self) -> list[Page] Get orphaned pages (no connections at all). Orphans are pages with no incoming or outgoing references. These might be: Forgotten content Draft pages Pages that should be linked from navigation Returns list[Page] — List of orphaned pages sorted by slug get_connectivity_report Get comprehensive connectivity report with pages grouped by level. Uses weight… 2 ConnectivityReport Caret Right def get_connectivity_report(self, thresholds: dict[str, float] | None = None, weights: dict[LinkType, float] | None = None) -> ConnectivityReport Get comprehensive connectivity report with pages grouped by level. Uses weighted scoring based on semantic link types to provide nuanced analysis beyond binary orphan detection. Parameters 2 thresholds dict[str, float] | None Custom thresholds for connectivity levels. Defaults to DEFAULT_THRESHOLDS. weights dict[LinkType, float] | None Custom weights for link types. Defaults to DEFAULT_WEIGHTS. Returns ConnectivityReport — ConnectivityReport with pages grouped by level and statistics. get_page_link_metrics Get detailed link metrics for a specific page. 1 LinkMetrics Caret Right def get_page_link_metrics(self, page: Page) -> LinkMetrics Get detailed link metrics for a specific page. Parameters 1 page Page Page to get metrics for Returns LinkMetrics — LinkMetrics with breakdown by link type get_connectivity_score Get total connectivity score for a page. Connectivity = incoming_refs + outgoi… 1 int Caret Right def get_connectivity_score(self, page: Page) -> int Get total connectivity score for a page. Connectivity = incoming_refs + outgoing_refs Parameters 1 page Page Page to analyze Returns int — Connectivity score (higher = more connected) get_layers Partition pages into three layers by connectivity. Layers enable hub-first str… 0 PageLayers Caret Right def get_layers(self) -> PageLayers Partition pages into three layers by connectivity. Layers enable hub-first streaming builds: Layer 0 (Hubs): High connectivity, process first, keep in memory Layer 1 (Mid-tier): Medium connectivity, batch processing Layer 2 (Leaves): Low connectivity, stream and release Returns PageLayers — PageLayers dataclass with hubs, mid_tier, and leaves attributes (supports tuple unpacking for backward compatibility) get_metrics Get overall graph metrics. 0 GraphMetrics Caret Right def get_metrics(self) -> GraphMetrics Get overall graph metrics. Returns GraphMetrics — GraphMetrics with summary statistics format_stats Format graph statistics as a human-readable string. 0 str Caret Right def format_stats(self) -> str Format graph statistics as a human-readable string. Returns str — Formatted statistics string get_actionable_recommendations Generate actionable recommendations for improving site structure. 0 list[str] Caret Right def get_actionable_recommendations(self) -> list[str] Generate actionable recommendations for improving site structure. Returns list[str] — List of recommendation strings with emoji prefixes get_seo_insights Generate SEO-focused insights about site structure. 0 list[str] Caret Right def get_seo_insights(self) -> list[str] Generate SEO-focused insights about site structure. Returns list[str] — List of SEO insight strings with emoji prefixes get_content_gaps Identify content gaps based on link structure and taxonomies. 0 list[str] Caret Right def get_content_gaps(self) -> list[str] Identify content gaps based on link structure and taxonomies. Returns list[str] — List of content gap descriptions compute_pagerank Compute PageRank scores for all pages in the graph. PageRank assigns importanc… 3 PageRankResults Caret Right def compute_pagerank(self, damping: float = 0.85, max_iterations: int = 100, force_recompute: bool = False) -> PageRankResults Compute PageRank scores for all pages in the graph. PageRank assigns importance scores based on link structure. Pages that are linked to by many important pages get high scores. Parameters 3 damping float Probability of following links vs random jump (default 0.85) max_iterations int Maximum iterations before stopping (default 100) force_recompute bool If True, recompute even if cached Returns PageRankResults — PageRankResults with scores and metadata compute_personalized_pagerank Compute personalized PageRank from seed pages. Personalized PageRank biases ra… 3 PageRankResults Caret Right def compute_personalized_pagerank(self, seed_pages: set[Page], damping: float = 0.85, max_iterations: int = 100) -> PageRankResults Compute personalized PageRank from seed pages. Personalized PageRank biases random jumps toward seed pages, useful for finding pages related to a specific topic or set of pages. Parameters 3 seed_pages set[Page] Set of pages to bias toward damping float Probability of following links vs random jump max_iterations int Maximum iterations before stopping Returns PageRankResults — PageRankResults with personalized scores get_top_pages_by_pagerank Get top-ranked pages by PageRank score. Automatically computes PageRank if not… 1 list[tuple[Page, float]] Caret Right def get_top_pages_by_pagerank(self, limit: int = 20) -> list[tuple[Page, float]] Get top-ranked pages by PageRank score. Automatically computes PageRank if not already computed. Parameters 1 limit int Number of pages to return Returns list[tuple[Page, float]] — List of (page, score) tuples sorted by score descending get_pagerank_score Get PageRank score for a specific page. Automatically computes PageRank if not… 1 float Caret Right def get_pagerank_score(self, page: Page) -> float Get PageRank score for a specific page. Automatically computes PageRank if not already computed. Parameters 1 page Page Page to get score for Returns float — PageRank score (0.0 if page not found) detect_communities Detect topical communities using Louvain method. Discovers natural clusters of… 3 CommunityDetectionResults Caret Right def detect_communities(self, resolution: float = 1.0, random_seed: int | None = None, force_recompute: bool = False) -> CommunityDetectionResults Detect topical communities using Louvain method. Discovers natural clusters of related pages based on link structure. Communities represent topic areas or content groups. Parameters 3 resolution float Resolution parameter (higher = more communities, default 1.0) random_seed int | None Random seed for reproducibility force_recompute bool If True, recompute even if cached Returns CommunityDetectionResults — CommunityDetectionResults with discovered communities get_community_for_page Get community ID for a specific page. Automatically detects communities if not… 1 int | None Caret Right def get_community_for_page(self, page: Page) -> int | None Get community ID for a specific page. Automatically detects communities if not already computed. Parameters 1 page Page Page to get community for Returns int | None — Community ID or None if page not found analyze_paths Analyze navigation paths and centrality metrics. Computes: - Betweenness centr… 4 PathAnalysisResults Caret Right def analyze_paths(self, force_recompute: bool = False, k_pivots: int = 100, seed: int = 42, auto_approximate_threshold: int = 500) -> PathAnalysisResults Analyze navigation paths and centrality metrics. Computes: Betweenness centrality: Pages that act as bridges Closeness centrality: Pages that are easily accessible Network diameter and average path length For large sites (> auto_approximate_threshold pages), uses pivot-based approximation for O(k*N) complexity instead of O(N²). Parameters 4 force_recompute bool If True, recompute even if cached k_pivots int Number of pivot nodes for approximation (default: 100) seed int Random seed for deterministic results (default: 42) auto_approximate_threshold int Use exact if pages <= this (default: 500) Returns PathAnalysisResults — PathAnalysisResults with centrality metrics get_betweenness_centrality Get betweenness centrality for a specific page. Automatically analyzes paths i… 1 float Caret Right def get_betweenness_centrality(self, page: Page) -> float Get betweenness centrality for a specific page. Automatically analyzes paths if not already computed. Parameters 1 page Page Page to get centrality for Returns float — Betweenness centrality score get_closeness_centrality Get closeness centrality for a specific page. Automatically analyzes paths if … 1 float Caret Right def get_closeness_centrality(self, page: Page) -> float Get closeness centrality for a specific page. Automatically analyzes paths if not already computed. Parameters 1 page Page Page to get centrality for Returns float — Closeness centrality score suggest_links Generate smart link suggestions to improve site connectivity. Uses multiple si… 3 LinkSuggestionResults Caret Right def suggest_links(self, min_score: float = 0.3, max_suggestions_per_page: int = 10, force_recompute: bool = False) -> LinkSuggestionResults Generate smart link suggestions to improve site connectivity. Uses multiple signals: Topic similarity (shared tags/categories) PageRank importance Betweenness centrality (bridge pages) Link gaps (underlinked content) Parameters 3 min_score float Minimum score threshold for suggestions max_suggestions_per_page int Maximum suggestions per page force_recompute bool If True, recompute even if cached Returns LinkSuggestionResults — LinkSuggestionResults with all suggestions get_suggestions_for_page Get link suggestions for a specific page. Automatically generates suggestions … 2 list[tuple[Page, fl… Caret Right def get_suggestions_for_page(self, page: Page, limit: int = 10) -> list[tuple[Page, float, list[str]]] Get link suggestions for a specific page. Automatically generates suggestions if not already computed. Parameters 2 page Page Page to get suggestions for limit int Maximum number of suggestions Returns list[tuple[Page, float, list[str]]] — List of (target_page, score, reasons) tuples Internal Methods 11 Caret Right __init__ Initialize knowledge graph analyzer. 4 None Caret Right def __init__(self, site: Site, hub_threshold: int = 10, leaf_threshold: int = 2, exclude_autodoc: bool = True) Initialize knowledge graph analyzer. Parameters 4 site Site Site instance to analyze hub_threshold int Minimum incoming refs to be considered a hub leaf_threshold int Maximum connectivity to be considered a leaf exclude_autodoc bool If True, exclude autodoc/API reference pages from analysis (default: True) _ensure_links_extracted Extract links from all pages if not already extracted. Links are normally extr… 0 None Caret Right def _ensure_links_extracted(self) -> None Extract links from all pages if not already extracted. Links are normally extracted during rendering, but graph analysis needs them before rendering happens. This ensures links are available. _analyze_cross_references Analyze cross-references (internal links between pages). Uses the site's xref_… 0 None Caret Right def _analyze_cross_references(self) -> None Analyze cross-references (internal links between pages). Uses the site's xref_index to find all internal links. Only analyzes links from/to pages included in analysis (excludes autodoc). _resolve_link Resolve a link string to a target page. 1 Page | None Caret Right def _resolve_link(self, link: str) -> Page | None Resolve a link string to a target page. Parameters 1 link str Link string (path, slug, or ID) Returns Page | None — Target page or None if not found _analyze_taxonomies Analyze taxonomy references (pages grouped by tags/categories). Pages in the s… 0 None Caret Right def _analyze_taxonomies(self) -> None Analyze taxonomy references (pages grouped by tags/categories). Pages in the same taxonomy group reference each other implicitly. Only includes pages in analysis (excludes autodoc). _analyze_related_posts Analyze related posts (pre-computed relationships). Related posts are pages th… 0 None Caret Right def _analyze_related_posts(self) -> None Analyze related posts (pre-computed relationships). Related posts are pages that share tags or other criteria. Only includes pages in analysis (excludes autodoc). _analyze_menus Analyze menu items (navigation references). Pages in menus get a significant b… 0 None Caret Right def _analyze_menus(self) -> None Analyze menu items (navigation references). Pages in menus get a significant boost in importance. Only includes pages in analysis (excludes autodoc). _analyze_section_hierarchy Analyze implicit section links (parent _index.md → children). Section index pa… 0 None Caret Right def _analyze_section_hierarchy(self) -> None Analyze implicit section links (parent _index.md → children). Section index pages implicitly link to all child pages in their directory. This represents topical containment—the parent page defines the topic, children belong to that topic. Weight: 0.5 (structural but semantically meaningful) _analyze_navigation_links Analyze next/prev sequential relationships. Pages in a section often have prev… 0 None Caret Right def _analyze_navigation_links(self) -> None Analyze next/prev sequential relationships. Pages in a section often have prev/next relationships representing a reading order or logical sequence (e.g., tutorial steps, changelogs). Weight: 0.25 (pure navigation, lowest editorial intent) _build_link_metrics Build detailed link metrics for each page. Aggregates links by type into LinkM… 0 None Caret Right def _build_link_metrics(self) -> None Build detailed link metrics for each page. Aggregates links by type into LinkMetrics objects for weighted connectivity scoring. _compute_metrics Compute overall graph metrics. 0 GraphMetrics Caret Right def _compute_metrics(self) -> GraphMetrics Compute overall graph metrics. Returns GraphMetrics — GraphMetrics with summary statistics ← Previous graph_visualizer Next → link_suggestions List © 2025 Bengal ᓚᘏᗢ window.BENGAL_LAZY_ASSETS = { tabulator: '/bengal/assets/js/tabulator.min.js', dataTable: '/bengal/assets/js/data-table.js', mermaidToolbar: '/bengal/assets/js/mermaid-toolbar.9de5abba.js', mermaidTheme: '/bengal/assets/js/mermaid-theme.344822c5.js', graphMinimap: '/bengal/assets/js/graph-minimap.cc7e42e3.js', graphContextual: '/bengal/assets/js/graph-contextual.440e59c6.js' }; window.BENGAL_ICONS = { close: '/bengal/assets/icons/close.911d4fe1.svg', enlarge: '/bengal/assets/icons/enlarge.652035e5.svg', copy: '/bengal/assets/icons/copy.3d56e945.svg', 'download-svg': '/bengal/assets/icons/download.04f07e1b.svg', 'download-png': '/bengal/assets/icons/image.c34dfd40.svg', 'zoom-in': '/bengal/assets/icons/zoom-in.237b4a83.svg', 'zoom-out': '/bengal/assets/icons/zoom-out.38857c77.svg', reset: '/bengal/assets/icons/reset.d26dba29.svg' }; Arrow Up X -------------------------------------------------------------------------------- Metadata: - Author: lbliii - Word Count: 3289 - Reading Time: 16 minutes