feat(redis): Add Redis-based semantic caching and chat memory implementations
-
Add semantic caching for chat responses:
- SemanticCache interface and Redis implementation using vector similarity
- SemanticCacheAdvisor for intercepting and caching chat responses
- Uses vector search to cache and retrieve responses based on query similarity
- Support for TTL-based cache expiration
- Improves response times and reduces API costs for similar questions
-
Add Redis-based chat memory implementation:
- RedisChatMemory using RedisJSON + RediSearch for conversation storage
- Configurable RedisChatMemoryConfig with builder pattern support
- Message TTL, ordering, multi-conversation and batch operations
- Efficient conversation history retrieval using RediSearch indexes
-
Add integration tests:
- Comprehensive test coverage using TestContainers
- Tests for semantic caching features and chat memory operations
- Integration test for RedisVectorStore with VectorStoreChatMemoryAdvisor
- Verify chat completion augmentation with vector store content
The Redis implementations enable efficient storage and retrieval of chat responses and conversation history, with semantic search capabilities and configurable persistence options.
/cc @jruaux
Signed-off-by: Brian Sam-Bodden [email protected]
Looks good! Thanks @bsbodden. @tzolov Can we get this merged?
@bsbodden thank you so much for this! We have just delivered some changes to the ChatMemory API which include the introduction of a ChatMemoryRepository API to separate the two different concerns: memory management strategy and storage mechanism. For example, the JdbcChatMemory has now been superseded by JdbcChatMemoryRepository. It would be great if we could use the new approach directly for Redis.
Upgrade Notes: https://docs.spring.io/spring-ai/reference/upgrade-notes.html#_chat_memory New Chat Memory Docs: https://docs.spring.io/spring-ai/reference/api/chat-memory.html PR with the change: https://github.com/spring-projects/spring-ai/pull/2890
@bsbodden thank you so much for this! We have just delivered some changes to the
ChatMemoryAPI which include the introduction of aChatMemoryRepositoryAPI to separate the two different concerns: memory management strategy and storage mechanism. For example, theJdbcChatMemoryhas now been superseded byJdbcChatMemoryRepository. It would be great if we could use the new approach directly for Redis.Upgrade Notes: https://docs.spring.io/spring-ai/reference/upgrade-notes.html#_chat_memory New Chat Memory Docs: https://docs.spring.io/spring-ai/reference/api/chat-memory.html PR with the change: #2890
@ThomasVitale I will make the needed changes and re-submit the branch! Thanks for looking into this. Cheers!
In the meantime I rebased the PR and am a bit stuck - see https://github.com/spring-projects/spring-ai/pull/2982
As thomas mentioned, we will definitely need to separate this out into multiple modules, but in the meantime, if @bsbodden you could look at the reworked PR to see what is broken, that would be a big help.
Thanks for the PR, I've been meaning to get to it for a while.
Thanks, it's been a while. Would like to get this in for 1.1 M1
Thanks, it's been a while. Would like to get this in for 1.1 M1
BTW, the latest is here https://github.com/spring-projects/spring-ai/pull/2991
@markpollack I thought this was making it into 1.1 - could you help us understand what is missing to get this merged? Thank you!
Hi, What's missing is between keyboard and monitor. There has just been so much of a flurry of activity good things like this get lost. We are going to 'sneak' it into 1.1.1 despite the patch release nature. I'll be working on this today and will ping if I have questions. My sincere apologies!
closing in favor of #2991