LiSSA implements a sophisticated caching system to improve performance and ensure reproducibility of results. The caching system consists of the following components:
-
Cache Interface (
cachepackage) -
Cache Implementations
LocalCache: File-based cache implementation that stores data in JSON format- Implements dirty tracking to optimize writes
- Automatically saves changes on shutdown
- Supports atomic writes using temporary files
RedisCache: Redis-based cache implementation with fallback to local cache- Uses Redis for high-performance caching
- Falls back to local cache if Redis is unavailable
- Supports both string and object serialization
-
Cache Management
CacheManager: Central manager for cache instances- Manages cache directory configuration
- Provides singleton access to cache instances
- Handles cache creation and retrieval
-
Caching Usage The caching system is used in several key components:
- Embedding Creators: Caches vector embeddings to avoid recalculating them
- Classifiers: Caches LLM responses for classification tasks
- Preprocessors: Caches preprocessing results for text summarization and other operations
-
Configuration
{ "cache_dir": "./cache/path" // Directory for cache storage } -
Redis Setup To use Redis for caching, you need to set up a Redis server. Here's a recommended Docker Compose configuration:
services: redis: image: redis/redis-stack:latest container_name: redis restart: unless-stopped ports: - "127.0.0.1:6379:6379" # Redis server port - "127.0.0.1:5540:8001" # RedisInsight web interface volumes: - ./redis_data:/data # Persistent storage
The Redis server will be available at
redis://localhost:6379. You can also access the RedisInsight web interface athttp://localhost:5540for monitoring and management.To use Redis with LiSSA:
- Start the Redis server using Docker Compose
- The system will automatically use Redis if available
- If Redis is unavailable, it will fall back to local file-based caching
-
Best Practices
- Use the cache directory specified in the configuration
- Clear the cache directory if you encounter issues
- For production environments:
- Use Redis for better performance
- Configure Redis persistence for data durability
- Monitor Redis memory usage
- Set up Redis replication for high availability
- Monitor cache size and implement cleanup strategies if needed