Skip to content

[P0-Enhancement] Add embedding cache with Redis backend #69

@VirtualAgentics

Description

@VirtualAgentics

Description

Implement Redis-based embedding cache to reduce provider costs and improve performance by caching computed embeddings.

Background

This enhancement complements Issues #51 (persistence) and #52 (Redis) by adding a caching layer for embeddings, reducing API calls to external providers and improving response times.

Requirements

  • Implement Redis-based embedding cache
  • Cache key format: (model_id, sha256(content))
  • Add cache TTL configuration
  • Implement cache invalidation strategies
  • Add cache hit/miss metrics
  • Add cache size monitoring
  • Implement cache warming strategies

Implementation Details

Files to modify:

  • src/contextforge_memory/cache/ - New caching module
  • src/contextforge_memory/embeddings/ - Add cache integration
  • src/contextforge_memory/config.py - Add cache configuration
  • tests/ - Add cache tests
  • README.md - Document cache configuration

Technical approach:

  • Create embedding cache service with Redis backend
  • Implement cache-aside pattern for embeddings
  • Add cache key generation with content hashing
  • Implement cache metrics and monitoring
  • Add cache configuration options

Acceptance Criteria

  • Embeddings are cached correctly with proper keys
  • Cache hit rate improves performance measurably
  • Cache TTL and invalidation work correctly
  • Cache metrics are tracked and exposed
  • Configuration is flexible and documented

Testing Requirements

  • Unit tests for cache operations
  • Integration tests with Redis
  • Performance tests for cache benefits
  • Cache invalidation tests

Documentation Updates

  • README.md - Document cache configuration
  • Performance guide - Cache benefits
  • Configuration examples - Cache setup
  • Monitoring guide - Cache metrics

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions