Skip to content

feat : : implement session-based local caching to reduce redundant Su…#143

Open
Soniyakmt wants to merge 2 commits into
sugarlabs:mainfrom
Soniyakmt:new-branch
Open

feat : : implement session-based local caching to reduce redundant Su…#143
Soniyakmt wants to merge 2 commits into
sugarlabs:mainfrom
Soniyakmt:new-branch

Conversation

@Soniyakmt
Copy link
Copy Markdown

fixes #87
summary:
Added local response caching for GenAI to reduce repeated Sugar-AI requests and improve response speed for repeated questions.

What changed
I had made: Added [cache.py] with an LRU-style [ResponseCache]
and Updated [gguf_inference.py] to:

  • Use a session-level response cache

  • return cached answers for identical questions

  • store successful and blocked responses in the cache

  • Limit the cache size to avoid unbounded memory growth

  • Coverage: Caches both successful responses and blocked profanity responses.

  • Caching Logic: Normalises question text (lowercase, trimmed), uses SHA256 for keys, and limits cache size to prevent memory issues.

  • Updated: [gguf_inference.py] - Integrates caching into [GGUFInference.ask_question()] to check for cached responses before generating new ones.

Note
: Cache keys are normalised to ignore extra whitespace/casing
. If persistence is enabled via [cache_file], the cache can survive restarts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Add local response caching for repeated LLM queries in GenAI module

1 participant