feat: hierarchical Leiden community detection + community summaries + relevance-pruned query#347
Open
zoedecker wants to merge 4 commits intosafishamsi:v4from
Open
Conversation
Add hierarchical_cluster() to cluster.py that runs Leiden/Louvain at multiple resolution parameters [0.5, 1.0, 2.0] to produce coarse, medium, and fine community levels. Falls back gracefully to networkx when graspologic is not installed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
New summarize.py with three backends: extractive (template-based, no LLM), ollama (local model), and claude (Anthropic API). LLM backends fall back to extractive on failure. Public API: summarize_community() and summarize_all_communities(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add --hierarchical and --summary-backend flags to cluster-only command. Update export.to_json() to store community_hierarchy and community_summaries as optional top-level keys in graph.json. Backward-compatible: omitted when flags are not used. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When community_summaries exist in graph.json, query_graph now scores communities by term overlap and restricts traversal to top-K relevant communities before applying token budget. Falls back to original behavior when no summaries are present. New list_communities tool exposes summaries and hierarchy levels for browsing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Microsoft GraphRAG-inspired hierarchical clustering and community summaries to graphify, enabling significantly fewer tokens on broad queries by matching against pre-computed community summaries and only expanding relevant subgraphs.
list_communitiesMCP tool for browsing community structure--hierarchicalflagDetails
Hierarchical Clustering (
cluster.py)hierarchical_cluster(G, resolutions)runs Leiden (or Louvain fallback) at multiple resolution levels{level: {community_id: [node_ids]}}stored in graph.json undercommunity_hierarchycommunityfield on nodes unchangedCommunity Summaries (
summarize.py— new file)extractive(template from top-degree nodes + edge types, zero LLM cost),ollama(local model),claude(API)community_summariesRelevance-Pruned Query (
serve.py)_community_relevance_score()scores each community summary against query terms_tool_query_graphnow prunes to top-K relevant communities before BFS/DFS when hierarchy existslist_communitiesMCP tool returns summaries for browsingCLI
graphify cluster-only <path> --hierarchicalenables multi-resolution clustering + summariesgraphify cluster-only <path> --summary-backend <extractive|ollama|claude>selects summary backendTest plan
test_hierarchical.py,test_summarize.py, andtest_serve.pyOpen questions
leiden()resolution parameter support may vary by version — code falls back to networkx gracefullyreport.pyandwiki.pynot yet updated to include summaries — keeping scope minimal for this PR