LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。
TypeScript
feat: knowledge graph shows relationship strength on edges
nash_sue67a196e1b56
diff --git a/src/components/graph/graph-view.tsx b/src/components/graph/graph-view.tsxindex d9bea334..d45bf83a 100644--- a/src/components/graph/graph-view.tsx+++ b/src/components/graph/graph-view.tsx@@ -82,13 +82,22 @@ function GraphLoader({ nodes, edges }: { nodes: GraphNode[]; edges: GraphEdge[]})}+ // Calculate max weight for normalization+ const maxWeight = Math.max(...edges.map((e) => e.weight), 1)+for (const edge of edges) {if (graph.hasNode(edge.source) && graph.hasNode(edge.target)) {const edgeKey = `${edge.source}->${edge.target}`if (!graph.hasEdge(edgeKey) && !graph.hasEdge(`${edge.target}->${edge.source}`)) {+ const normalizedWeight = edge.weight / maxWeight // 0..1+ const size = 0.5 + normalizedWeight * 3.5 // 0.5..4+ // Stronger relationships → darker color+ const alpha = Math.round(40 + normalizedWeight * 180) // 40..220+ const color = `rgba(100,116,139,${alpha / 255})` // slate-500 with variable opacitygraph.addEdgeWithKey(edgeKey, edge.source, edge.target, {- color: "#cbd5e1",- size: 1,+ color,+ size,+ weight: edge.weight,})}}@@ -326,7 +335,7 @@ export function GraphView() {<SigmaContainerstyle={{ width: "100%", height: "100%", background: "transparent" }}settings={{- renderEdgeLabels: false,+ renderEdgeLabels: true,defaultEdgeColor: "#cbd5e1",defaultNodeColor: "#94a3b8",labelSize: 13,@@ -353,11 +362,15 @@ export function GraphView() {const result = { ...attrs }if (attrs.dimmed) {result.color = "#f1f5f9"- result.size = 0.5+ result.size = 0.3}if (attrs.highlighted) {- result.color = "#475569"- result.size = 2.5+ // Highlighted edges: show stronger with weight-based thickness+ const w = attrs.weight ?? 1+ result.color = "#1e293b"+ result.size = Math.max(2, (attrs.size ?? 1) * 1.5)+ result.label = `relevance: ${w.toFixed(1)}`+ result.forceLabel = true}return result},diff --git a/src/lib/wiki-graph.ts b/src/lib/wiki-graph.tsindex d462146d..deb00e56 100644--- a/src/lib/wiki-graph.ts+++ b/src/lib/wiki-graph.ts@@ -1,5 +1,6 @@import { readFile, listDirectory } from "@/commands/fs"import type { FileNode } from "@/types/wiki"+import { buildRetrievalGraph, calculateRelevance } from "./graph-relevance"export interface GraphNode {id: string@@ -12,6 +13,7 @@ export interface GraphNode {export interface GraphEdge {source: stringtarget: string+ weight: number // relevance score between source and target}const WIKILINK_REGEX = /\[\[([^\]|]+?)(?:\|[^\]]+?)?\]\]/g@@ -122,17 +124,40 @@ export async function buildWikiGraph(}}- // Deduplicate edges (keep only unique source->target pairs)+ // Deduplicate edgesconst seenEdges = new Set<string>()- const edges: GraphEdge[] = []+ const dedupedEdges: { source: string; target: string }[] = []for (const edge of rawEdges) {const key = `${edge.source}:::${edge.target}`- if (!seenEdges.has(key)) {+ const reverseKey = `${edge.target}:::${edge.source}`+ if (!seenEdges.has(key) && !seenEdges.has(reverseKey)) {seenEdges.add(key)- edges.push(edge)+ dedupedEdges.push(edge)}}+ // Calculate relevance weights using the retrieval graph+ let retrievalGraph: Awaited<ReturnType<typeof buildRetrievalGraph>> | null = null+ try {+ const { useWikiStore } = await import("@/stores/wiki-store")+ const dv = useWikiStore.getState().dataVersion+ retrievalGraph = await buildRetrievalGraph(projectPath, dv)+ } catch {+ // ignore — weights will default to 1+ }++ const edges: GraphEdge[] = dedupedEdges.map((e) => {+ let weight = 1+ if (retrievalGraph) {+ const nodeA = retrievalGraph.get(e.source)+ const nodeB = retrievalGraph.get(e.target)+ if (nodeA && nodeB) {+ weight = calculateRelevance(nodeA, nodeB, retrievalGraph)+ }+ }+ return { source: e.source, target: e.target, weight }+ })+const nodes: GraphNode[] = Array.from(nodeMap.values()).map((n) => ({id: n.id,label: n.label,