Memory-Augmented RAG
Combining document retrieval with structured agent knowledge.
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.
- Knowledge retriever — fetch relevant structured agent knowledge 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 structured agent knowledge from LocusGraph
const knowledge = 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
${knowledge.map(m => m.payload.value).join('\n\n')}
## User Question
${userQuery}
`;What Structured Agent Knowledge Adds
Documents tell you what exists. Structured agent knowledge tells you what works.
| Source | Provides |
|---|---|
| Documents | API specs, guides, reference material |
| LocusGraph | Past mistakes, user preferences, learned patterns, graduated skills |
A document might say "use retry logic for network calls." LocusGraph 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 replace your existing RAG pipeline — you augment it with validated agent knowledge.
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, LocusGraph learns which document combinations answer which question types. RAG gets smarter with every interaction.