Skip to content

feat(context): episodic memory — recall how a similar task was solved before#23

Merged
QodeXcli merged 1 commit into
mainfrom
feat/episodic-memory
Jun 25, 2026
Merged

feat(context): episodic memory — recall how a similar task was solved before#23
QodeXcli merged 1 commit into
mainfrom
feat/episodic-memory

Conversation

@QodeXcli

Copy link
Copy Markdown
Owner

The remaining genuinely-new gap from the review (#2). Companion to user-preference modeling (#22) — instead of rediscovering a recurring job, QodeX recalls how it solved a similar task before.

How it works

  • After each objectively-successful task, records a lean episode (prompt, summary, files, tools) to ~/.qodex/episodes/<project>.jsonl.
  • At the start of a new task, ranks past episodes against the prompt and injects a one-line reminder of the most similar one(s).
  • Smart, not always-on: lexical TF-cosine, top-K above a similarity threshold — an unrelated task injects nothing; near-identical re-runs of the same task are excluded; only a short summary is injected, never full transcripts.
  • Off by default (learning.episodicMemory.enabled).

Clean + lightweight (same discipline as #22)

  • src/context/episodic-memory.tspure rankEpisodes / buildEpisodeBlock (reuses the already-tested similarity primitives, no embedding dependency) + thin JSONL I/O.
  • The lexical ranker is a pure function, so an embedding-backed variant can be swapped in later without touching call sites (the "stronger ambition" path).
  • Loop: record at the success hook (next to capture/dataset); inject at run start.

Live-verified

Recorded two episodes → a pagination-shaped query recalled the pagination episode (with files); an unrelated k8s query recalled nothing.

Also

Completed the README Self-learning section: the episodic-memory step + config, and a worked end-to-end example (addresses review item #3).

Tests

6 (similar-retrieval, unrelated→empty, self-match excluded, topK/sort, empty guards). ✅ typecheck · ✅ full suite (1189) · ✅ build.

… before

Companion to user-preference modeling (#22). Instead of rediscovering a recurring
job, QodeX records a lean episode after each objectively-successful task and, at
the start of a new one, recalls the most SIMILAR past task on this project and
injects a one-line reminder of what worked. Off by default
(learning.episodicMemory.enabled).

Clean + lightweight, same discipline as #22:
- src/context/episodic-memory.ts (pure rank + thin I/O): records to
  ~/.qodex/episodes/<project>.jsonl; rankEpisodes scores a query against past
  episodes by lexical TF-cosine (reuses the tested similarity primitives — no
  embedding dependency), excludes near-identical re-runs (score ≥ 0.98), returns
  top-K above a similarity threshold; buildEpisodeBlock renders a concise block.
- SMART, not always-on: an unrelated task injects nothing (below threshold), and
  only a one-line summary is injected, never full transcripts.
- Loop hooks: record at the objective-success point (alongside capture/dataset);
  inject the recalled block into the system prompt at run start.
- The lexical ranker is a pure function, so an embedding-backed variant can be
  swapped in later without touching call sites.

Also: completed the README Self-learning section with the episodic-memory step,
its config, and a worked end-to-end example.

Live-verified: recorded two episodes, a pagination-shaped query recalled the
pagination episode (with files), an unrelated k8s query recalled nothing.
Tests: 6 (similar-retrieval, unrelated→empty, self-match excluded, topK/sort,
empty guards). typecheck + full suite (1189) + build green.
@QodeXcli QodeXcli merged commit 4360bb3 into main Jun 25, 2026
2 checks passed
@QodeXcli QodeXcli deleted the feat/episodic-memory branch June 25, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant