Status: [UNTESTED] Endpoints found: http://127.0.0.1:8088/v1/chat/completions Source: https://github.com/Ashwin-180803/Kindred # Kindred **Proposal:** put a semantic cache in front of our LLM calls. **Headline from the attached load test:** a drop-in caching layer that reduced LLM API costs by **64.8%** and cut hit P95 to **10ms** vs **200ms** uncached on a **2,000-request** mix. The same mix at 1M GPT-4o calls/month is about **$3,140** not sent to the provider. This is not a tutorial. It is the system, the numbers, and the deploy path. ## Problem We already pay for prompts we have answered. Exact string keys miss the obvious duplicates: "What is Python?" and "Explain Python to me" are the same job. Every miss is latency plus tokens. At GPT-4o list prices, a mid-length call is about $0.00485. A 65% redundant workload on 1M calls is thousands of dollars a month and hundreds of milliseconds on every repeat. ## What ships A FastAPI proxy that speaks the OpenAI chat completions contract. Point `base_url` at Kindred. No caller code changes. On each request: 1. Hash the **system prompt** and generation params (`model`, `temperature`, `max_tokens`, provider). That tuple is the partition. Two identical user prompts with different system prompts do not share a row. 2. Embed the user prompt (`text-embedding-3-small` in production, signed n-gram hashing on a laptop). 3. Cosine nearest neighbor in that partition. Default threshold **0.95**. Hit: return the stored completion and `X-Kindred-Cache: HIT`. Miss: forward, then store the full provider payload (usage, finish reason, model id) with TTL metadata. Streaming: hits replay as SSE immediately. Misses stream through from the provider and are written only if the assembled response finishes cleanly (`stop` / `length`). Providers: OpenAI, Anthropic (normalized back to OpenAI shape), Ollama. The cache is provider-agnostic; an OpenAI row is never served for a Claude model. ## Policy | Task | Threshold | TTL | Cache? | |---|---|---|---| | Classification | 0.90 | 24h | yes | | Factual / general | 0.95 | 24h | yes | | Time-sensitive | 0.95 | 1h |