#!/usr/bin/env python3 """ Knowledge Universe — Cache Warmup Script Pre-populates cache with the most common queries. Usage: python scripts/warmup_cache.py """ import asyncio import httpx import sys API_BASE = "http://localhost:8000" API_KEY = "ku_test_warmup" # Replace with valid key WARMUP_TOPICS = [ ("machine learning", 2), ("transformer architecture", 3), ("RAG retrieval augmented generation", 3), ("python data science", 2), ("LLMOps deployment", 4), ("credit scoring models", 3), ("fraud detection machine learning", 3), ("neural networks introduction", 1), ("attention mechanism", 3), ("vector databases", 3), ] async def warmup(): print(f"Warming up {len(WARMUP_TOPICS)} queries...\n") async with httpx.AsyncClient(timeout=60) as client: for topic, difficulty in WARMUP_TOPICS: try: resp = await client.post( f"{API_BASE}/v1/discover", headers={"X-API-Key": API_KEY}, json={"topic": topic, "difficulty": difficulty, "formats": ["pdf", "github", "stackoverflow"], "max_results": 5} ) status = "✓" if resp.status_code == 200 else "✗" data = resp.json() results = data.get("total_found", 0) print(f"{status} [{difficulty}] {topic} → {results} results") except Exception as e: print(f"✗ {topic}: {e}") await asyncio.sleep(1) # Be polite to upstream APIs print("\nWarmup complete.") if __name__ == "__main__": asyncio.run(warmup())