DEV.co
AI Frameworks · zilliztech

GPTCache

GPTCache is a semantic caching layer for LLM queries that reduces API costs and latency by storing and retrieving similar responses from a local cache instead of re-querying the LLM. It integrates directly with LangChain and llama_index, supporting both exact-match and semantic similarity-based cache retrieval.

Source: GitHub — github.com/zilliztech/GPTCache
8.1k
GitHub stars
582
Forks
Python
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryzilliztech/GPTCache
Ownerzilliztech
Primary languagePython
LicenseMIT — OSI-approved
Stars8.1k
Forks582
Open issues91
Latest release0.1.44 (2024-08-01)
Last updated2025-07-11
Sourcehttps://github.com/zilliztech/GPTCache

What GPTCache is

GPTCache provides a Python library for semantic caching of LLM responses using embeddings and vector similarity search. It supports multiple backend storage options (SQLite, Milvus, Redis), embedding models (ONNX, OpenAI), and pluggable similarity evaluation, allowing developers to intercept LLM calls and serve cached responses when similarity thresholds are met.

Quickstart

Get the GPTCache source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/zilliztech/GPTCache.gitcd GPTCache# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

High-traffic LLM applications

Reduces per-request API costs and latency for applications with repetitive or semantically similar queries, particularly useful when serving chatbots or retrieval-augmented generation (RAG) systems with recurring question patterns.

Cost-sensitive LLM deployments

Ideal for cost-conscious organizations using expensive closed-source LLM APIs (OpenAI, etc.) where even a 10-20% cache hit rate significantly reduces monthly API spend without degrading user experience.

Local semantic search integration

Enables organizations to build self-hosted semantic caching without relying on proprietary cache services, with fine-grained control over embedding models, similarity thresholds, and backend storage (FAISS, Milvus, Redis).

Implementation considerations

  • Choose appropriate embedding model (ONNX for local inference, OpenAI embeddings for accuracy) balancing latency, cost, and accuracy of semantic similarity.
  • Configure similarity evaluation threshold and post-processing (e.g., temperature_softmax) to control cache hit rate vs. response freshness trade-off.
  • Select backend storage (SQLite for single-server, Milvus/Redis for distributed) based on scale, multi-tenancy needs, and existing infrastructure.
  • Monitor cache hit rates, embedding latency, and backend performance to validate cost savings and identify queries that should bypass cache.
  • Plan for cache invalidation strategy (TTL, manual refresh) to manage staleness, especially for time-sensitive domains.

When to avoid it — and what to weigh

  • Requires guarantees of freshness or real-time data — Caching introduces staleness; responses from cache may not reflect the latest information. Not suitable for applications where real-time accuracy is critical (live data, legal compliance, dynamic pricing).
  • Low query volume or highly unique queries — Cache benefits diminish if each query is semantically unique or traffic is sparse. Setup and maintenance overhead may outweigh cost savings for low-volume or bespoke LLM usage.
  • Strict compliance or audit trail requirements — Cached responses may complicate audit trails and compliance verification. Organizations needing immutable logs of every LLM interaction should carefully evaluate caching policies and logging integration.
  • Production deployment without infrastructure readiness — README explicitly notes the project is 'under heavy development' and API may change at any time. Production rollout requires careful version pinning and testing to handle breaking changes.

License & commercial use

GPTCache is released under the MIT License, a permissive OSI-approved open-source license. MIT permits commercial use, modification, and distribution with minimal restrictions, requiring only attribution and inclusion of the license.

MIT License clearly permits commercial use without restriction. No proprietary or dual-licensing terms identified in provided data. Suitable for commercial products. Recommend reviewing any custom extensions or dependencies for their own license terms.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationAdequate
License clarityClear
Deployment complexityLow
DEV.co fitGood
Assessment confidenceHigh
Security considerations

Caching layer stores LLM request/response pairs; ensure cached data is not sensitive (PII, secrets, credentials). When using OpenAI API key, verify environment variable handling and credential storage. If using Redis/Milvus backend, secure network access and consider encryption at rest/in-transit. Docker deployments should follow container security best practices. No explicit security audit or vulnerability disclosure process mentioned in provided data.

Alternatives to consider

LangChain built-in LLM caching

LangChain has native LLM caching via `llm_cache` parameter; simpler for LangChain-native workflows but less feature-rich (fewer backend options, no semantic similarity).

Hybrid LLM / Vector DB solutions (Pinecone, Weaviate)

Managed vector databases with native caching capability; outsources infrastructure but adds vendor lock-in and per-token costs; better for teams without infra expertise.

Custom Redis caching layer

Manual implementation of caching around LLM calls; more control but requires engineering effort and ongoing maintenance; suitable for teams with strong backend experience.

Software development agency

Build on GPTCache with DEV.co software developers

Explore GPTCache for your next LLM application. Integration is simple—start with a few lines of Python code. Review the examples and docs to understand caching strategy best suited to your use case.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

GPTCache FAQ

Will GPTCache work with my LLM provider (not OpenAI)?
README states 'we no longer add support for new API or models' due to rapid LLM evolution. Use the generic `get` and `set` API (example provided in repo) to integrate any LLM provider. LangChain adapter supports any LLM integrated with LangChain.
How much can I save on API costs?
README claims '10x cost reduction' and '100x speed boost' but these are not independently verified benchmarks. Actual savings depend on query semantics, cache hit rate, and embedded model cost. Savings scale with query overlap and traffic volume.
Is the API stable for production use?
README explicitly warns 'the repository is still under heavy development' and 'API may be subject to change at any time.' Version is 0.1.44 (pre-1.0), indicating beta maturity. Production use requires version pinning and readiness to absorb breaking changes.
What embedding model should I use?
Options include ONNX (local, free, faster setup) and OpenAI embeddings (higher accuracy, but API cost and latency). Choose based on accuracy requirements and total cost (cache overhead vs. LLM API savings).

Custom software development services

Need help beyond evaluating GPTCache? DEV.co is a software development agency offering software development services and web development for teams of every size. Our software developers and web developers build custom software, web applications, APIs, and ai frameworks integrations — and maintain them long-term.

Ready to reduce LLM costs and latency?

Explore GPTCache for your next LLM application. Integration is simple—start with a few lines of Python code. Review the examples and docs to understand caching strategy best suited to your use case.