MemOS icon indicating copy to clipboard operation
MemOS copied to clipboard

[Feature Request] Re-embed existing memories when embedding model/provider changes

Open z6166 opened this issue 8 months ago • 2 comments

Pre-submission checklist | 提交前检查

  • [x] I have searched existing issues and this hasn't been mentioned before | 我已搜索现有问题,确认此问题尚未被提及
  • [x] I have read the project documentation and confirmed this issue doesn't already exist | 我已阅读项目文档并确认此问题尚未存在
  • [x] This issue is specific to MemOS and not a general software issue | 该问题是针对 MemOS 的,而不是一般软件问题

Problem

When a user changes their embedding model configuration (e.g., switching from text-embedding-3-small to text-embedding-3-large, or from OpenAI to a self-hosted model), existing memories become incompatible with vector search.

The embeddings table stores vectors with dimensions but does not store which embedding model/provider generated them:

CREATE TABLE embeddings (
  chunk_id   TEXT PRIMARY KEY,
  vector     BLOB NOT NULL,
  dimensions INTEGER NOT NULL,
  updated_at INTEGER NOT NULL
);

After changing the embedding model:

  • New queries are embedded with the new model
  • Existing stored vectors were generated by the old model
  • Cosine similarity between vectors from different embedding spaces yields meaningless scores
  • Vector search effectively breaks (either returns garbage or 0 scores when dimensions mismatch)

The system falls back to FTS-only search, but this is a silent degradation — users have no indication that their vector search is broken.

Expected Behavior

A supported way to re-embed all existing memories when the embedding model changes:

  1. Detection: When embedding config changes (model, provider, or endpoint), warn users that vector search may be degraded until re-embedding is complete
  2. Re-embedding tool: Provide a CLI command or API to regenerate embeddings for all existing chunks using the new model
  3. Incremental support: Allow re-embedding only new chunks (those without embeddings)

Environment

  • MemOS Local Plugin: memos-local-openclaw-plugin
  • Storage: SQLite with embeddings table
  • Search: Hybrid (FTS5 + vector via RRF fusion)

Happy to contribute if pointed in the right direction.

z6166 avatar Mar 23 '26 17:03 z6166

🤖 AutoDev has picked up this issue and started working on it.

Task ID: aaa5d7dd575337ba Working branch: feature/autodev-1333 Target branch: latest dev* branch Workflow: opsp (analysis → coding → testing → PR)

I will post the PR link here once done. If I need more information, I will ask in the comments.

Memtensor-AI avatar Jun 30 '26 02:06 Memtensor-AI

✅ AutoDev task aaa5d7dd575337ba completed.

Summary: Resolves issue #1333 by teaching memos-local-openclaw-plugin to detect embedding model/provider changes and provide a re-embed CLI. Every embedding row in embeddings, skill_embeddings, task_embeddings, hub_embeddings, hub_skill_embeddings, and hub_memory_embeddings is now tagged with (provider, model) via an idempotent migration; ingest / viewer / hub call sites pass the producer triple from the live Embedder. On plugin init, when legacy or mismatched rows exist, the plugin emits a single warn line pointing the user to pnpm exec tsx scripts/re-embed.ts.

The new scripts/re-embed.ts resolves ~/.openclaw/openclaw.json, prints a before/after stats block (matched / mismatched / legacy / missing plus byProducer counts), and re-embeds in configurable batches. Supports --missing-only, --dry-run, --limit, --batch-size, --db, and --config. Failures inside a batch log a warn and continue so a single bad row doesn't abort the run; re-running picks up where it left off because the candidate list is recomputed each time.

Verification: 15 new tests in tests/embedding-reembed.test.ts cover migration, producer-aware writes, getEmbeddingStats, listChunkIdsForReembed, Embedder.signature, the init warning, CLI arg parsing, and dry-run no-write behavior — all pass. 132/132 in 13 related suites (storage, hub-server, recall, integration, migration-status, plugin-impl-access, multi-agent, skill-sync, worker-lifecycle, viewer-config, policy, capture) pass. tsc --noEmit is clean. The 5 pre-existing failures elsewhere in the repo (accuracy / skill-auto-install / task-processor / update-install) were confirmed unchanged on the unmodified baseline via git stash and are unrelated to this change.

Base branch: main Branch: feature/autodev-1333 Commit: 346d867 PR: https://github.com/MemTensor/MemOS/pull/1975 Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller

Memtensor-AI avatar Jun 30 '26 03:06 Memtensor-AI