feat(graph): GET/POST /graph/structural-stats — full-graph Cat 5/8 (gated) - #211
Merged
Conversation
…ated) green-Somnia's catch: SME's --real-kg adapter reads a SAMPLED /graph?limit=N slice whose Cat 5 (connectivity/isolates) and Cat 8 (modularity) absolute numbers DRIFT with the limit and ≠ the full graph (the `other` fraction alone moves 47%→58% across sample sizes). Cat 4 is safe (it uses the exact full-graph GROUP BY aggregation), but Cat 5/8 needed an exact full-graph computation. A row-returning `MATCH ()-[r:RELATION]->()` OOMs AGE (#160 — agtype edge-object materialization), so this reads the endpoint INTEGER pairs (start_id, end_id) directly off the `mempalace_kg."RELATION"` label table (no agtype) — the kg_reader.read_kg_postgres pattern — and computes: * Cat 5 connectivity via a dependency-free union-find (exact, ~O(E·α)): component_count, largest_component_size + fraction, isolate_count (entities with zero RELATION degree, counted against the full Entity universe), component_size_histogram. * Cat 8 modularity via networkx Louvain over the largest WCC. networkx is a soft dep (added to requirements with the established "degraded-state worse than disk" rationale, imported only by this route); absent → modularity None + a note, connectivity unaffected.⚠️ HEAVY + GATED — the compute is a GB-RAM / minutes spike over ~1.9M edges, so it is NEVER run inline on demand: * POST /graph/structural-stats triggers it once; GET returns the cached payload (404 until first computed — a plain read never computes). * POST is write-auth gated (header key, not the viz cookie) and REFUSED 409 while a bench is active (.bench-active.lock), run under the read semaphore + off the event loop, result cached. * 503 under chroma / unreachable AGE. The one-time production run is intended off-peak (not inline on the box serving the live palace). Validated against synthetic graphs with known WCC/modularity (two-triangles, isolates-vs-full-universe, clique-bridge-clique, empty, None-endpoints) + route gating/caching tests — NO prod compute run here. 33 tests green (1 modularity test skips without networkx), ruff clean. SME consumer (get_structural_stats() + cat5/cat8) lands separately. Refs #147. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
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.
What
Adds a gated daemon endpoint that computes the exact full-graph SME Cat 5 (connectivity / isolates) and Cat 8 (modularity) stats over the whole RELATION knowledge graph — replacing the biased, sample-dependent numbers SME's
--real-kgadapter currently derives from a capped/graph?limit=Nslice.Why (green-Somnia's catch)
SME's
--real-kgpath reads a/graph?limit=Nsample whose absolute Cat 5/8 numbers drift with the limit and don't equal the full graph — theotherrelation fraction alone moves 47% (5k) → 58% (10k) vs 55% full. Cat 4 is unaffected (it already uses the exact full-graphGROUP BY), but Cat 5/8 needed a true full-graph computation. The verdicts (well-connected, hierarchical-PASS) are robust across samples; the precise absolute figures were not publishable from a sample.How
A row-returning
MATCH ()-[r:RELATION]->()OOMs AGE (#160 — agtype edge-object materialization), so this reads the endpoint integer pairs(start_id, end_id)directly offmempalace_kg."RELATION"(no agtype — thekg_reader.read_kg_postgrespattern) and computes:Entityuniverse), size histogram.requirements.txtwith the established rationale, imported only by this route); if absent →modularity: null+ a note, connectivity unaffected.The compute is a GB-RAM / minutes spike over ~1.9M edges, so it is never run inline on demand:
POST /graph/structural-statstriggers it once;GETreturns the cached payload (404 until first computed — a plain read never computes).409while a bench is active (.bench-active.lock), run under the read semaphore + off the event loop, result cached.503under chroma / unreachable AGE.The one-time production run is intended off-peak, surfaced for scheduling — not inline on the box serving the live palace.
Tests
33 green (1 modularity test skips without networkx), ruff clean. Validated against synthetic graphs with known answers (two disjoint triangles, isolates-vs-full-universe, clique-bridge-clique modularity, empty graph, None-endpoints) + route gating/caching (GET-404-before-compute, POST-409-under-bench, compute+cache+serve, 503-on-None, modularity-flag threading). No prod compute was run — the real 1.9M-edge population waits for an off-peak window.
SME consumer side (
get_structural_stats()adapter method + cat5/cat8 wiring) lands in a separate SME PR.Refs #147.
🤖 Generated with Claude Code