A semantic cache middleware: embeds prompts, serves cached responses for semantically similar prompts, forwards misses to a mock model. Node/TS + Redis (vector search) + React.
Runs in 3 modes:
- Local — Redis in Docker, services run directly via
tsx. - Docker — every service in its own container on a shared Docker network.
- Kubernetes — deployed to a cluster from
k8s/manifests.
A miss ("how do I sort an array in javascript?") costs a ~2500ms model call; a reworded prompt ("js array sorting") is served from cache in single-digit ms, matched by embedding similarity.
Requires Node 20+ and Docker Desktop.
Install dependencies:
npm install
cd dashboard & npm install & cd ..Build the image (Docker and Kubernetes modes only):
docker build -t semantic-cache:v1 .Start Redis:
docker run -d --name redis-local -p 6379:6379 -p 8001:8001 redis/redis-stack:latestRedisInsight: http://localhost:8001/redis-stack/browser
Start services (separate terminals):
npx tsx ai-model-server.ts
npx tsx cache-server.ts
cd dashboard & npm run devDashboard: http://localhost:5173
Test from dashboard, or use Powershell:
Invoke-RestMethod -Uri http://localhost:3000/ask -Method Post -ContentType "application/json" -Body '{"prompt":"how do I sort an array in javascript?"}'
Invoke-RestMethod -Uri http://localhost:3000/statsdocker network create scdemo
docker run -d --name redis-local --network scdemo -p 8001:8001 redis/redis-stack:latest
docker run -d --name mock-model --network scdemo semantic-cache:v1 node dist/ai-model-server.js
docker run -d --name cache --network scdemo -p 3000:3000 -e REDIS_URL=redis://redis-local:6379 -e MODEL_URL=http://mock-model:4000 semantic-cache:v1Dashboard: http://localhost:3000
Apply:
kubectl apply -f k8s/Check:
kubectl get pods -w
kubectl logs deploy/semantic-cacheExpose service locally:
kubectl port-forward svc/semantic-cache 3000:80Dashboard: http://localhost:3000
Teardown:
kubectl delete -f k8s/