Optimize Configuration

July 16, 2026 · View on GitHub

SuperLocalMemory V3 Documentation https://superlocalmemory.com | Part of Qualixar

Reference for all SLM v3.6 Optimize configuration options.


Config File

Optimize settings are stored in a single JSON file:

~/.superlocalmemory/optimize.json

Runtime behavior: When proxy routes were mounted at daemon startup, cache and compression changes saved through the daemon API reload immediately; direct file edits and standalone CLI writes are detected by the watchdog within 2 seconds. Changing proxy_enabled is different: it is evaluated during daemon startup, so config file changes do not mount proxy routes in an already-running daemon.

Write via:

  • UI — Dashboard → Optimize tab (runtime toggles, TTL sliders, per-provider settings)
  • CLIslm optimize|cache|compress commands
  • APIPUT /api/optimize/config
  • Direct — Edit optimize.json manually

Master Switches

FieldTypeDefaultDescription
enabledboolfalseSDK adapter enablement; it does not gate proxy route mounting
proxy_enabledboolfalseMount proxy routes at daemon startup; changing it requires a daemon restart
config_versionint1Revision written by ConfigStore.save(); it does not trigger hot-reload

Cache Configuration

FieldTypeDefaultDescription
cache_enabledbooltrueEnable cache lookups
semantic_enabledboolfalseEnable vCache semantic cache (opt-in)
semantic_return_thresholdfloat0.98Cosine score threshold for direct return
semantic_verify_lofloat0.90Lower bound for verify-and-rewrite path
semantic_error_targetfloat0.02vCache epsilon — max acceptable error rate
semantic_explore_ratefloat0.10vCache exploration rate
semantic_constant_timeboolfalseEnable side-channel padding (blocks CacheAttack timing-based inference)
semantic_centroid_defensebooltrueEnable SAFE-CACHE centroid defense
semantic_multiturn_guardbooltrueMulti-turn guard — skips semantic after max_turns_for_semantic
semantic_ann_top_kint5ANN search — top-K candidates
semantic_boundary_initfloat0.95Initial semantic-cache decision boundary
semantic_boundary_floorfloat0.85Lowest adaptive semantic-cache boundary
semantic_boundary_ceilingfloat0.995Highest adaptive semantic-cache boundary
semantic_boundary_stepfloat0.01vCache boundary adjustment step
semantic_max_turns_for_semanticint6Max conversation turns before semantic cache is bypassed
semantic_context_window_turnsint3Context window size for multi-turn matching
semantic_centroid_distance_floorfloat0.15Minimum centroid distance for safe return
semantic_verifier_modelstr""Optional model for verify path
semantic_pad_latency_msfloat0Optional latency padding for CacheAttack mitigation
semantic_centroid_min_similarityfloat0.85Minimum centroid similarity for a semantic-cache candidate
semantic_max_index_entriesint10000Maximum semantic-cache index entries
semantic_max_tenantsint10000Maximum semantic-cache tenants

Tuning the semantic tier (read before enabling). The semantic cache is off by default because, unlike the exact cache, a too-loose threshold can return a near-duplicate's answer for a different question (a wrong-answer hit). Recommended rollout:

  1. Start at the default semantic_return_threshold = 0.98 (conservative; targets a sub-1% false-hit rate).
  2. Measure your own false-hit rate before trusting it — enable SLM_OPTIMIZE_CAPTURE=1, collect real traffic, and replay near-duplicate vs. genuinely-different prompt pairs through benchmarks/optimize to see how often a "hit" would have returned the wrong answer.
  3. Only lower the threshold if your measured false-hit rate stays inside semantic_error_target. Raise it (toward 0.99) if you see any wrong hits.

The exact cache (always on when cache_enabled) has zero false-hit risk — it keys on the full system+messages+params hash — so semantic is purely an opt-in recall booster, never a correctness dependency.

Cache TTL

FieldTypeDefaultDescription
ttl.exact_secondsint86400Exact cache TTL (24 hours)
ttl.semantic_secondsint3600Semantic cache TTL (1 hour)
ttl.ccr_secondsint604800CCR originals TTL (7 days)
ttl.sweep_interval_secondsint3600TTL sweep interval (1 hour)

