oh, hello
back to projects

Semantic Cache for LLMs

A FastAPI semantic cache that uses pgvector retrieval and cross-encoder validation to safely reuse LLM responses.

01 / overview

Built with intent.

A scoped semantic cache for LLM responses. It embeds incoming queries, retrieves the nearest non-expired pgvector candidates through an HNSW index, then validates them with a cross-encoder before returning a cached response. Entries are scoped by model, temperature, prompt fingerprint, and embedding version; misses call the configured LLM and are stored with expiry and least-recently-used eviction.