MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / getAugmentedContext

Function getAugmentedContext

packages/baseai/src/utils/memory/lib.ts:112–134  ·  view source on GitHub ↗
({
	similarChunks,
	messages
}: {
	similarChunks: SimilarChunk[];
	messages: Message[];
})

Source from the content-addressed store, hash-verified

110};
111
112export const getAugmentedContext = ({
113 similarChunks,
114 messages
115}: {
116 similarChunks: SimilarChunk[];
117 messages: Message[];
118}) => {
119 if (similarChunks.length === 0) return '';
120
121 const memoryContext = similarChunks
122 .map(chunk => `${chunk.text} \n\n Source: ${chunk.attributes.docName}`)
123 .join('\n\n');
124
125 // Extract Rag prompt from the messages.
126 const ragMsg = messages.find(m => m.role === 'system' && m.name === 'rag');
127 // If there is no rag prompt, use the default rag prompt.
128 const ragPrompt = ragMsg?.content || defaultRagPrompt;
129
130 const contextContent = `"""CONTEXT:\n ${memoryContext}"""`;
131 const augmentedContext = `"""${ragPrompt}""" \n\n ${contextContent}`;
132
133 return augmentedContext;
134};
135
136export const addContextFromMemory = async ({
137 messages,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected