Short answer: cache retrieval results only for content and identities that share a clear privacy boundary, and invalidate by document version rather than by elapsed time alone. In a privacy-focused personal knowledge manager, freshness and isolation matter more than shaving a network round trip; a stale private note can be a correctness failure, not a harmless performance glitch.

The bill is usually made of repeated embedding and retrieval work. A query that arrives five times in an afternoon can trigger five vector searches, five reranking passes, and five prompt assemblies even though the user's notes have not changed. The dominant term is therefore recomputation, not the bytes sitting in a small local cache. The useful change is to retain a compact, versioned result for a short period and to discard the larger derived payload as soon as its source version changes.

That trade has a cost. Keeping less history means a deleted or edited note may be harder to explain during an audit. I would rather retain a hash, source version, and decision log than preserve the full text in a fast cache. The log tells me what was selected without creating another copy of sensitive content.

How should caching work in a privacy-focused personal knowledge manager?

Treat the cache as a derived index, not as a second database. A cache key should include the normalized query, tenant or user identifier, retrieval policy, embedding-model identifier, and a snapshot token representing the documents visible to that user. Omitting any one of these fields creates a collision: a changed policy can return an old top-k list, and a shared machine can reveal one person's results to another.

The snapshot token can be a monotonic counter in the metadata store. Every successful document write increments the counter for that notebook. A read captures the counter before searching; the resulting entry is tagged with that value. On the next read, a mismatch is a miss. This is deterministic invalidation, and it avoids guessing whether a five-minute TTL is long enough.

TTL still has a role. It bounds memory and limits the lifetime of data that a user has asked to remove, while version checks provide the freshness guarantee. Use a short TTL for query-result identifiers and a longer TTL for public, immutable artifacts such as tokenizer metadata. Never use one global TTL as a substitute for access control.

An in-process cache is often the safest first layer for a single-user application because its address space disappears with the process. A shared cache can help a multi-device service, but it must use encryption at rest, authenticated connections, and per-user namespaces. The cache should contain document IDs and scores where possible; hydrate text from the encrypted primary store only after authorization succeeds.

The retrieval path and its failure modes

A reliable path has four checkpoints: authorize the request, read the current snapshot token, look up a versioned result, and run the vector search on a miss. Reranking and prompt construction happen after the result has passed the same authorization check. This order prevents a warm cache from bypassing policy.

The common failure is a negative cache entry that outlives a write. Suppose a query finds no note, then a sync process adds one. If the empty result is cached without the snapshot token, the user sees “nothing found” until the TTL expires. Cache empty results, if at all, with a shorter TTL and the same version test as non-empty results.

Cache misses are acceptable.

Consider a media notebook receiving a burst of transcript edits while an editor searches for a quote. Request A reads snapshot 41 and starts a vector search. Before it returns, the sync worker commits snapshot 42, then request B searches under the new token. If A blindly writes under a query-only key, B can receive a list built from 41; if A writes under the versioned key, both entries can coexist briefly and each caller gets the state it asked for. A later cleanup removes 41 by age or by an explicit generation sweep. The extra key is cheap compared with debugging a citation that points to text the editor has already changed, and the event record makes the choice inspectable without retaining the transcript itself.

Another failure is stampede: dozens of identical misses start the same expensive search. A per-key single-flight guard lets one request populate the entry while the others wait for that result. Add a bounded timeout so a slow vector store does not pin every caller. On timeout, serve no cached answer rather than silently mixing an old snapshot with a new policy.

Cache poisoning deserves the same attention as SQL injection. Keys must be derived from parsed fields, not a user-controlled string that can contain separators or unbounded length. Hash the canonical key, cap query size, and record hit, miss, age, and snapshot values without recording note text.

Decision Keeps fresh Main cost
Snapshot in key Changes are isolated immediately More entries during sync bursts
TTL only Simple eviction policy Stale answers after edits
IDs and scores only Small exposure surface Extra primary-store reads

A small Go cache with version-aware reads

This example keeps only IDs and scores. The Snapshot value is supplied by the encrypted metadata store; the cache itself does not decide who may read a notebook.

package retrieval import ( "crypto/sha256" "encoding/hex" "encoding/json" "sync" "time" ) type Hit struct { ID string `json:"id"` Score float64 `json:"score"` } type Entry struct { Snapshot uint64 Hits []Hit Expires time.Time } type Cache struct { mu sync.RWMutex m map[string]Entry } func NewCache() *Cache { return &Cache{m: make(map[string]Entry)} } func Key(user, query, policy, model string, snapshot uint64) string { payload, _ := json.Marshal([]any{user, query, policy, model, snapshot}) sum := sha256.Sum256(payload) return hex.EncodeToString(sum[:]) } func (c *Cache) Get(key string, snapshot uint64, now time.Time) ([]Hit, bool) { c.mu.RLock() e, ok := c.m[key] c.mu.RUnlock() if !ok || e.Snapshot != snapshot || !now.Before(e.Expires) { return nil, false } return append([]Hit(nil), e.Hits...), true } func (c *Cache) Put(key string, snapshot uint64, hits []Hit, ttl time.Duration, now time.Time) { c.mu.Lock() c.m[key] = Entry{Snapshot: snapshot, Hits: append([]Hit(nil), hits...), Expires: now.Add(ttl)} c.mu.Unlock() } 

Production code needs eviction, bounded entry size, and a single-flight mechanism. Those are operational controls, not reasons to put full note bodies in a process-wide map. Test the invariant that an old snapshot can never produce a hit, including after clock jumps and restart recovery.

Measuring freshness without retaining private text

Record counters for cache hits, misses, invalidations, stampede waits, and authorization denials. A useful dashboard plots hit rate beside the age of the newest source snapshot; a high hit rate with an old snapshot is a warning, not a success. Sample query-shape hashes for debugging, and keep the mapping out of application logs so an operator cannot reconstruct a user's phrase from telemetry.

Measure twice.

Reconciliation needs an audit trail. For each answer, store the snapshot number, selected document IDs, retrieval policy, and model identifier in an append-only event stream. Hash the event payload if tamper evidence is required. This supports an exactly-once mindset for writes: retries may repeat a request, but they must not create two logically different cache generations for one document version. During a replay, the consumer reads the document-change event, verifies that the referenced generation is still the one associated with the snapshot, and emits an invalidation event if it is not. The invalidation is idempotent; applying it twice has the same result as applying it once. A reconciliation job can compare the event stream with the metadata counter and report a missing generation without opening the note body. That separation matters in a personal knowledge manager: operators can prove that a result came from snapshot 41 while access logs and dashboards remain free of transcript or journal text. The audit record is useful precisely because it is smaller than the thing it describes.

Privacy regulations can limit retention even when a cache is technically encrypted. Define deletion semantics up front: a delete increments the snapshot, removes primary content, and schedules cache eviction; the audit record keeps identifiers and timestamps only. I don't assume every jurisdiction treats derived embeddings identically to source text, so the compliance owner should make that call and document it rather than relying on a library default.

When should you skip the cache?

Caching is not suitable when every query carries a unique policy, when authorization changes more frequently than the index, or when the result itself is too sensitive to duplicate. It is also a poor fit for a tiny notebook whose vector search is already below the user's latency budget. In those cases, spend the engineering effort on an encrypted index, deterministic chunk boundaries, and clear deletion behavior.

The limitation is deliberate: this design does not make a shared cache safe for cross-user data by itself. Stick with a direct query when the privacy boundary cannot be represented in a stable key, and choose a per-device cache when synchronized eviction is harder to prove than the latency benefit is worth.

For a shared service, keep the cache behind the same key-management boundary as the index and isolate tenants at the storage layer. For a local application, an in-memory layer plus a bounded on-disk metadata file may be enough. Your mileage may vary: device memory, sync frequency, and the cost of the embedding model change the break-even point.

The decision rule is simple: cache a result only when its privacy scope, policy, model, and snapshot are explicit; invalidate on version change; and measure freshness as carefully as latency. The retrieval-augmented generation paper that introduced the now-common pattern combines a retriever with a generator, but it does not remove the need to govern copies of the retrieved data. That governance is the architecture.

References

Further reading