cotabby icon indicating copy to clipboard operation
cotabby copied to clipboard

Exploration: semantic cache with self-learning loop

Open Jam-Cai opened this issue 6 months ago • 1 comments

Idea

Beyond the byte-level KV prefix cache (#74, shipped) and the prompt-cache hint tracker in `LlamaSuggestionEngine`, explore a semantic cache: when the focused-field context (app, role, recent prefix, surrounding text) is close to a prior request, reuse the prior accepted continuation directly — or use it as a strong prior for sampling — instead of re-running generation.

The "self-learning" angle: every `Tab`-accepted suggestion is a high-quality `(context, continuation)` pair generated by the user themselves. Index those locally.

Why it's interesting

  • Latency: a hit is a string lookup, not a model call.
  • Quality: accepted continuations are by definition things this specific user wanted.
  • Privacy: stays on-device, opt-in, complements but doesn't replace #27 (opt-in encrypted capture).

Open design questions

  • Similarity metric. Embedding-based (need a small embedder bundled in-app) vs. cheap n-gram / suffix-array on the prefix. Start with the cheap one.
  • Storage. SQLite? A flat file with a LRU? Bounded by what (entries, MB)?
  • Cache key. `(bundleID, role, normalized-prefix-suffix)` — same shape as `FocusKey` in the existing prompt-cache hint tracker.
  • Invalidation. Per-app reset? TTL? User-visible "forget this" control?
  • Interaction with #3 (typing-history personalization) and #25 (`tabby-native-1` LoRA). These overlap — the same `(prefix, accepted)` corpus could feed LoRA training and serve the semantic cache.
  • Scoring. When a cached entry is "close but not exact," do we splice it, or use it as a sampling prior, or just discard? Splicing is where quality bugs will live.

Acceptance for this ticket

Plan only — no implementation. Land a design doc (or extended issue body) covering:

  1. Chosen similarity metric and rationale.
  2. Storage shape and bounds.
  3. Cache-key + invalidation strategy.
  4. Integration point in the pipeline (before runtime call vs. after, fallback behavior on miss).
  5. Privacy posture and user-visible controls.
  6. Eval plan: how do we know it's not making things worse?

Then split into implementation child issues.

Related

  • #74 KV prefix cache reuse (shipped)
  • #23 KV-cache reuse across consecutive requests
  • #3 Typing-history personalization with local continuous learning
  • #25 `tabby-native-1` LoRA
  • #27 Opt-in encrypted capture for training data

Jam-Cai avatar May 11 '26 01:05 Jam-Cai

Closing — acceptance criteria is explicitly "plan only, no implementation." The scope (embedding models, similarity metrics, caching strategies, privacy posture) is far too exploratory for a contributor to act on. If the team decides to pursue semantic caching, it should start with a concrete, bounded spike.

FuJacob avatar May 21 '26 06:05 FuJacob