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
fix: preserve subject boundaries in generated context
nash_su1312525ef543
diff --git a/src/components/chat/chat-panel.tsx b/src/components/chat/chat-panel.tsxindex bd7a74c1..3c1991e9 100644--- a/src/components/chat/chat-panel.tsx+++ b/src/components/chat/chat-panel.tsx@@ -381,6 +381,8 @@ export function ChatPanel() {? "- Answer based ONLY on the numbered wiki pages and external sources provided below.": "- Answer based ONLY on the numbered wiki pages provided below.","- If the provided pages don't contain enough information, say so honestly.",+ "- Keep subject boundaries strict: do not apply a claim, limitation, evaluation, benchmark result, or recommendation about one entity/model/product/method to another subject just because they share keywords.",+ "- If pages or external sources discuss multiple subjects, attribute each claim to the exact subject named in that page or source; when uncertain, state the uncertainty instead of generalizing.","- Use [[wikilink]] syntax to reference wiki pages.",externalContext? "- When citing wiki information, use page numbers like [1], [2]. When citing external information, use external source IDs like [E1], [E2]."diff --git a/src/lib/ingest.prompt.test.ts b/src/lib/ingest.prompt.test.tsindex 88d0351a..c74f2f8f 100644--- a/src/lib/ingest.prompt.test.ts+++ b/src/lib/ingest.prompt.test.ts@@ -2,6 +2,7 @@ import { describe, it, expect, beforeEach } from "vitest"import {buildAnalysisPrompt,buildGenerationPrompt,+ buildPageMergeSystemPrompt,computeIngestGenerationMaxTokens,computeIngestReviewMaxTokens,computeIngestSourceBudget,@@ -46,6 +47,12 @@ describe("buildAnalysisPrompt language directive", () => {expect(prompt).toContain("## Main Arguments & Findings")expect(prompt).toContain("## Recommendations")})++ it("requires claims to stay attached to their named subject", () => {+ const prompt = buildAnalysisPrompt("", "", "")+ expect(prompt).toContain("Which named subject is each claim about")+ expect(prompt).toContain("Do not transfer claims, limits, or evaluations")+ })})describe("buildGenerationPrompt language directive", () => {@@ -93,6 +100,14 @@ describe("buildGenerationPrompt language directive", () => {expect(prompt).not.toContain("No exceptions — not even for page names")})+ it("tells generation to preserve subject and source boundaries", () => {+ const prompt = buildGenerationPrompt("", "", "", "source.pdf")++ expect(prompt).toContain("Preserve subject boundaries")+ expect(prompt).toContain("Do not merge or generalize a claim about one subject into another subject's page")+ expect(prompt).toContain("cite which source/frontmatter `sources` entry supports that statement")+ })+it("makes project schema routing authoritative over default entity and concept folders", () => {const prompt = buildGenerationPrompt("Use wiki/people/ for people. Use wiki/technologies/ for technical methods.",@@ -136,6 +151,18 @@ describe("analysis + generation prompt consistency", () => {})})+describe("page merge prompt", () => {+ it("keeps comparisons attribution-exact instead of folding them into the main subject", () => {+ const prompt = buildPageMergeSystemPrompt()+ expect(prompt).toContain("Both versions target the same wiki page")+ expect(prompt).toContain("may mention additional subjects for comparison or context")+ expect(prompt).toContain("keep those comparisons attribution-exact")+ expect(prompt).toContain("do not fold them into claims about the main page subject")+ expect(prompt).toContain("prefer keeping them separate")+ expect(prompt).not.toContain("describe the same entity")+ })+})+describe("long-source ingest planning", () => {it("scales generation output tokens with the configured context window", () => {expect(computeIngestGenerationMaxTokens(64_000)).toBe(8_192)diff --git a/src/lib/ingest.ts b/src/lib/ingest.tsindex 69dda850..71121622 100644--- a/src/lib/ingest.ts+++ b/src/lib/ingest.ts@@ -1769,6 +1769,7 @@ export function buildAnalysisPrompt(purpose: string, index: string, sourceConten"- What are the core claims or results?","- What evidence supports them?","- How strong is the evidence?",+ "- Which named subject is each claim about? Do not transfer claims, limits, or evaluations from one entity/model/product/method to another just because they share keywords.","","## Connections to Existing Wiki","- What existing pages does this source relate to?",@@ -1885,6 +1886,9 @@ export function buildGenerationPrompt("Other rules:","- Use [[wikilink]] syntax in the BODY for cross-references between pages","- If you include images, use wiki-root-relative paths such as `media/source-slug/image.png`; never output absolute filesystem paths.",+ "- Preserve subject boundaries: when a source discusses multiple entities/models/products/methods, keep claims, evaluations, limitations, benchmark results, and recommendations attached to the exact subject they describe.",+ "- Do not merge or generalize a claim about one subject into another subject's page solely because they share terms (for example context window size, benchmark name, dataset, architecture, or feature name).",+ "- If a page needs to mention another subject for comparison, write it explicitly as a comparison and cite which source/frontmatter `sources` entry supports that statement.","- Use kebab-case filenames","- Derive filenames from the page title in the mandatory output language, but short proper nouns and technical identifiers take precedence: preserve names such as OpenAI, GPT-5, Transformer, CLIP, ImageNet, PyTorch, CUDA, GitHub, arXiv, React, LanceDB, AnyTXT, MinerU, model names, dataset names, tool names, and code identifiers in their standard original form. Do not put raw URLs, citation strings, or full paper titles directly into file paths; convert surrounding descriptive prose to a safe readable title. For Chinese/Japanese/Korean prose titles, keep readable CJK characters in the filename instead of translating the slug to English.","- Follow the analysis recommendations on what to emphasize",@@ -2541,26 +2545,7 @@ async function analyzeLongSourceInChunks(*/function buildPageMerger(llmConfig: LlmConfig): MergeFn {return async (existingContent, incomingContent, sourceFileName, signal) => {- const systemPrompt = [- "You are merging two versions of the same wiki page into one coherent document.",- "Both versions describe the same entity / concept; one is already on disk,",- "the other was just generated from a different source document.",- "",- "Output ONE merged version that:",- "- Preserves every factual claim from both versions (do not drop content)",- "- Eliminates redundancy when both versions state the same fact",- "- Reorganizes sections so the structure is logical for the merged topic,",- " not just a concatenation of the two inputs",- "- Uses consistent markdown structure (headings, tables, lists, callouts)",- "- Keeps `[[wikilink]]` references intact",- "",- "Output requirements:",- "- The FIRST character of your response MUST be `-` (the opening of `---`)",- "- Output the COMPLETE file: YAML frontmatter + body",- "- No preamble (no \"Here is the merged version:\"), no analysis prose",- "- The caller will overwrite `sources`/`tags`/`related`/`updated` with",- " deterministic values — your job is the body and any other fields",- ].join("\n")+ const systemPrompt = buildPageMergeSystemPrompt()const userMessage = [`## Existing version on disk`,@@ -2611,6 +2596,33 @@ function buildPageMerger(llmConfig: LlmConfig): MergeFn {}}+export function buildPageMergeSystemPrompt(): string {+ return [+ "You are merging two versions of the same wiki page into one coherent document.",+ "Both versions target the same wiki page; one is already on disk,",+ "the other was just generated from a different source document.",+ "Either version may mention additional subjects for comparison or context.",+ "",+ "Output ONE merged version that:",+ "- Preserves every factual claim from both versions (do not drop content)",+ "- Eliminates redundancy when both versions state the same fact",+ "- Preserves subject/source boundaries: if either version mentions other entities/models/products/methods for comparison, keep those comparisons attribution-exact and do not fold them into claims about the main page subject",+ "- When claims conflict or apply to different subjects, keep them separated and say which source version supports each one instead of synthesizing a single generalized conclusion",+ "- When in doubt whether two similar-looking claims describe the same fact, prefer keeping them separate",+ "- Reorganizes sections so the structure is logical for the merged topic,",+ " not just a concatenation of the two inputs",+ "- Uses consistent markdown structure (headings, tables, lists, callouts)",+ "- Keeps `[[wikilink]]` references intact",+ "",+ "Output requirements:",+ "- The FIRST character of your response MUST be `-` (the opening of `---`)",+ "- Output the COMPLETE file: YAML frontmatter + body",+ "- No preamble (no \"Here is the merged version:\"), no analysis prose",+ "- The caller will overwrite `sources`/`tags`/`related`/`updated` with",+ " deterministic values — your job is the body and any other fields",+ ].join("\n")+}+/*** Best-effort snapshot of a page before a fallback merge overwrites* it. Saved to `.llm-wiki/page-history/<sanitized-path>-<timestamp>.md`