Skip to content

feat(llm): implement intelligent Redis caching layer for narratives (fixes #335) - #496

Merged
eshaanag merged 1 commit into
eshaanag:mainfrom
Diwakar-odds:feat/issue-335-llm-cache
Sep 1, 2026
Merged

feat(llm): implement intelligent Redis caching layer for narratives (fixes #335)#496
eshaanag merged 1 commit into
eshaanag:mainfrom
Diwakar-odds:feat/issue-335-llm-cache

Conversation

@Diwakar-odds

Copy link
Copy Markdown
Contributor

Summary

This PR implements an intelligent Redis-based caching layer for LLM narrative generation, significantly reducing redundant LLM API calls and mitigating rate-limit exhaustion for repetitive commits. Fixes #335.

Files Modified

  • backend/features/llm_analysis/cache.py (NEW)
  • backend/features/llm_analysis/claude_client.py
  • backend/features/llm_analysis/router.py
  • backend/requirements.txt
  • docker-compose.yml

Changes Made

  • Redis Cache Abstraction: Added get_cached_narrative and set_cached_narrative utilizing redis.asyncio with deterministic SHA256 cache keys.
  • LLM Bypass: Modified claude_client.py and router.py to check the Redis cache prior to database lookups or LLM invocation. Upon cache hit, returns the pre-generated explanation and calculates cost as $0.0.
  • Infrastructure: Added a redis container definition to docker-compose.yml and updated backend/requirements.txt with redis>=5.0.0.

Outcode

LLM API costs and request latency are now drastically lowered by retrieving identical analysis batches directly from memory.

@github-actions github-actions Bot added the backend Backend changes label Sep 1, 2026
@Diwakar-odds

Copy link
Copy Markdown
Contributor Author

Hi @eshaanag! I have implemented the intelligent Redis caching layer for LLM narratives as requested in #335.

Technical Work Done:

  • Integrated
    edis.asyncio\ to intercept identical analysis requests based on SHA256 hashes of the commit diffs and metadata.
  • Updated \claude_client.py\ and
    outer.py\ to hit the Redis cache prior to querying the database or external APIs, bypassing the slow and expensive network hops.
  • Re-architected the \LLMProvider\ tracking to appropriately record \cache\ usage with zero cost implications.
  • Added Redis to the local \docker-compose.yml\ and \�ackend/requirements.txt\ for frictionless onboarding.

Because this change introduces an architectural infrastructure component (Redis cache layer) and optimizes core backend performance to drastically reduce API token exhaust, it maps directly to Level 3 (Core/Architecture/Performance).

Could you please assign the \ECSoC26, \Level 3, and \good-backend\ labels? Thank you!

@eshaanag eshaanag added ECSoC26 Required tag — marks PR as counted for ECSoC 2026 scoring ECSoC26-L2 Medium — 10 pts (auto-applied by Sentinel) good-pr Bonus XP: exceptional PR (+15 XP) labels Sep 1, 2026
@eshaanag
eshaanag merged commit 432686e into eshaanag:main Sep 1, 2026
15 of 19 checks passed
@ecsoc-sentinel ecsoc-sentinel Bot added ECSoC26-L2 Medium — 10 pts (auto-applied by Sentinel) and removed ECSoC26-L2 Medium — 10 pts (auto-applied by Sentinel) labels Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend changes ECSoC26-L2 Medium — 10 pts (auto-applied by Sentinel) ECSoC26 Required tag — marks PR as counted for ECSoC 2026 scoring good-pr Bonus XP: exceptional PR (+15 XP)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Implement intelligent caching layer for LLM narrative generation

2 participants