๐งชTDD Challengeยทintermediateยทโฑ๏ธ 30โ45mยทโญ 200 XP
M-060Build a Semantic Cache for LLM Requests
Description
Nebula Corp is spending too much on LLM API calls. Many requests are semantically similar โ 'What is Python?' and 'Explain Python' should return the same cached response. Build a semantic cache that uses cosine similarity between embeddings to match similar prompts. If a new prompt is similar enough to a cached one (above a threshold), return the cached response instead of calling the LLM.
Test Cases (3)
Cache miss on empty
Empty cache should return null
Input:testCacheMiss()
Expected:null
Cache hit on similar prompt
Similar prompts should return cached response
Input:testCacheHit()
Expected:CONTAINS:Python is a programming language
Tracks stats
Stats should report entries and hits
Input:testStats()
Expected:CONTAINS:entries
Related Lessons
Click Run / Check to validate your solution