Skip to content

feat(web): graph-lab Cosmograph PoC menu page#1791

Merged
earayu merged 1 commit into
mainfrom
feat/web-graph-cosmograph-poc
Apr 28, 2026
Merged

feat(web): graph-lab Cosmograph PoC menu page#1791
earayu merged 1 commit into
mainfrom
feat/web-graph-cosmograph-poc

Conversation

@earayu
Copy link
Copy Markdown
Collaborator

@earayu earayu commented Apr 28, 2026

Summary

Per @earayu2 ask in #Graph可视化 (msg=4a8309e4): one menu page where the team can flip between visualisation experiments without leaving the production graph routes alone. Two embedded Cosmograph modes — topology (live KG) and semantic map (synthetic 1k/5k/10k fixture) — plus external-page links to /graph and /graph-showcase for side-by-side comparison.

Why a sibling and not overwriting graph-showcase/: graph-showcase/ already carries 745 LOC of an earlier react-force-graph-2d exploration; replacing it would lose the prior probe. PM ratified the new sibling path in DM (msg=30e30aab).

License caveat: @cosmograph/react is CC-BY-NC-4.0. @earayu2 explicitly fine for PoC (msg=26e5530d), called out in the nav UI as a productionisation gate. The MIT-licensed @cosmos.gl/graph engine is the swap target if the visual sticks.

Files

  • graph-lab/page.tsx — server breadcrumbs + container
  • graph-lab/collection-graph-lab.tsx — client shell, nav ↔ renderer wiring
  • graph-lab/graph-lab-nav.tsx — left rail, mode tabs + external links + license note
  • graph-lab/cosmograph-topology.tsx — live KG → Cosmograph Graph mode (dynamic({ ssr: false }))
  • graph-lab/cosmograph-semantic-map.tsx — synthetic fixture → embedding mode + scale toggle + bench panel
  • graph-lab/lab-modes.ts — shared types so page.tsx stays import-light
  • features/knowledge-graph/cosmograph-adapter.ts — pure data transform (toTopologyDataset / buildSyntheticSemanticDataset)

§K.12 invariant cross-check

4-pattern pre-check matrix

  • Pattern 1 v1 (existing graph routes): production /graph and /graph-showcase are unchanged; no imports moved/renamed.
  • Pattern 1 v2 (data-shape consumers): the new adapter consumes KnowledgeGraph / GraphNode / GraphEdge from @/features/knowledge-graph/types — same source the production graph uses. No type duplication.
  • Pattern 2 (response-shape change list): n/a, no API/schema touched.
  • Pattern 3 (additive helpers): adapter + fixture generator are pure functions; production graph page could adopt them later without circular imports.

simple-stable directive 4-guardrail

  • feat/frontend #1 不无限扩范围 — explicit PoC scope per @ziang acceptance (msg=4db79b66). No backend changes; semantic mode uses front-end fixture data only.
  • feat: auth bearer token support #2 尽快上线 — single-PR ship, ~0.5 day work envelope.
  • feat: api test #3 简单稳定 — production /graph and /graph-showcase byte-identical pre/post.
  • fix: upload token #4 私有化部署免维护 — no operator config introduced. License decision deferred to productionisation; surfaced in the nav UI for visibility.

Acceptance items (per @ziang msg=4db79b66)

  • New graph-lab/ route, graph/ and graph-showcase/ untouched
  • Topology mode reads live /api/v2/collections/{id}/graphs
  • Semantic mode uses front-end synthetic fixture (no API spec churn)
  • Search / select / detail / filter minimal closed loop (cluster legend + selected-node detail panel + topology shows neighbours)
  • Bench panel exposes 1k / 5k / 10k synthetic-scale generate + first-frame ms
  • Screenshot / video + verbal feel comparison vs react-force-graph-2d — deferred to reviewer-side; bench numbers will be visible in the panel as soon as the page loads
  • License risk surfaced in PoC report — inline in the nav UI

