Skip to content

feat: optimize memory extraction for concise output and precise retrieval#549

Open
lishixiang0705 wants to merge 1 commit intovolcengine:mainfrom
lishixiang0705:feat/optimize-memory-extraction
Open

feat: optimize memory extraction for concise output and precise retrieval#549
lishixiang0705 wants to merge 1 commit intovolcengine:mainfrom
lishixiang0705:feat/optimize-memory-extraction

Conversation

@lishixiang0705
Copy link

Problem

In production, extracted memories average 500-2000 chars per item, causing:

  1. Embedding vector dilution — any query fuzzy-matches long content, scores cluster in 0.18-0.21 range
  2. Poor retrieval discrimination — relevant and irrelevant items score similarly
  3. Context bloat — 5 injected memories can exceed 5000 chars (~3000 tokens) per turn

Solution

1. Prompt optimization (memory_extraction.yaml)

  • Add explicit length targets: abstract ~50-80 chars, content 2-4 sentences
  • Add good/bad examples showing concise vs verbose patterns
  • Guide LLM to split multi-topic memories into separate atomic items
  • Emphasize fact-dense "sticky note" style over narrative expansion

2. Vectorization improvement (memory_extractor.py)

  • Use abstract instead of content for embedding generation
  • Shorter text → more focused vectors → better cosine similarity discrimination
  • Fallback: abstract or content ensures no empty embeddings

Expected Impact

  • Memory size: 500-2000 chars → 100-300 chars per item
  • Injection cost: ~3000 tokens/turn → ~600 tokens/turn (80% reduction)
  • Retrieval precision: score spread from 0.03 → 0.15+ between relevant/irrelevant

Files Changed

  • openviking/prompts/templates/compression/memory_extraction.yaml — prompt template
  • openviking/session/memory_extractor.py — 2 lines: set_vectorize text source

…eval

- Prompt (memory_extraction.yaml):
  - Add explicit length targets for abstract (~50-80 chars) and content (2-4 sentences)
  - Add good/bad examples showing concise vs verbose memory patterns
  - Guide LLM to split multi-topic memories into separate atomic items
  - Emphasize fact-dense 'sticky note' style over narrative expansion

- Vectorization (memory_extractor.py):
  - Use abstract instead of content for embedding generation
  - Shorter text produces more discriminative vectors, improving retrieval precision
  - Reduces score clustering (e.g., 0.18-0.21 all similar) by focusing embeddings

Background:
  In production, extracted memories averaged 500-2000 chars per item, causing:
  1. Embedding vector dilution — any query fuzzy-matches long content
  2. Poor score discrimination — relevant and irrelevant items score similarly
  3. Context bloat — 5 injected memories could exceed 5000 chars per turn

  After this change, new memories will be shorter and more atomic, and
  vector search will match on focused abstract text rather than diluted content.
@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