Forked from bakit/rag-ultimate
Forked from bakit/rag-ultimate
src / templates / document_context.ts
/**
* Unique marker embedded at the start of every augmented user message.
* Uses Unicode bookmarks (U+00AB/U+00BB) which are extremely unlikely
* to appear naturally in user prompts.
*/
export const RAG_AUGMENTED_MARKER = "\u00AB[RAG]\u00BB";
/**
* Check if a prompt has already been augmented by this plugin.
* Uses startswith for accuracy — the old `includes()` could match
* the marker text appearing in user content (e.g., code snippets).
*/
export function isAlreadyAugmented(prompt: string): boolean {
return prompt.trimStart().startsWith(RAG_AUGMENTED_MARKER);
}
export function buildDocumentContext(args: {
citations: string;
context: string;
memory: string;
prompt: string;
}): string {
const { citations, context, memory, prompt } = args;
return `${RAG_AUGMENTED_MARKER}\n[SYSTEM]\nYou are a grounded retrieval assistant.\nUse only the provided context and memory.\nIf the answer is not in the context, say you do not know.\nDo not invent citations or facts.\nPrefer concise, direct answers.\n\n[MEMORY]\n${memory || "(none)"}\n\n[CITATIONS]\n${citations || "(none)"}\n\n[CONTEXT]\n${context || "(no retrieved context)"}\n\n[USER]\n${prompt}\n`;
}
src / templates / document_context.ts
/**
* Unique marker embedded at the start of every augmented user message.
* Uses Unicode bookmarks (U+00AB/U+00BB) which are extremely unlikely
* to appear naturally in user prompts.
*/
export const RAG_AUGMENTED_MARKER = "\u00AB[RAG]\u00BB";
/**
* Check if a prompt has already been augmented by this plugin.
* Uses startswith for accuracy — the old `includes()` could match
* the marker text appearing in user content (e.g., code snippets).
*/
export function isAlreadyAugmented(prompt: string): boolean {
return prompt.trimStart().startsWith(RAG_AUGMENTED_MARKER);
}
export function buildDocumentContext(args: {
citations: string;
context: string;
memory: string;
prompt: string;
}): string {
const { citations, context, memory, prompt } = args;
return `${RAG_AUGMENTED_MARKER}\n[SYSTEM]\nYou are a grounded retrieval assistant.\nUse only the provided context and memory.\nIf the answer is not in the context, say you do not know.\nDo not invent citations or facts.\nPrefer concise, direct answers.\n\n[MEMORY]\n${memory || "(none)"}\n\n[CITATIONS]\n${citations || "(none)"}\n\n[CONTEXT]\n${context || "(no retrieved context)"}\n\n[USER]\n${prompt}\n`;
}