Test plan

  • next dev --turbopack reaches "Ready in 1476ms" cleanly post-add (SSR pass does not load @cosmograph/react)
  • yarn tsc --noEmit → zero errors in the new files. Five pre-existing errors remain in graph/collection-graph*.tsx (from PR Wave 11: dynamic graph entity types #1789 dynamic-entity-types) and are out of scope.
  • Manual: cd web && yarn dev, navigate to /workspace/collections/<id>/graph-lab, flip both modes, screenshot bench panel at each scale.

🤖 Generated with Claude Code

Per @earayu2 ask in #Graph可视化 (msg=4a8309e4): one menu page where
the team can flip between visualisation experiments without leaving
the production graph routes alone. The first two embedded modes are
both Cosmograph (`@cosmograph/react` 2.x): a topology renderer that
consumes the live `/api/v2/collections/{id}/graphs` payload, and a
semantic-map renderer that visualises a deterministic synthetic
fixture at 1k / 5k / 10k point scales for FPS benchmarking. The nav
also links out to the existing `/graph` and `/graph-showcase`
production pages so all four can be compared in adjacent tabs.

Why a PoC sibling instead of overwriting `graph-showcase`:
`graph-showcase/` already carries 745 LOC of an earlier
`react-force-graph-2d` exploration (see
`collection-graph-showcase.tsx`); replacing it would lose the prior
visual probe. PM ratified the new sibling path in DM (msg=30e30aab).

License caveat surfaced inline in the nav: `@cosmograph/react` is
CC-BY-NC-4.0 — explicitly fine for a PoC per @earayu2 (msg=26e5530d)
but flagged as a productionisation gate. The MIT-licensed
`@cosmos.gl/graph` engine is the intended swap target if the
visual direction sticks.

Files:
- `web/src/app/workspace/collections/[collectionId]/graph-lab/page.tsx`
  Server component, breadcrumbs + container layout (mirror of
  `graph-showcase/page.tsx`).
- `…/graph-lab/collection-graph-lab.tsx` Client shell, wires the nav
  to one of two embedded renderers.
- `…/graph-lab/graph-lab-nav.tsx` Left rail with mode tabs +
  external page links + license note.
- `…/graph-lab/cosmograph-topology.tsx` Live KG → Cosmograph Graph
  mode. `dynamic({ ssr: false })` keeps the WebGL renderer out of the
  server pass. Detail panel reuses cluster legend + selected-node
  metadata.
- `…/graph-lab/cosmograph-semantic-map.tsx` Synthetic fixture →
  Cosmograph embedding mode (`pointXBy`/`pointYBy` set, simulation
  off). Scale toggle bench panel exposes generate-time + first-frame
  latency for the 1k/5k/10k presets.
- `…/graph-lab/lab-modes.ts` Tiny shared module so the server-side
  page.tsx stays import-light.
- `web/src/features/knowledge-graph/cosmograph-adapter.ts` Pure data
  transform, `KnowledgeGraph → {points, links, clusterLabels}`. Two
  entry points (`toTopologyDataset` for live data,
  `buildSyntheticSemanticDataset` for deterministic fixture) so the
  PoC can rebuild reproducibly under different scales.

§K.12 invariant cross-check
============================
Largely n/a (frontend exploratory PoC). Direct hits:
- #11 (read-only / not auto-action) — the lab page is read-only;
  no merge/curate surface added.
- #12 (grep-zero LightRAG) — `rg -i lightrag web/src` returns zero
  hits both before and after.

4-pattern pre-check matrix
==========================
- Pattern 1 v1 (existing graph routes): the production
  `/graph` page (`collection-graph.tsx`) and the prior
  `/graph-showcase` page are not modified; no imports moved or
  renamed. `rg "from '\\..*collection-graph(-showcase)?'"` returns
  only the original page bindings.
- Pattern 1 v2 (data-shape consumers): the new adapter consumes
  `KnowledgeGraph`/`GraphNode`/`GraphEdge` from
  `@/features/knowledge-graph/types` — same source the existing
  graph page uses. No type duplication.
- Pattern 2 (response-shape change list): n/a, no API or schema
  touched.
- Pattern 3 (additive helpers): the adapter and synthetic fixture
  generator live in `features/knowledge-graph/`; both are pure
  functions so the production graph page can adopt them later
  without circular imports.

simple-stable directive 4-guardrail
===================================
- #1 不无限扩范围 — explicit PoC scope per @ziang acceptance
  (msg=4db79b66). No backend changes; no `/api/v2/...` additions;
  semantic mode uses front-end fixture data only.
- #2 尽快上线 — single-PR ship, ~0.5 day work envelope.
- #3 简单稳定 — production routes (`/graph`, `/graph-showcase`)
  are byte-identical before/after this commit; PoC lives in its
  own directory.
- #4 私有化部署免维护 — no operator config introduced. The
  Cosmograph dependency is bundled with the rest of the web app;
  productionisation will need a license decision (called out in
  the nav UI itself so reviewers see it).

Test plan
=========
- `next dev --turbopack` reaches "Ready in 1476ms" cleanly post-add
  (verified locally; SSR pass does not load `@cosmograph/react`).
- `yarn tsc --noEmit` reports zero errors in the new files
  (`graph-lab/**`, `cosmograph-adapter.ts`). Five pre-existing
  errors remain in `graph/collection-graph*.tsx` from PR #1789
  and are out of scope.
- Manual smoke deferred to reviewer-side; the bench panel logs
  generate-time + first-frame latency for the three scale presets
  on render so a screenshot at each scale is enough to satisfy the
  PoC acceptance items.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@earayu earayu merged commit 538831d into main Apr 28, 2026
10 checks passed
@earayu earayu deleted the feat/web-graph-cosmograph-poc branch April 28, 2026 10:48
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