Skip to content

WIP - Redis/semantic caching advisor and chat memory #2982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

markpollack
Copy link
Member

Thank you for taking time to contribute this pull request!
You might have already read the [contributor guide][1], but as a reminder, please make sure to:

  • Sign the contributor license agreement
  • Rebase your changes on the latest main branch and squash your commits
  • Add/Update unit tests as needed
  • Run a build and make sure all tests pass prior to submission

bsbodden and others added 2 commits May 3, 2025 16:02
…ntations

Add comprehensive Redis-backed features to enhance Spring AI:

* 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.

Signed-off-by: Brian Sam-Bodden <bsb@redis.com>
@markpollack markpollack requested a review from joshlong May 3, 2025 20:44
@markpollack markpollack changed the title Redis/semantic caching advisor and chat memory WIP - Redis/semantic caching advisor and chat memory May 3, 2025
@markpollack
Copy link
Member Author

not sure why the semantic cache IT doesn't connect to redis.

bsbodden added a commit to bsbodden/spring-ai that referenced this pull request May 4, 2025
…nectivity

  Refactor Redis-based chat memory implementation to:
  - Implement ChatMemoryRepository interface as requested in PR spring-projects#2295
  - Fix Redis connection issues in integration tests reported in PR spring-projects#2982
  - Optimize conversation ID lookup with server-side deduplication
  - Add configurable result limits to avoid Redis cursor size limitations
  - Implement robust fallback mechanism for query failures
  - Enhance support for metadata, toolcalls, and media in messages
  - Add comprehensive test coverage with reliable Redis connections
bsbodden added a commit to bsbodden/spring-ai that referenced this pull request May 4, 2025
…nectivity

  Refactor Redis-based chat memory implementation to:
  - Implement ChatMemoryRepository interface as requested in PR spring-projects#2295
  - Fix Redis connection issues in integration tests reported in PR spring-projects#2982
  - Optimize conversation ID lookup with server-side deduplication
  - Add configurable result limits to avoid Redis cursor size limitations
  - Implement robust fallback mechanism for query failures
  - Enhance support for metadata, toolcalls, and media in messages
  - Add comprehensive test coverage with reliable Redis connections

  Signed-off-by: Brian Sam-Bodden <brian@redis.com>
bsbodden added a commit to bsbodden/spring-ai that referenced this pull request May 4, 2025
…nectivity

  Refactor Redis-based chat memory implementation to:
  - Implement ChatMemoryRepository interface as requested in PR spring-projects#2295
  - Fix Redis connection issues in integration tests reported in PR spring-projects#2982
  - Optimize conversation ID lookup with server-side deduplication
  - Add configurable result limits to avoid Redis cursor size limitations
  - Implement robust fallback mechanism for query failures
  - Enhance support for metadata, toolcalls, and media in messages
  - Add comprehensive test coverage with reliable Redis connections

Signed-off-by: Brian Sam-Bodden <brian@redis.com>
bsbodden added a commit to bsbodden/spring-ai that referenced this pull request May 4, 2025
…nectivity

  Refactor Redis-based chat memory implementation to:
  - Implement ChatMemoryRepository interface as requested in PR spring-projects#2295
  - Fix Redis connection issues in integration tests reported in PR spring-projects#2982
  - Optimize conversation ID lookup with server-side deduplication
  - Add configurable result limits to avoid Redis cursor size limitations
  - Implement robust fallback mechanism for query failures
  - Enhance support for metadata, toolcalls, and media in messages
  - Add comprehensive test coverage with reliable Redis connections

Signed-off-by: Brian Sam-Bodden <bsb@redis.com>
@bsbodden
Copy link

bsbodden commented May 4, 2025

not sure why the semantic cache IT doesn't connect to redis.

I'm on it Mark! - prelim PR #2991

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants