Skip to content

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

refactor: Save to Wiki uses lightweight wikilink enrichment instead of full auto-ingest

nash_su2cf576cfc551
diff --git a/src/components/chat/chat-message.tsx b/src/components/chat/chat-message.tsx
index a96a6b0f..002d8d53 100644
--- a/src/components/chat/chat-message.tsx
+++ b/src/components/chat/chat-message.tsx
@@ -12,6 +12,7 @@ import type { DisplayMessage } from "@/stores/chat-store"
import type { FileNode } from "@/types/wiki"
import { convertLatexToUnicode } from "@/lib/latex-to-unicode"
+import { enrichWithWikilinks } from "@/lib/enrich-wikilinks"
// Module-level cache of source file names
let cachedSourceFiles: string[] = []
@@ -185,12 +186,11 @@ function SaveToWikiButton({ content, visible }: { content: string; visible: bool
setSaved(true)
setTimeout(() => setSaved(false), 2000)
- // Auto-ingest the saved query to generate entities/concepts/cross-references
+ // Lightweight cross-referencing: ask LLM to add [[wikilinks]] to the saved content
const llmConfig = useWikiStore.getState().llmConfig
if (llmConfig.apiKey || llmConfig.provider === "ollama") {
- const { autoIngest } = await import("@/lib/ingest")
- autoIngest(project.path, filePath, llmConfig).catch((err) =>
- console.error("Failed to auto-ingest saved query:", err)
+ enrichWithWikilinks(project.path, filePath, llmConfig).catch((err) =>
+ console.error("Failed to enrich with wikilinks:", err)
)
}
} catch (err) {
diff --git a/src/lib/enrich-wikilinks.ts b/src/lib/enrich-wikilinks.ts
new file mode 100644
index 00000000..df881016
--- /dev/null
+++ b/src/lib/enrich-wikilinks.ts
@@ -0,0 +1,70 @@
+import { readFile, writeFile } from "@/commands/fs"
+import { streamChat } from "./llm-client"
+import { useWikiStore, type LlmConfig } from "@/stores/wiki-store"
+import { LANGUAGE_RULE } from "./ingest"
+
+/**
+ * Lightweight post-save enrichment: ask LLM to add [[wikilinks]] to a saved wiki page.
+ * Much cheaper than full auto-ingest — no new pages created, just cross-references added.
+ */
+export async function enrichWithWikilinks(
+ projectPath: string,
+ filePath: string,
+ llmConfig: LlmConfig,
+): Promise<void> {
+ const [content, index] = await Promise.all([
+ readFile(filePath),
+ readFile(`${projectPath}/wiki/index.md`).catch(() => ""),
+ ])
+
+ if (!content || !index) return
+
+ // Quick LLM call: just add wikilinks, don't change content
+ let enriched = ""
+
+ await streamChat(
+ llmConfig,
+ [
+ {
+ role: "system",
+ content: [
+ "You are a wiki cross-referencing assistant.",
+ "Your ONLY job: add [[wikilinks]] to the text where entities or concepts from the wiki index are mentioned.",
+ "",
+ LANGUAGE_RULE,
+ "",
+ "Rules:",
+ "- Return the COMPLETE text with [[wikilinks]] added.",
+ "- Do NOT change any content, only add [[ and ]] around existing words that match wiki pages.",
+ "- Do NOT add new text, summaries, or explanations.",
+ "- Do NOT remove or modify any existing text.",
+ "- Preserve all YAML frontmatter exactly as-is.",
+ "- Only link to pages that exist in the wiki index below.",
+ "- Each page should be linked only on first mention.",
+ "",
+ `## Wiki Index (link to these pages)\n${index}`,
+ ].join("\n"),
+ },
+ {
+ role: "user",
+ content: `Add [[wikilinks]] to this wiki page:\n\n${content}`,
+ },
+ ],
+ {
+ onToken: (token) => { enriched += token },
+ onDone: () => {},
+ onError: () => {},
+ },
+ )
+
+ if (!enriched || enriched.length < content.length * 0.5) {
+ // LLM returned something too short — probably an error, don't overwrite
+ return
+ }
+
+ // Write the enriched version back
+ await writeFile(filePath, enriched)
+
+ // Refresh graph
+ useWikiStore.getState().bumpDataVersion()
+}