fix(wiki): strip internal chunk aliases from page content

Wiki ingest prompts previously encouraged inline [cNNN] citations that
leak internal chunk metadata into reader-facing Markdown. Strip legacy
aliases on read/write paths and update the modify prompt to keep prose
clean while source links remain in ChunkRefs.
This commit is contained in:
wizardchen
2026-07-13 13:24:19 +08:00
committed by lyingbug
parent 07ba01ec93
commit eacc278b9a
5 changed files with 76 additions and 8 deletions
+4 -4
View File
@@ -318,10 +318,10 @@ Now apply the instructions above to the chunks and output ONLY the JSON.`
// WikiPageModifyPrompt updates an existing wiki page with new additions and removes stale/deleted information in a single pass.
const WikiPageModifyPrompt = `You are a wiki editor tasked with updating an existing wiki page. You must process a set of NEW information to add, AND/OR a set of deleted documents whose exclusive contributions must be REMOVED.
### STRICT CITATION & MERGE RULES (CRITICAL):
1. **Preserve Citations:** When merging new information with existing content, you MUST strictly preserve all existing inline chunk citations (e.g., [c003]).
2. **Mandatory Tracing:** Any newly added factual claim, entity, or numerical data MUST be followed by an inline citation to the appropriate new source chunk (e.g., [c003]).
3. **No Hallucination:** Do not invent, synthesize, or infer any information that is not explicitly present in the provided source chunks. If the new chunks clearly and directly supersede or contradict existing content, update the main text to reflect the newer cited information AND add a brief "Contradictions / Updates" section summarizing the change. If the conflict is ambiguous, unresolved, or not directly supported by the provided chunks, do not overwrite the existing content; instead, add only a "Contradictions / Updates" section describing the conflict with citations.
### SOURCE GROUNDING & MERGE RULES (CRITICAL):
1. **No Inline Chunk IDs:** Chunk aliases such as [c003] are internal processing metadata. NEVER output them in the page body or summary, and remove any legacy inline chunk aliases from existing content while editing. Source associations are stored separately by the system.
2. **Mandatory Grounding:** Every newly added factual claim, entity, or numerical value MUST be directly supported by the provided new source chunks, but the final prose must remain clean Markdown without inline chunk IDs.
3. **No Hallucination:** Do not invent, synthesize, or infer any information that is not explicitly present in the provided source chunks. If the new chunks clearly and directly supersede or contradict existing content, update the main text to reflect the newer supported information AND add a brief "Contradictions / Updates" section summarizing the change. If the conflict is ambiguous, unresolved, or not directly supported by the provided chunks, do not overwrite the existing content; instead, add only a "Contradictions / Updates" section describing the conflict.
<page_metadata>
<slug>{{.PageSlug}}</slug>
+18
View File
@@ -123,3 +123,21 @@ func TestWikiChunkCitationPrompt_PreservesPlaceholders(t *testing.T) {
}
}
}
func TestWikiPageModifyPrompt_HidesInternalChunkAliases(t *testing.T) {
for _, guidance := range []string{
"NEVER output them in the page body or summary",
"Source associations are stored separately by the system",
"clean Markdown without inline chunk IDs",
} {
if !strings.Contains(WikiPageModifyPrompt, guidance) {
t.Errorf("WikiPageModifyPrompt missing chunk-alias guidance %q", guidance)
}
}
for _, obsolete := range []string{"Preserve Citations", "followed by an inline citation"} {
if strings.Contains(WikiPageModifyPrompt, obsolete) {
t.Errorf("WikiPageModifyPrompt still contains obsolete inline-citation rule %q", obsolete)
}
}
}