Skip to main content

Storage Backends

OmniCache-AI provides five interchangeable storage backends -- three for key-value caching and two for vector similarity search. Every backend conforms to a Protocol, so you can swap implementations without changing application code.

Overview

Backends are the persistence layer beneath every cache layer. Choosing the right one depends on your durability requirements, latency budget, deployment topology, and whether you need exact-match or semantic-similarity lookups.

OmniCache-AI defines two protocols in omnicache_ai.backends.base:

  • CacheBackend -- key-value storage with optional TTL (implemented by InMemoryBackend, DiskBackend, RedisBackend).
  • VectorBackend -- vector similarity search over embedding spaces (implemented by FAISSBackend, ChromaBackend).

Both protocols are @runtime_checkable, so you can verify conformance with isinstance().

Decision Flowchart

Use the diagram below to pick the right backend for your workload.

Comparison Table

Key-Value Backends (CacheBackend)

FeatureInMemoryBackendDiskBackendRedisBackend
PersistenceNone (process lifetime)Disk (survives restarts)Redis server
Multi-process safeNoYes (SQLite locking)Yes (server-based)
Multi-nodeNoNoYes
TTL supportYes (per-entry)Yes (native)Yes (native)
EvictionLRU (configurable max_size)Size-based (size_limit)Server-side policies
Optional dependencyNonediskcache (core)redis
Typical latency~microseconds~milliseconds~milliseconds (network)
Best forDev, testing, single-processSingle-node productionDistributed production

Vector Backends (VectorBackend)

FeatureFAISSBackendChromaBackend
Similarity metricCosine (via L2-norm + inner product)Cosine (native HNSW)
PersistenceNone (in-memory only)Optional (PersistentClient)
Metadata filteringNoYes (Chroma native)
Deletion supportSoft (mapping removal)Native
Optional dependencyfaiss-cpuchromadb
Best forFast in-process similarityProduction with persistence

Protocols

CacheBackend Protocol

from omnicache_ai.backends.base import CacheBackend

# Methods every key-value backend must implement:
# get(key: str) -> Any | None
# set(key: str, value: Any, ttl: int | None = None) -> None
# delete(key: str) -> None
# exists(key: str) -> bool
# clear() -> None
# close() -> None

VectorBackend Protocol

from omnicache_ai.backends.base import VectorBackend

# Methods every vector backend must implement:
# add(key: str, vector: np.ndarray, metadata: dict[str, Any]) -> None
# search(vector: np.ndarray, top_k: int = 1) -> list[tuple[str, float]]
# delete(key: str) -> None
# clear() -> None
# close() -> None
Runtime protocol checking

Both protocols are decorated with @runtime_checkable, so you can write isinstance(my_backend, CacheBackend) to verify at runtime that an object conforms to the expected interface.

Backend Pages