OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: events memory L2 stores raw dialogue while L0/L1 are unreachable by vector retrieval, contradicting design doc

Open AaronZ345 opened this issue 7 months ago • 10 comments

Problem

The events memory type in openviking/prompts/templates/memory/events.yaml uses:

content_template: |
  time: {{ extract_context.get_first_message_time_with_weekday_from_ranges(ranges) }}
  {{ extract_context.read_message_ranges(ranges).pretty_print() }}

This stores raw dialogue pretty-print as the L2 file body. Meanwhile, examples/claude-code-memory-plugin/scripts/auto-recall.mjs:337-346 auto-reads L2 content for any leaf hit and injects it into the prompt:

if (item.level === 2) {
  const content = await readMemoryContent(item.uri);
  if (content) return `- [${item.category}] ${content}`;
}

Combined effect: every recalled events memory dumps full raw dialogue into <relevant-memories>, polluting the prompt context.

Measured Behavior

Tested 5 queries against a user scope with 166 L2 memories + directory-level L0/L1:

Scope L2 hits L1 hits L0 hits
user 50/50 0 0
agent (5 L2) 0 9 6

User scope L0/L1 are structurally unreachable — DIRECTORY_DOMINANCE_RATIO=1.2 in hierarchical_retriever.py:51 prevents them from surfacing when dense L2 candidates exist. Agent scope L0/L1 surface only because L2 is sparse, but their scores (0.18-0.30) fall below the plugin's default scoreThreshold=0.5.

Net result: 100% of prompt-injected memories are L2 raw dialogue. L0/L1 are generated, vectorized, and stored, but never reach the prompt.

Conflict with Design Doc

docs/design/memory-extractor-optimization.md defines events as Simple Mode — no content_template, no overview_template, just event_name + event_time + content (LLM-generated markdown):

name: events
filename_template: "{event_time}_{event_name}.md"
fields:
  - name: event_name (immutable)
  - name: event_time (immutable)
  - name: content (patch)  # LLM-generated markdown body

The actual events.yaml ships as Template Mode with content_template + overview_template + date-tree filenames ({year}/{month}/{day}/{event_name}.md). These diverge from both:

  • The design doc's Simple Mode for events
  • docs/zh/concepts/03-context-layers.md's L1 spec ("~1-2k tokens, structured overview with navigation") — our leaf-date .overview.md measures 18.5KB because it's raw Jinja2 concatenation of all child summaries with no LLM refinement

Workaround We Use

Local prompts.templates_dir override replacing content_template with just {{ summary }}. This makes L2 contain LLM-generated summary (~2KB) instead of raw dialogue, mirroring what preferences/entities already do (both have no content_template and L2 is clean LLM markdown).

Suggestions

  1. Align events.yaml with the design doc's Simple Mode — remove content_template, remove ranges field, let LLM generate the content field as markdown directly (same pattern as preferences/entities/cases/patterns).

  2. Or at minimum, change content_template from read_message_ranges(ranges).pretty_print() to {{ summary }} so L2 stores the LLM summary rather than raw dialogue.

  3. Consider flattening filename_template to {event_time}_{event_name}.md (matching the design doc) to avoid date-based L1 bloat.

  4. Document L0/L1 reachability limits — or expose DIRECTORY_DOMINANCE_RATIO as a config option so users can tune when L1 should surface over L2.

Related: #1139 reports the mirror-image symptom (L1/L2 unreachable via search API). The root cause is the same — L0/L1 structurally can't compete with dense L2 vectors, and auto-recall compensates by reading L2 directly. The fix should clarify whether L0/L1 are meant for vector retrieval at all, or purely for on-demand client.overview()/client.read() calls.

Environment:

  • OpenViking 0.3.7.dev38
  • claude-code-memory-plugin (latest)
  • Memory version: v2

AaronZ345 avatar Apr 17 '26 17:04 AaronZ345

