Semantic Similarity Cache for LLM & RAG Pipelines
“What is your refund policy?” costs $0.003 the first time—it should cost $0.0000 every time after that. Unlike string-matching caches, LongCache uses local BGE embeddings and FAISS to recognize paraphrased queries, verifies tenant and corpus scope to prevent cache poisoning, and serves cached answers in milliseconds.
pip install longcacheLocal semantic embeddings, strict multi-tenant request scoping, and singleflight concurrency control.
Local BAAI/bge-small-en-v1.5 embeddings + FAISS Flat/HNSW search recognize paraphrased queries and serve answers in milliseconds.
Composite SHA-256 keys isolate tenant, user, provider, model, prompt version, and corpus version to eliminate cross-tenant cache poisoning.
Coalesces identical concurrent in-flight requests via `get_or_compute`, `aget_or_compute`, and `@cache.cached` to prevent LLM stampedes.
Zero-dependency SQLite WAL mode by default, durable Redis response storage, multi-process Shared Redis mode, and In-Memory for CI/CD.
Invalidate by tag within scoped contexts, override per-entry TTLs, and automatically rebuild FAISS indexes after sweeps and evictions.
Includes `@cache.cached`, OpenAI SDK replay, FastAPI middleware, LangChain/LangGraph/LlamaIndex wrappers, and the `longcache` CLI.
The Long Suite covers the full production AI lifecycle. LongParser prepares your documents. LongTrainer builds the chatbot. LongTracer verifies the answers. LongProbe tests the retrieval. LongGuard protects runtime agent loops. LongCache eliminates repetitive token costs.
View the Long Suite ecosystemWe build enterprise RAG and agent systems using the full Long Suite stack. Book a free discovery call to discuss your requirements.