Caching
Skip the vector DB for repeated or similar queries.
Attach a cache and repeated queries are served without hitting S3 Vectors. Three backends:
from dynavec import Dynavec, SemanticCache, DynamoDBCache, RedisCache
# 1) in-process semantic cache — also serves near-duplicate queries
db = Dynavec(cfg, embedder=emb, cache=SemanticCache(threshold=0.97))
# 2) durable, shared cache with TTL jitter to spread simultaneous expiry
db = Dynavec(
cfg,
embedder=emb,
cache=DynamoDBCache(cfg, ttl_seconds=3600, ttl_jitter_seconds=300),
)
# 3) sub-millisecond shared cache on Redis / AWS ElastiCache
db = Dynavec(cfg, embedder=emb, cache=RedisCache("redis://my-elasticache:6379/0"))
| Backend | Best for |
|---|---|
SemanticCache | single process; tolerant of near-duplicate hits; zero infra |
DynamoDBCache | durable, shared, no extra service; exact-match with TTL and optional expiry jitter |
RedisCache | many workers/hosts; lowest latency; AWS ElastiCache |
Force a fresh search per call with db.search(..., use_cache=False).