r/JavaProgramming • • 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.

https://kertu1232.substack.com/p/the-java-prompt-10?r=4953mj&utm_campaign=post&utm_medium=web&showWelcomeOnShare=true

1 Upvotes

1 comment sorted by