MCPcopy Index your code
hub / github.com/Doorman11991/smallcode / getRagContext

Function getRagContext

bin/smallcode.js:2045–2055  ·  view source on GitHub ↗
(messages)

Source from the content-addressed store, hash-verified

2043// Auto-load similar code snippets from the local RAG index. The index is
2044// created with `npm run rag:index` / `smallcode-rag-index` and stays fully local.
2045function getRagContext(messages) {
2046 try {
2047 if (!_ragRetriever) return '';
2048 const lastUser = [...messages].reverse().find(m => m.role === 'user');
2049 if (!lastUser || typeof lastUser.content !== 'string') return '';
2050 const maxChars = Math.min(6000, Math.floor(((config?.context?.detected_window || 32768) * 0.06) * 4));
2051 return _ragRetriever.formatForPrompt(lastUser.content, { limit: 6, maxChars });
2052 } catch {
2053 return '';
2054 }
2055}
2056
2057// Auto-load relevant memory for the current task (injected into system prompt)
2058// Fix #15: Only inject memory objects with score >= 2 (at least 2 word matches)

Callers 2

buildCompactSystemPromptFunction · 0.85
buildDynamicContextFunction · 0.85

Calls 1

formatForPromptMethod · 0.45

Tested by

no test coverage detected