Beyond Vector Similarity: A Two-Stage Safety-Aware Semantic Caching Architecture for Large Language Model Gateways

Large Language Model (LLM) gateways rely heavily on semantic caching to reduce inference latency and computational cost by reusing responses for semantically similar queries. However, conventional single-stage semantic caches that depend solely on dense vector cosine similarity are structurally vulnerable to false-positive cache hits. High vector similarity frequently fails to distinguish logical negations, antonym substitutions, subtle parameter shifts, and safety-critical boundary conditions—resulting in contextually incorrect or unsafe cached responses being served to users. This paper presents a two-stage safety-aware semantic caching architecture designed for production LLM gateways. Stage 1 performs fast approximate nearest-neighbor retrieval using dense vector embeddings (pgvector) to identify candidate cache entries above an initial similarity threshold. Stage 2 introduces a deterministic safety and intent verification gate that evaluates structural divergence, negation tokens, and policy boundaries before confirming a cache hit. By decoupling fast candidate retrieval from strict semantic equivalence verification, the proposed architecture significantly reduces false-positive cache hits on adversarial and edge-case prompts while maintaining low end-to-end latency overhead.

Authors

Publication Details

Journal
Zenodo (CERN European Organization for Nuclear Research)
Published
2026-11-10
DOI
https://doi.org/10.5281/zenodo.24097814
Primary Topic
Topic Modeling
Type
preprint
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
NOV
preprint

Beyond Vector Similarity: A Two-Stage Safety-Aware Semantic Caching Architecture for Large Language Model Gateways

MappillaiMeeran A
Zenodo (CERN European Organization for Nuclear Research)
Topic Modeling
preprint

Beyond Vector Similarity: A Two-Stage Safety-Aware Semantic Caching Architecture for Large Language Model Gateways

MappillaiMeeran A
preprint en

Abstract

Large Language Model (LLM) gateways rely heavily on semantic caching to reduce inference latency and computational cost by reusing responses for semantically similar queries. However, conventional single-stage semantic caches that depend solely on dense vector cosine similarity are structurally vulnerable to false-positive cache hits. High vector similarity frequently fails to distinguish logical negations, antonym substitutions, subtle parameter shifts, and safety-critical boundary conditions—resulting in contextually incorrect or unsafe cached responses being served to users. This paper presents a two-stage safety-aware semantic caching architecture designed for production LLM gateways. Stage 1 performs fast approximate nearest-neighbor retrieval using dense vector embeddings (pgvector) to identify candidate cache entries above an initial similarity threshold. Stage 2 introduces a deterministic safety and intent verification gate that evaluates structural divergence, negation tokens, and policy boundaries before confirming a cache hit. By decoupling fast candidate retrieval from strict semantic equivalence verification, the proposed architecture significantly reduces false-positive cache hits on adversarial and edge-case prompts while maintaining low end-to-end latency overhead.

Zenodo (CERN European Organization for Nuclear Research)
Topic Modeling
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

Laika access coming soon