Skip to content

feat(prompts): add facet guard and length limits to memory_merge_bundle#533

Open
lishixiang0705 wants to merge 1 commit intovolcengine:mainfrom
lishixiang0705:fix/memory-merge-facet-guard-and-length-limits
Open

feat(prompts): add facet guard and length limits to memory_merge_bundle#533
lishixiang0705 wants to merge 1 commit intovolcengine:mainfrom
lishixiang0705:fix/memory-merge-facet-guard-and-length-limits

Conversation

@lishixiang0705
Copy link

Problem

The current memory_merge_bundle.yaml template has three issues that degrade memory quality over time:

  1. No facet coherence check — Two memories sharing the same category (e.g. both preferences) are always merged, even when they describe completely unrelated topics (e.g. "Python code style" + "food preferences"). This produces bloated, semantically diluted memories.

  2. No length constraints — Merged content grows unbounded. In production, single memory items can exceed 1000+ characters, causing:

    • Embedding dilution (vector search scores cluster in a narrow band with ~0.02 spread)
    • High token cost when memories are injected into LLM context
    • Low retrieval precision
  3. Accumulate-only strategy — The template instructs to "keep non-conflicting details", which means memories only grow, never condense. Old, superseded facts persist alongside new ones.

Solution

Upgrade template to v2.0.0 with three changes:

1. Facet guard (decision: skip)

Before merging, the LLM must verify both memories describe the same specific facet/topic. If they cover different facets, output {"decision": "skip"} to keep them separate. Includes concrete examples for both cases.

2. Hard character limits

  • abstract: ≤ 80 characters
  • overview: ≤ 200 characters
  • content: ≤ 300 characters

When limits would be exceeded, aggressively summarize — drop older details first, preserve specific values (names, numbers, versions) over narrative.

3. Condensed snapshot strategy

Replace "keep non-conflicting details" with:

  • Conflicts → keep newer version only
  • Non-conflicts → condense to essential facts
  • Result should read as a clean, up-to-date snapshot — not a changelog

Breaking Changes

  • The decision field now accepts "skip" in addition to "merge". Callers that parse the merge output must handle this new value.
  • Merged content will be significantly shorter than before. Downstream systems that rely on verbose L2 content may need adjustment.

Testing

Tested in production with ~2800 vectors and ~76 leaf memory files. The facet guard correctly prevents cross-topic merges, and length limits keep individual memories within embedding-friendly bounds.

- Add 'skip' decision: reject merging memories with different facets
  even if they share the same category, preventing semantic dilution
- Add hard character limits: abstract ≤80, overview ≤200, content ≤300
- Change merge strategy from accumulate-all to condensed snapshot:
  conflicts resolved by keeping newer version only
- Bump template version from 1.0.0 to 2.0.0

Motivation: without facet checking, the merge prompt would combine
unrelated facts (e.g. 'Python code style' + 'food preferences') into
a single bloated memory just because both were categorized as
'preferences'. Without length limits, merged memories grew unbounded
(some exceeding 1000+ chars), causing embedding dilution and low
retrieval precision in downstream vector search.
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


lishixiang seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants