Feature/llm cache redis semantic issue 362#417
Open
Francis6-git wants to merge 3 commits into
Open
Conversation
|
@Francis6-git Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Description
Implements an optimized, provider-agnostic semantic caching layer for LLM responses under #362. To achieve the required sub-50ms lookup performance without introducing heavy external vector database dependencies, this implementation leverages an inline Python cosine similarity calculation engine sweeping a bounded window of recent candidates managed through Redis Sorted Sets (
ZSET).Technical Architecture
astroml/cache/llm_semantic_cache.py): Candidate lookups are pinned directly toZSETblocks by target LLM models ({namespace}:idx:{model}:all). New completions are logged with chronological epoch milliseconds as their tracking scores.zremrangebyrankto safeguard operational memory constraints and ensure O(log(N)) execution timelines.astroml/llm/llm_cached_client.py): Exposes an expandableLLMProviderstructurally typed protocol and an underlyingLLMEmbeddingProviderconstructor to support hot-swapping embedding models natively without breaking API pipelines.hits,misses) along with high-precisiontime.perf_counter()calculations via Redis pipelines, automatically generating calculated hit rates and average lookup latency execution times.Validation Status against Acceptance Criteria
1. Lookup Latency SLA (< 50ms)
candidate_top_kthreshold configuration payload safely constrains linear_cosine_similarityiteration times.pipeline()batches to minimize round-trip connection overheads.2. Targeted Cache Hit Rate (> 40%)
LLM_CACHE_SIMILARITY_THRESHOLD(defaults to0.88) allowing runtime matching optimization parameters across text structures.Closes #362