hoangsonww/AI-RAG-Assistant-Chatbot

Knowledge Graph Explorer (Interactive Neo4j Entity/Relationship Visualization in Admin UI)

オープン

#61 opened on 2026/08/08

 (0 件のコメント) (0 件のリアクション) (1 人の担当者)TypeScript (14 件のフォーク)auto 404
bugdocumentationenhancementfeaturegood first issuehelp wantedquestion

Repository metrics

Stars
 (43 個のスター)
PR merge metrics
 (PR metrics pending)

説明

Summary

Add an interactive Knowledge Graph Explorer to the admin UI so admins can visually browse the Neo4j entity/relationship graph that Lumina already builds during ingestion, instead of only seeing aggregate counts via knowledge:graph:status.

Problem

Every knowledge source is chunked, embedded into Pinecone, and run through entity extraction into Neo4j (DocumentChunkEntity, linked by RELATED_TO, see server/src/services/graphKnowledge.ts). Right now the only visibility into that graph is:

  • npm run knowledge:graph:status — four aggregate numbers (documentCount, chunkCount, entityCount, relationshipCount), no detail.
  • npm run knowledge:graph:rebuild[:clean] — blunt, all-or-nothing rebuild.

There's no way to answer basic questions like "what entities did we extract from the profile source?", "is this entity linked to sources it shouldn't be?", or "did the last edit actually change the graph?" without opening the Neo4j AuraDB console directly (which most admins won't have credentials for). This makes the graph side of RAG effectively a black box compared to the vector side, which is now fully visible and editable via the Knowledge Manager UI (#34).

Proposed Solution

Backend (server/src/routes/knowledge.ts, server/src/services/graphKnowledge.ts)

  • Add GET /api/knowledge/graph (admin-only, same requireAdmin gate as the rest of the router):
    • Query params: sourceId (optional filter to one document's subgraph), entityType (optional), limit (capped, e.g. max 500 nodes) to keep responses renderable.
    • Returns a { nodes, edges } payload — nodes typed document | chunk | entity with label/type metadata, edges typed by the existing RELATED_TO relationship (plus Document -[:HAS_CHUNK]-> Chunk / Chunk -[:MENTIONS]-> Entity if those relationship types exist — confirm exact schema in ingestChunksToGraph).
    • Reuse the existing Neo4j session/driver pattern from getGraphStats; do not add a second driver instance.
  • Add GET /api/knowledge/graph/stats as a thin wrapper if the raw counts are still useful standalone (or fold into the payload above under a stats key — avoid two round trips if we can help it).

Frontend (client/src/pages/KnowledgeAdmin.tsx or a new KnowledgeGraphExplorer.tsx)

  • New tab/panel in the Knowledge Manager: "Graph" alongside the existing sources table.
  • Force-directed graph view (e.g. react-force-graph or vis-network, whichever is lighter given the existing bundle-size warning on npm run build) with:
    • Color/shape coded by node type (document, chunk, entity).
    • Click a node → side panel with its properties; clicking a document/chunk node deep-links to that source's edit dialog (reuse openEdit + the GET /api/knowledge/:id endpoint added in #60).
    • Filter dropdown scoped to a single source, and a search box that highlights matching entity names.
    • Empty/disabled state when Neo4j isn't configured (isNeo4jConfigured() === false), matching how the CLI already degrades gracefully.

Docs

  • Document the new endpoint(s) in openapi.yaml.
  • Add a "Graph Explorer" subsection to UPDATE_KNOWLEDGE.md near the existing Architecture Overview / graph troubleshooting sections, and a screenshot to the README's admin UI section.

Acceptance Criteria

  • Admin can open a graph view scoped to "all sources" or a single source and see real nodes/edges pulled from Neo4j, not placeholder data.
  • Graph responses are capped/paginated so a large graph can't hang the browser tab or the Neo4j query.
  • Clicking a document/chunk node navigates to the corresponding source's edit view.
  • The panel degrades to a clear "Graph RAG not configured" message when NEO4J_URI etc. are unset, rather than erroring.
  • openapi.yaml and docs updated to match the shipped endpoint contract.

Out of Scope

  • Editing the graph directly from the visualization (creating/deleting entities or relationships by hand) — read-only explorer for now.
  • Graph algorithms (community detection, shortest path, centrality) — just browsing/filtering.
  • Non-admin access to any graph data.

Suggested Tasks

  • Confirm exact Neo4j relationship types used by ingestChunksToGraph (RELATED_TO and any HAS_CHUNK/MENTIONS types) so the API response is accurate.
  • Add GET /api/knowledge/graph (+ optional /stats) with requireAdmin guard and a hard node-count cap.
  • Add graph visualization panel to the Knowledge Manager admin page.
  • Wire node click-through to existing source edit flow.
  • Handle the Neo4j-not-configured state gracefully in the UI.
  • Update openapi.yaml, UPDATE_KNOWLEDGE.md, and README with the new capability.

コントリビューターガイド