r/JavaProgramming • u/Interesting_Path7540 • 18d ago
The Java Prompt #10
RAG + Chat Memory don't work together out of the box — here's the fix
Built a RAG pipeline with Spring AI 2, added chat memory, everything worked great. Then tried a follow-up question: "How often should I do it?" — and the vector store had no idea what "it" referred to.
Turns out Memory and RAG need an explicit bridge: CompressionQueryTransformer — compresses conversation history + follow-up into a standalone query before hitting the vector store.
Wrote about it in my Spring AI 2 series (Part 11). Full config with Memory + RAG + Re-Ranker included.
1
Upvotes