How kartik-707/semantic-cache-gateway works
Semantic Cache Gateway is a policy-governed FastAPI front door for compatible chat APIs. A client request is validated, matched to a feature policy, and checked for cache eligibility and compatibility. Eligible requests try Redis exact lookup, then local embeddings and Qdrant semantic search; the decision logic either serves a cached response or lets the gateway call the provider. Successful eligible responses can be written to both stores. The README also documents cache seeding and Prometheus metrics. Some links are based on README descriptions or SOURCE INDEX references because the relevant implementation excerpts are incomplete.
Main entry points: proxy.py Chat Gateway · cache_store.py Exact Cache · vector_store.py Vector Store · cache_rules.py Compatibility Rules
Components 21
Gateway API
- Chat Gateway
gateway/proxy.py - Provider Adapter
gateway/adapter.py - Cache Seeding
gateway/proxy.py - Metrics Endpoint
gateway/metrics.py
Policy and Contracts
- Policy Loader
intelligence/policy_loader.py - Feature Policies
policies - Policy Contract
contracts/policy.py - Chat Contracts
contracts/proxy.py - Cache Entry
contracts/cache.py - Decision Metadata
contracts/decision.py - Near-Miss Record
contracts/near_miss.py
Cache Runtime
- Compatibility Rules
gateway/cache_rules.py - Exact Cache
gateway/cache_store.py - Vector Store
gateway/vector_store.py
Semantic Matching
- Local Embeddings
intelligence/embeddings.py - Similarity Decisions
intelligence/similarity.py
Other components
- Chat Client
- Chat Provider
- Prometheus
- Redis
- Qdrant
Connections 27
- Chat Client → Chat Gateway: submits chat
README.md - Chat Gateway → Chat Contracts: validates
gateway/proxy.py - Chat Gateway → Policy Loader: loads policy
gateway/proxy.py - Policy Loader → Feature Policies: reads YAML
intelligence/policy_loader.py - Policy Loader → Policy Contract: validates against
intelligence/policy_loader.py - Chat Gateway → Compatibility Rules: builds context
gateway/proxy.py - Compatibility Rules → Policy Contract: uses policy
gateway/cache_rules.py - Chat Gateway → Exact Cache: looks up exact
gateway/proxy.py - Exact Cache → Redis: reads and writes
README.md - Exact Cache → Compatibility Rules: uses context
gateway/cache_store.py - Chat Gateway → Local Embeddings: embeds prompt
gateway/proxy.py - Chat Gateway → Vector Store: searches candidates
gateway/proxy.py - Vector Store → Qdrant: queries and stores
README.md - Vector Store → Compatibility Rules: filters by context
gateway/vector_store.py - Chat Gateway → Similarity Decisions: decides semantic hit
gateway/proxy.py - Similarity Decisions → Decision Metadata: produces decision
intelligence/similarity.py - Chat Gateway → Decision Metadata: returns cache metadata
gateway/proxy.py - Chat Gateway → Provider Adapter: forwards misses
gateway/proxy.py - Provider Adapter → Chat Provider: calls API
README.md - Chat Gateway → Vector Store: stores eligible result
gateway/proxy.py - Chat Gateway → Exact Cache: stores eligible result
gateway/proxy.py - Chat Gateway → Cache Entry: creates entries
gateway/proxy.py - Cache Seeding → Local Embeddings: embeds seeded prompt
gateway/proxy.py - Cache Seeding → Exact Cache: stores seeded answer
gateway/proxy.py - Cache Seeding → Vector Store: stores seeded answer
gateway/proxy.py - Chat Gateway → Metrics Endpoint: exposes metrics
gateway/proxy.py - Metrics Endpoint → Prometheus: exports counters
README.md