Skip to content

feat: replace BFS with Louvain clustering#211

Merged
blak0p merged 2 commits into
feat/graph-clusteringfrom
feat/graph-clustering-01-core
Jul 2, 2026
Merged

feat: replace BFS with Louvain clustering#211
blak0p merged 2 commits into
feat/graph-clusteringfrom
feat/graph-clustering-01-core

Conversation

@blak0p

@blak0p blak0p commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Chain Context

Field Value
Chain graph-clustering
Tracker PR #210
Position 1 of 2
Base feat/graph-clustering
Depends on None
Follow-up #212 (tests)
Review budget 310 / 400
Starts at main
Ends with Louvain pipeline in place, regression green

Chain Overview

main
 └── #210 Tracker PR (draft)
      └── 📍 #211 This PR (core)
           └── #212 Next PR (tests)

Scope

  • Includes: Louvain community detection, bridge merging (weight > 500), greedy oversized-cluster split, maxFilesPerChunk wiring
  • Excludes: New tests, louvain_compare_test.go deletion (PR 2)

Autonomy

  • CI is expected to pass for this PR branch
  • This PR has one deliverable scope
  • This PR can be rolled back without unrelated changes
  • Tests, docs, or manual verification cover this unit

Closes #208

WHY
The previous BFS-based clustering treated every connected component as a single cluster, ignoring community structure within large components. This resulted in oversized chunks that exceeded the `maxFilesPerChunk` limit and failed to group files by semantic density.

WHAT
* Replaced BFS traversal with a three-stage pipeline: Louvain community detection, bridge merging (weight > 500), and greedy splitting.
* Implemented deterministic Louvain modularity optimization using sorted node ordering for reproducible cluster assignments.
* Added `mergeBridgeClusters` to rejoin communities connected by strong semantic links that Louvain might have separated.
* Assigned `c.maxFilesPerChunk` to `c.unifiedPass.maxFilesPerChunk` in the chunker configuration.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

…212)

## Chain Context

| Field | Value |
|-------|-------|
| Chain | graph-clustering |
| Tracker PR | #210 |
| Position | 2 of 2 |
| Base | `feat/graph-clustering-01-core` |
| Depends on | #211 (core) |
| Follow-up | None |
| Review budget | 331 / 400 |
| Starts at | #211 (core implementation) |
| Ends with | Full test coverage + cleanup |

### Chain Overview

```
main
 └── #210 Tracker PR (draft)
      └── #211 Core implementation
           └── 📍 #212 This PR (tests)
```

### Scope
- Includes: Unit tests for louvainClusters, mergeBridgeClusters,
splitOversizedClusters, integration test for createClusters end-to-end
- Excludes: Production code changes

### Autonomy
- [x] CI is expected to pass for this PR branch
- [x] This PR has one deliverable scope
- [x] This PR can be rolled back without unrelated changes
- [x] Tests, docs, or manual verification cover this unit

---

Closes #208
@blak0p blak0p merged commit 96ce9ea into feat/graph-clustering Jul 2, 2026
1 of 2 checks passed
@blak0p blak0p deleted the feat/graph-clustering-01-core branch July 2, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant