Skip to content

⚡ feat(synapse): Caffeine cache — embedding, provider response, query result caching #173

Description

@sbharatjoshi

Summary

Build Caffeine cache infrastructure to optimize performance and reduce LLM provider costs. This includes caching for embeddings, provider responses, and semantic search results.


🏛️ Caching Layers

1. Embedding Cache (embeddingCache)

  • Key: SHA-256(text + model)
  • Value: float[] vector
  • TTL: 24h

2. LLM Response Cache (llmResponseCache)

  • Key: Hash(system_prompt + user_input + params)
  • Value: String response
  • TTL: 1h

3. Search Cache (searchCache)

  • Key: Hash(query + topK + threshold)
  • Value: List<SearchResult>
  • TTL: 10m (with eviction on memory store)

✅ Acceptance Criteria

  • CaffeineCacheManager is configured with dedicated specs for each cache type.
  • LlmBridge and MemoryService use Spring's @Cacheable annotations.
  • GET /api/v1/system/cache/stats returns hit/miss rates and eviction counts.
  • POST /api/v1/system/cache/clear invalidates all caches.
  • Automated tests verify that redundant calls bypass the bridge/engine.

🚀 Contributor Guidance

  1. Add spring-boot-starter-cache and caffeine to pom.xml.
  2. Create com.spectrayan.spector.synapse.config.CacheConfig.
  3. Update SynapseProperties to include spector.cache.* settings.
  4. Apply annotations to LlmBridge and MemoryService.

RICE-C Score

Factor Score Rationale
Reach 3/5 Performance improvement
Impact 2x Latency reduction
Effort M ~2 days

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions