Caching¶
Graph exploration is repetitive by nature: PPR and beam search revisit the same nodes and edges constantly. To keep that from turning into a flood of database round-trips, Odin wraps every graph read in an LRU cache, so warm data is served from memory.
Two layers, one goal¶
There are actually two caches working together. The graph accessor cache sits over ArangoDB: when you build an engine, the raw accessor is wrapped in a CachedGraphAccessor, and every node fetch and neighbor lookup during a walk goes through it.
backend = ArangoBackend(db, graph) # `graph` is your ArangoGraphConfig
engine = OdinEngine(backend, cache_size=5000) # LRU size for graph reads
Above that, the NPLL confidence layer caches score_edge results internally. Because a beam search evaluates the same (head, relation, tail) triples over and over, this avoids repeated model evaluation after the first lookup; measure the effect on your own data and hardware.
| Layer | What it caches | Controlled by |
|---|---|---|
| Graph accessor | Node and edge reads from the database | cache_size (default 5000) |
| NPLL confidence | Edge plausibility scores | internal (cache_size=10000) |
Why it matters for latency¶
A warm cache avoids repeated database reads and model evaluations, so latency is typically lower once the working set has filled; hit rates and latency depend on your graph and queries, so measure them. The first retrieval after startup is slower while the cache fills, which is why warming an engine before it serves traffic matters in production.
Sizing the cache¶
cache_size is the main lever, and the right value depends on your graph and host. On a large, dense graph, raise it to keep more of the working set resident. On a memory-constrained host, lower it and accept more round-trips. For many short, unrelated queries, a small cache is fine because there is little locality to exploit anyway. Memory use grows with cache size and graph density; measure it on your own data.
One caveat on freshness: the cache holds reads for the lifetime of the engine's working set. After a significant data change, construct a fresh engine, and if the edge patterns themselves shifted, retrain the NPLL model, so stale structure does not linger.
Cache size is one dial among a few; Tuning Retrieval covers how it interacts with beam width and hops, and Production Deployment puts it in the context of real workloads.