Thank you for your advice. You have observed very carefully. The final implementation of events is indeed inconsistent with what is described in the design document. This is our current best-performing result based on evaluation (83% accuracy on the Locomo dataset). In fact, events store key snippets extracted from the original text by an LLM, rather than the full original text. Compared with summaries, this approach preserves more factual details. In our evaluations, the original-text-based approach achieved an improvement of several percentage points over the summary-only approach. We need to ensure that the results of public evaluations are reproducible with the default configuration, so we have chosen the original-text approach as the default. Of course, the final solution is still being optimized and iterated upon, and further evolution will be driven by evaluation results. You may use your own dataset to test the performance of both implementations in your scenario (you can refer to the evaluation scripts under benchmark/locomo/vikingbot/). If you prefer the summary-based approach, you can replace the current script with a custom one.

chenjw avatar Apr 17 '26 17:04 chenjw

Thanks @chenjw for the detailed response. After running with the default implementation for a while, I have two follow-up questions:

1. Default events template in agent-dialogue archival scenarios

The default content_template renders read_message_ranges().pretty_print(), which concatenates raw dialogue turns. When events are used to archive agent conversations, each L2 easily grows to several thousand tokens. Once auto-recall hits multiple of them, the injected prompt burns through the context window very quickly.

My current workaround is overriding events.yaml via memory.custom_templates_dir and rewriting content_template to render only the LLM-generated summary field. But this makes L2 (a summary paragraph) and L1 (overview_template joining summary fields into a link list) consume essentially the same LLM output in slightly different shapes.

Could you clarify:

  • Is downgrading L2 to a summary (to avoid length issues) an officially acceptable trade-off?
  • Or should events not be used for agent-dialogue flow in the first place, and such content should be routed to other memory types instead? (The design doc docs/design/memory-extractor-optimization.md classifies events under Simple Mode, which reads more like milestone archival than day-to-day dialogue.)

2. Zero-hit rate of agent-scope memory in default auto-recall

Measured on my workspace:

  • user-scope: 166 L2 entries, similarity 0.33–0.55, top 1–2 clear the 0.5 threshold
  • agent-scope: 34 L2 entries (tools 7 + skills 22 + cases 4 + patterns 1), similarity 0.18–0.30, none cross the threshold

agent-scope and user-scope are physically isolated by namespace, but retrieval runs against the same vector store without any scope-level filtering or bucketing. As a result agent-scope memories are effectively only reachable via manual ov read.

Is this the intended behavior? If so, how is the value of agent-scope memories (tools/skills/cases/patterns) meant to surface in the default auto-recall path?

AaronZ345 avatar Apr 17 '26 17:04 AaronZ345

  1. In fact, the mainstream benchmarks for user memory (Locomo / LongMemEval) are all fact-oriented memory tasks. In our tests, event memory contributes significantly more than other types of memory on these benchmarks. Using a summary as L2 is certainly acceptable (again, this depends on evaluation results for your specific scenario). Regarding the value of the event memory overview, our evaluation shows it contributes no more than 1%. Given that you are setting L2 to summary, we recommend changing the overview to be rendered using the goal field to avoid information redundancy.
  2. Regarding agent memory. Our tests indicate that auto-recall is not the optimal approach for agent memory. In future versions, we plan to split agent memory retrieval into two parts: (1) Binding to skills (loaded when skill.md is loaded, rather than via vector retrieval); (2) Retrieval via vector search (but with different thresholds from user memory). The current implementation of agent memory is still relatively preliminary. We already have a new version ready to be submitted soon (evaluated on the TAU-2 benchmark). Additionally, we will train a lightweight local intent model to address the issue of invalid retrievals (work in progress). This will alleviate the aforementioned context size issue and improve agent memory retrieval.

chenjw avatar Apr 17 '26 18:04 chenjw

