feat(llm): implement intelligent Redis caching layer for narratives (fixes #335) - #496
Merged
Merged
Conversation
Contributor
Author
|
Hi @eshaanag! I have implemented the intelligent Redis caching layer for LLM narratives as requested in #335. Technical Work Done:
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.pybackend/features/llm_analysis/router.pybackend/requirements.txtdocker-compose.ymlChanges Made
get_cached_narrativeandset_cached_narrativeutilizingredis.asynciowith deterministic SHA256 cache keys.claude_client.pyandrouter.pyto 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.rediscontainer definition todocker-compose.ymland updatedbackend/requirements.txtwithredis>=5.0.0.Outcode
LLM API costs and request latency are now drastically lowered by retrieving identical analysis batches directly from memory.