The pattern
- User asks a question.
- Embed the question.
- Retrieve top-k similar entries from vector store.
- Prepend retrieved context to the prompt.
- Model answers using the retrieved context.
Advertisement
Wiring in ADK Java
public class MemoryEnabledAgent extends LlmAgent {
private final VectorStore memory;
@Override
protected void beforeModelCall(AgentContext ctx) {
String q = ctx.currentUserMessage();
List hits = memory.search(q, TOP_K);
ctx.prependContext(formatAsContext(hits));
}
} Advertisement
What to store
Not every message. Distill each session down to key facts, user preferences, and outcomes. Store those.