Skip to main content

Module semantic_cache

Module semantic_cache 

Source
Expand description

§Semantic Cache

LRU-evicting similarity cache for prompt/response pairs.

Prompts are embedded into a 64-dimensional TF-IDF-style vector using FNV-1a token hashing, then L2-normalised. Cache lookup returns a stored response if the cosine similarity between the query embedding and any stored embedding is at or above the configured threshold.

Structs§

CacheEntry
A single entry stored in the SemanticCache.
CacheStats
Aggregate statistics for a SemanticCache.
SemanticCache
LRU-evicting semantic similarity cache.

Functions§

cosine_similarity
Cosine similarity between two equal-length vectors.
embed_prompt
Produce a deterministic TF-IDF-style 64-dim embedding for prompt.