Caching π‘ BETA
The LLM cache in botllm reuses a stored answer when a new prompt matches an earlier one exactly or, when enabled, by configured semantic similarity.
Features
Two matching paths exist: an exact key based on the prompt, and a semantic search over cached embeddings. Similarity checks are bounded by max_similarity_checks; TTL expiry is handled by the cache component. Settings are read per bot through ConfigManager.
How Caching Works
CacheConfig holds ttl, semantic_matching, similarity_threshold, max_similarity_checks and key_prefix. For a bot, with_db_pool.rs reads the keys below and returns a per-bot configuration before deciding whether to answer from cache.
Configuration
| Key | Read by | Default in code | Effect |
|---|---|---|---|
llm-cache |
with_db_pool.rs |
true |
Enables the cache for the bot. |
llm-cache-ttl |
with_db_pool.rs |
3600 |
Seconds before an entry expires. |
llm-cache-semantic |
with_db_pool.rs |
false |
Enables similarity matching. |
llm-cache-threshold |
with_db_pool.rs |
0.95 |
Minimum similarity for a semantic hit. |
embedding-url, embedding-model |
embedding config | see source | Supply vectors for semantic matching. |
CacheConfig also fixes max_similarity_checks = 100 and key_prefix = "llm_cache"; these are not bot-configurable keys.
Conversation History Management
Episodic memory is a separate mechanism, configured by episodic-memory-history and episodic-memory-threshold; see Episodic Memory. It compacts history, not cached answers.
Cache Storage
Exact keys live in the cache component; semantic matching compares a new prompt's embedding against stored vectors. No administrative clear endpoint is registered in the source; expiry is automatic through TTL.
Use
' Caching is applied by the LLM path, not by a BASIC keyword.
' First similar question stores the answer; a later match can reuse it.
TALK "What is the vacation policy?"
Limits
- Semantic matching is off unless
llm-cache-semanticis explicitly true for the bot. - Cached answers can be stale until their TTL expires.
- Semantic matching needs a working embedding configuration; otherwise only exact matching applies.
- No verified manual cache-clear endpoint exists.
Related
- Chapter overview - Index of this chapter.
See Also
- Episodic Memory - History compaction
- Configuration Parameters - Bot keys
- AI and LLM - Provider configuration