As a supplement, regarding the issue of summaries versus original messages, in our commercial version, we are attempting to use fine-tuned models for memory extraction to achieve summary performance close to that of using the original messages. However, there is still some gap when using publicly available models.

chenjw avatar Apr 17 '26 18:04 chenjw

Thanks @chenjw for the thorough clarification on both points. The distinction between benchmark-oriented defaults and production-oriented customization makes a lot of sense now. Looking forward to the upcoming agent-memory improvements (skill-binding + separate retrieval thresholds + lightweight intent model) — those sound like they'll directly address the zero-hit issue I've been seeing.

I've updated my local override to render the L1 overview with the goal field per your suggestion, so L1 (title index) and L2 (summary detail) are no longer redundant.

AaronZ345 avatar Apr 18 '26 02:04 AaronZ345

💬 我也在做记忆系统相关的工作:CausaMem,可以来看看,说不定有能借鉴的地方 🙂

MaiHHConnect avatar Apr 19 '26 00:04 MaiHHConnect

💬 我也在做记忆系统相关的工作:CausaMem,可以来看看,说不定有能借鉴的地方 🙂

MaiHHConnect avatar Apr 19 '26 00:04 MaiHHConnect

Events memory L2 raw dialogue storage: a common design trap

We hit this exact pattern in our memory system at KinthAI. Storing raw dialogue as L2 content creates two cascading problems:

Problem 1: Retrieval noise Raw dialogue is full of conversational artifacts: "um, let me think...", "oh actually, I meant...", "going back to what you said earlier...". When this is vectorized and used for retrieval, similarity search returns these noisy chunks instead of the actual semantic content.

Problem 2: Context pollution When L2 content is auto-injected into prompts (as your auto-recall.mjs does), the model processes raw dialogue as if it were structured knowledge. It picks up conversational tone, tentative statements, and corrected errors as facts.

The fix: extract-then-store, not store-then-extract

Instead of:

conversation → raw storage (L2) → vector index → retrieval → prompt injection

Do:

conversation → fact extraction → structured storage (L2) → vector index → retrieval → prompt injection

The extraction step:

  1. Feed the raw conversation to a lightweight model (Haiku-class)
  2. Prompt: "Extract durable facts from this conversation. Output structured entries: {type, key, value, confidence}. Ignore greetings, filler, and tentative statements."
  3. Store the structured output as L2, not the raw dialogue

For the L0/L1 unreachability issue: This is likely because your vector embeddings are computed on L2 content (raw dialogue), but retrieval queries are typically phrased as questions or topics (very different embedding space). Structured facts embed much closer to the retrieval queries.

Practical migration path:

  1. Add an extraction step before L2 write
  2. Re-index existing L2 entries through the extraction pipeline
  3. Keep raw dialogue in a separate archive tier (L3) for audit/debugging, but exclude it from vector retrieval

We documented this architecture: Why Character.AI Forgets You — Persistent Memory Architecture

kinthaiofficial avatar Apr 28 '26 15:04 kinthaiofficial

@kinthaiofficial Thank you very much for your reply. We also extract facts in our implementation. However, in our evaluations on Locomo and LongMemEval benchmarks, we observed that selected raw dialogue content outperforms LLM-summarized facts. Could you kindly share the phenomena and quantitative data you observed in your experiments?

chenjw avatar Apr 28 '26 16:04 chenjw

Thanks for the detailed investigation and the thoughtful follow-up discussion.

After rechecking the current behavior and the maintainer responses above, the default events representation is intentional: selected source snippets are retained because that default performed better than summary-only storage in the referenced memory evaluations. A summary-only representation remains available through custom templates for deployments with a different context-budget trade-off.

The general level-selection/retrieval topic is tracked separately in #1139. Closing this issue as a resolved design decision rather than an implementation defect. A focused current-version reproduction is still welcome if the configurable path itself behaves incorrectly.

qin-ctx avatar Jul 14 '26 03:07 qin-ctx