Memory-Augmented RAG
Combining document retrieval with stored wisdom.
Beyond Standard RAG
Standard RAG retrieves documents. Memory-augmented RAG also retrieves agent experience. The result: context that includes not just what the documents say, but what the agent has learned from working with them.
The Pattern
Retrieve from two sources, combine in the prompt:
- Document retriever — fetch relevant docs from your vector DB.
- Wisdom retriever — fetch relevant memories from LocusGraph.
- Combine — merge both into the agent's context window.
// 1. Retrieve documents (your existing RAG pipeline)
const docs = await vectorDB.search({
query: userQuery,
limit: 5,
});
// 2. Retrieve agent wisdom from LocusGraph
const wisdom = await client.retrieveMemories({
query: userQuery,
limit: 5,
});
// 3. Combine in prompt
const prompt = `
## Relevant Documents
${docs.map(d => d.content).join('\n\n')}
## Agent Knowledge
${wisdom.map(m => m.payload.value).join('\n\n')}
## User Question
${userQuery}
`;What Wisdom Adds
Documents tell you what exists. Wisdom tells you what works.
| Source | Provides |
|---|---|
| Documents | API specs, guides, reference material |
| Wisdom graph | Past mistakes, user preferences, learned patterns, successful approaches |
A document might say "use retry logic for network calls." The wisdom graph adds "exponential backoff with a 3-second base works best for this API — linear retry caused rate limiting last week."
LocusGraph's semantic search works alongside any vector database. You do not need to replace your existing RAG pipeline — you augment it.
Storing RAG Outcomes
Close the loop by storing what the agent learns from each RAG interaction:
// After answering, store what worked
await client.storeEvent({
graph_id: 'support-bot',
event_kind: 'observation',
source: 'agent',
context_id: 'rag:effectiveness',
payload: { topic: 'query_pattern', value: 'Users asking about auth need both the setup guide and the troubleshooting doc' },
});Over time, the wisdom graph learns which document combinations answer which question types. RAG gets smarter with every interaction.