Queries are embedded with nomic-embed-text and stored as high-dimensional vectors in ChromaDB. On each new query, the embedding is computed and the top-k nearest neighbors are fetched by cosine similarity. If the closest match exceeds the 0.92 threshold, the stored answer is returned instantly — no LLM call.
- Threshold tunable via
CACHE_SIMILARITY_THRESHOLDenv var - Async embedding via thread pool — never blocks FastAPI event loop
- Cache grows passively; every answered query seeds future hits
- ChromaDB persists to disk across restarts (
cache/data/chromadb/)