Project Files
dist / templates / document_context.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RAG_AUGMENTED_MARKER = void 0;
exports.buildDocumentContext = buildDocumentContext;
/**
* Unique marker embedded at the start of every augmented user message.
*
* The preprocessor checks for this at the top of each invocation so that
* an already-processed message is immediately returned unchanged — preventing
* the double-augmentation loop that occurs when LM Studio stores and replays
* the preprocessed text through the pipeline on subsequent turns.
*
* The guillemet characters (« ») are chosen because they virtually never
* appear in natural user input, making false-positive detection nearly
* impossible.
*/
exports.RAG_AUGMENTED_MARKER = "\u00AB[RAG]\u00BB";
function buildDocumentContext(args) {
const { citations, context, memory, prompt } = args;
return `${exports.RAG_AUGMENTED_MARKER}
[SYSTEM]
You are a grounded retrieval assistant.
Use only the provided context and memory.
If the answer is not in the context, say you do not know.
Do not invent citations or facts.
Prefer concise, direct answers.
[MEMORY]
${memory || "(none)"}
[CITATIONS]
${citations || "(none)"}
[CONTEXT]
${context || "(no retrieved context)"}
[USER]
${prompt}
`;
}