liveBook · Manning

Hierarchical clustering

As explained in Domain-Specific Small Language Models

A clustering approach that builds communities through repeated refinement and aggregation of grouped items.

Builds communities by starting from singleton partitions, moving nodes to improve quality, refining the partition, then aggregating and repeating until improvement stops. section 14.1 section 14.1

Here, it serves community detection for GraphRAG indexing, where better-separated clusters support later summarization and query answering. section 14.1 section 14.1

Key implementation points shown here:

  • Starts from a singleton partition with each node in its own community. section 14.1
  • Moves nodes between communities using modularity gain as the score. section 14.1
  • Refines the partition before building the aggregated network. section 14.1
  • Repeats move and aggregate steps until no further improvement is possible. section 14.1

GraphRAG community detection

A Python implementation computes modularity gain, aggregates communities, runs Leiden on the combined graph, then groups nodes into community text for summarization. section 14.1 section 14.1

How Domain-Specific Small Language Models covers it

How deep it goes
Explains the move-refine-aggregate loop and modularity gain, but stops short of a full validated implementation.
Examples
Uses a combined graph, community summaries, and a custom Python Leiden implementation.
What it assumes
Assumes graph nodes, edges, and communities, and introduces the algorithm from a singleton partition.
What you can do after
Apply it to partition graphs into communities for downstream summarization and query answering.
How it connects
Connects to GraphRAG, Louvain, Leiden algorithm, modularity, and NetworkX.

Also explained in

Compare how 5 books explain hierarchical clustering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.