Compression Configuration

FieldTypeDefaultDescription
compress_enabledboolfalseEnable compression
compress_modestr"safe""safe" (lossless whitespace normalization) or "aggressive" (lossy prose allowed)
compress_proseboolfalseProse compression (LLMLingua-2, opt-in)
compress_protect_recentint4Number of most recent messages to skip compression

Layer 1 lossless whitespace normalization runs whenever compression is enabled. Layer 2 prose compression requires compress_mode="aggressive", compress_prose=true, and the optional LLMLingua dependency. The legacy code, ccr, and align compression subcommands and their configuration fields were removed in v3.6.10; they are not active configuration options.


Proxy Configuration

Configured at startup via CLI flags, not in optimize.json:

FlagDefaultDescription
--port8765Proxy server port
--providerauto-detectTarget provider: anthropic, openai, gemini
--no-compressfalseDisable compression (cache only)
--semanticfalseEnable semantic cache on proxy
--jsonfalseJSON output

Pricing Configuration

FieldTypeDefaultDescription
pricing_overridesdict{}Per-provider pricing overrides (e.g. {"anthropic": {"input_per_1m_usd": 3.0, "output_per_1m_usd": 15.0}})
usd_to_inr_ratefloat83.5USD to INR conversion rate
prometheus_portint9091Prometheus metrics port

Default pricing (used when no overrides set):

ProviderInput ($/1M tokens)Output ($/1M tokens)
Anthropic$3.00$15.00
OpenAI$2.50$10.00
Gemini$1.25$10.00

Pricing rules:

  • Cache SKIP saves BOTH input + output tokens (whole call avoided)
  • Compression saves INPUT tokens only (output not compressed)
  • Pricing data older than 90 days is flagged as is_stale: true

Storage Configuration

The optimize module uses a separate SQLite database:

PropertyValue
Database path~/.superlocalmemory/llmcache.db
EncryptionAES-256-GCM with PBKDF2-HMAC-SHA256 key derivation (100K iterations)
File permissionschmod 600
Corruption recoveryInvalid files moved to .corrupt sidecar — fresh DB created
Database managerReuses SLM's DatabaseManager (WAL, busy-timeout, retry)

Isolation: assert_no_memory_db_tables() prevents accidental cross-contamination with memory.db.


Config File Example

{
  "enabled": false,
  "proxy_enabled": false,
  "config_version": 1,
  "cache_enabled": true,
  "semantic_enabled": false,
  "semantic_return_threshold": 0.98,
  "semantic_verify_lo": 0.9,
  "semantic_error_target": 0.02,
  "semantic_explore_rate": 0.1,
  "semantic_centroid_defense": true,
  "semantic_multiturn_guard": true,
  "semantic_ann_top_k": 5,
  "semantic_boundary_init": 0.95,
  "semantic_boundary_floor": 0.85,
  "semantic_boundary_ceiling": 0.995,
  "semantic_centroid_distance_floor": 0.15,
  "semantic_pad_latency_ms": 0,
  "semantic_centroid_min_similarity": 0.85,
  "semantic_max_index_entries": 10000,
  "semantic_max_tenants": 10000,
  "compress_enabled": false,
  "compress_mode": "safe",
  "compress_prose": false,
  "compress_protect_recent": 4,
  "ttl": {
    "exact_seconds": 86400,
    "semantic_seconds": 3600,
    "ccr_seconds": 604800,
    "sweep_interval_seconds": 3600
  },
  "pricing_overrides": {},
  "usd_to_inr_rate": 83.5,
  "prometheus_port": 9091
}

API Endpoints

MethodRoutePurpose
GET/api/optimize/configFull runtime config as JSON
PUT/api/optimize/configPartial config update (hot-reloaded)
GET/api/optimize/savingsSavings report (USD/INR, hit rate, compress ratio, cache stats)
GET/api/optimize/statsRaw MetricsSnapshot (16 fields)
DELETE/api/optimize/cache/clearClear cache for a tenant


Part of Qualixar | Created by Varun Pratap Bhardwaj | AI Reliability Engineering