Skip to main content

Configuration

OmniCache-AI can be configured programmatically or via environment variables.


OmnicacheSettings

The OmnicacheSettings dataclass holds all configuration. Use it with CacheManager.from_settings().

from omnicache_ai import CacheManager, OmnicacheSettings

# Programmatic configuration
settings = OmnicacheSettings(
backend="disk",
disk_path="/data/cache",
default_ttl=3600,
namespace="myapp",
)
manager = CacheManager.from_settings(settings)

All Parameters

ParameterTypeDefaultDescription
backend"memory" | "disk" | "redis""memory"Primary storage backend
redis_urlstr"redis://localhost:6379/0"Redis connection URL
disk_pathstr"/tmp/omnicache"Disk cache directory path
default_ttlint | None3600Default TTL in seconds (None = no expiry)
semantic_thresholdfloat0.95Minimum cosine similarity for semantic cache hit
vector_backend"faiss" | "chroma" | "none""none"Vector similarity backend
embedding_dimint1536Embedding dimension (for FAISS)
max_memory_entriesint10000Max entries for InMemoryBackend
key_hash_algo"sha256" | "md5""sha256"Hash algorithm for key generation
namespacestr"omnicache"Key prefix namespace
ttl_embeddingint | None86400TTL for embedding cache (24h)
ttl_retrievalint | None3600TTL for retrieval cache (1h)
ttl_contextint | None1800TTL for context cache (30min)
ttl_responseint | None600TTL for response cache (10min)

Environment Variables

Every setting maps to an OMNICACHE_* environment variable. Load them with OmnicacheSettings.from_env().

from omnicache_ai import CacheManager, OmnicacheSettings

manager = CacheManager.from_settings(OmnicacheSettings.from_env())
VariableDefaultDescription
OMNICACHE_BACKENDmemorymemory, disk, or redis
OMNICACHE_REDIS_URLredis://localhost:6379/0Redis connection URL
OMNICACHE_DISK_PATH/tmp/omnicacheDisk cache directory
OMNICACHE_DEFAULT_TTL3600Seconds; none = no expiry
OMNICACHE_NAMESPACEomnicacheKey prefix
OMNICACHE_SEMANTIC_THRESHOLD0.95Float 0-1
OMNICACHE_VECTOR_BACKENDnonefaiss, chroma, or none
OMNICACHE_EMBEDDING_DIM1536Embedding dimension
OMNICACHE_MAX_MEMORY_ENTRIES10000InMemoryBackend capacity
OMNICACHE_KEY_HASH_ALGOsha256sha256 or md5
OMNICACHE_TTL_EMBEDDING86400Per-layer TTL
OMNICACHE_TTL_RETRIEVAL3600Per-layer TTL
OMNICACHE_TTL_CONTEXT1800Per-layer TTL
OMNICACHE_TTL_RESPONSE600Per-layer TTL

Example

export OMNICACHE_BACKEND=redis
export OMNICACHE_REDIS_URL=redis://cache.internal:6379/0
export OMNICACHE_DEFAULT_TTL=7200
export OMNICACHE_NAMESPACE=prod
export OMNICACHE_TTL_RESPONSE=300