Skip to content

feat: improve MemOS performance #1926

Closed

Description

@World-controller

Pre-submission checklist | 提交前检查

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

Problem Statement | 问题陈述

As a MemOS user, I want MemOS to have better overall performance across common usage scenarios.

Currently, some MemOS workflows may become slow as the amount of memory data grows or as more operations are executed in a session. This can affect the user experience when creating, updating, searching, retrieving, or managing memories.

This issue is specific to MemOS because it focuses on improving the runtime performance and responsiveness of MemOS itself.

Willingness to Implement | 实现意愿

  • I'm willing to implement this myself | 我愿意自己解决
  • I would like someone else to implement this | 我希望其他人来解决

Activity

  1. added
    types:enhancementNew feature or improvement | 新功能或改进
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    on Jun 15, 2026
  2. added
    area:coreMOS 编排层 / 框架底座 / 跨模块问题
    ai:codingAI agent is coding | AI 正在编码
    on Jun 15, 2026
  3. self-assigned this
    on Jun 15, 2026
  4. Memtensor-AI commented on Jun 15, 2026

    @Memtensor-AI
    Collaborator

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

    Task ID: f4939bc985cde6d5
    Working branch: feature/autodev-1926
    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.

  5. Memtensor-AI commented on Jun 15, 2026

    @Memtensor-AI
    Collaborator

    🤔 AutoDev task f4939bc985cde6d5 needs clarification to proceed:
    Issue #1926 ("improve MemOS performance") is broad — five different operations are named (create/update/search/retrieve/manage) with no baseline, repro, or acceptance criterion. Could you clarify so I work on the highest-value target?

    1. Which workflow has the highest priority? e.g., textual-memory search/retrieve, memory ingestion (MOS.add), MOS.chat end-to-end, scheduler tick latency, API endpoint throughput.
    2. Do you have profiling data, a benchmark, or a concrete repro (dataset size, memory type, operations) that shows the current slowdown?
    3. What's the target scale and acceptance criterion? e.g., "p95 search latency < 200ms at 100k memories" or "≥10% reduction in MOS.chat round-trip at N=50k".
    4. What's the acceptable change scope? Small targeted PR (≤ ~300 LOC, in-process only) vs. larger refactor that may touch vec_dbs / graph_dbs / mem_scheduler / external services.
    5. Any constraints on public API contract, DB schema, or dependency changes? Or must everything stay backward compatible?

    Reply with /autodev confirm yes to accept the defaults below, or /autodev confirm no <your answers> to override.
    Suggested default assumption: Default plan if you reply "/autodev confirm yes":

    • Target: textual-memory search/retrieve hot path (MOS.search → TreeTextMemory.search / GeneralTextMemory.search) — most user-facing op, most impacted by data growth.
    • Scope: small in-process improvements inside src/memos/memories/textual/ and src/memos/mem_os/ only.
    • Type of change: measurable hot-path wins (e.g., cache repeated per-search embedding lookups, drop redundant DB round-trips, reduce per-call allocation). No algorithmic rewrites of scoring or indexes.
    • Verification: add a synthetic micro-benchmark + perf regression pytest case, plus standard pytest tests/memories/ run.
    • Out of scope under the default: vec_dbs/, graph_dbs/, mem_scheduler/, evaluation/, API contract changes, DB schema changes, new dependencies.
      Please reply with one of the following commands (only issue author or repo collaborators):
    • /autodev confirm yes — agree and continue
    • /autodev confirm no <additional info> — provide more details
    • /autodev cancel — cancel this task
      If no reply within 24h, I will proceed with the default assumption.
  6. Memtensor-AI commented on Jun 16, 2026

    @Memtensor-AI
    Collaborator

    ⏰ AutoDev task f4939bc985cde6d5 received no /autodev confirm reply within 24h. Proceeding with the default assumption. You can still provide feedback during PR review.

  7. Memtensor-AI commented on Jun 16, 2026

    @Memtensor-AI
    Collaborator

    ❌ AutoDev task f4939bc985cde6d5 failed.

    Summary: AutoDev executor crashed before producing a result.
    Error: Claude SDK query failed: Claude Code returned an error result: Failed to authenticate. API Error: 403 token quota is not enough, token remain quota: $0.152016, need quota: $0.491764 (request id: 20260616150518609724790LG9WNQfu)

  8. added
    ai:codingAI agent is coding | AI 正在编码
    and removed
    ai:codingAI agent is coding | AI 正在编码
    on Jun 17, 2026
  9. Memtensor-AI commented on Jun 17, 2026

    @Memtensor-AI
    Collaborator

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

    Task ID: f4939bc985cde6d5
    Working branch: feature/autodev-1926
    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.

  10. Memtensor-AI commented on Jun 17, 2026

    @Memtensor-AI
    Collaborator

    ✅ AutoDev task f4939bc985cde6d5 completed.

    Summary: Issue #1926 asks for "better overall MemOS performance" without a specific scenario. A Phase-1 clarification round timed out, so per opsp rules the locked-in default scope applies: targeted, low-risk hot-path wins inside src/memos/memories/textual/general.py only — no public API change, no schema change, no new dependency.

    This PR makes three concrete improvements to GeneralTextMemory. First, _embed_one_sentence now consults a per-instance bounded LRU cache (size cap 256) keyed on raw sentence text, so identical queries within a process — common in retry / rerank loops, repeated chat lookups, and update() calls whose memory text matches a recent search() — skip the embedder round-trip; cached values are deep-copied on the way in and out so downstream mutation cannot poison the cache. Second, the redundant sorted(..., reverse=True) in search is removed because qdrant_client.query_points already returns hits in descending-by-score order; a regression test guards the ordering contract. Third, the read paths (search, get, get_by_ids, get_all) construct TextualMemoryItem via model_validate(payload) instead of **payload — equivalent semantics on a dict input and the idiomatic Pydantic v2 path.

    Verification: 4 new unit tests in tests/memories/textual/test_general.py cover cache hit, LRU eviction, search ordering preservation, and search↔update cache sharing. Full textual suite passes 62/62. Broader smoke (tests/memories/, tests/mem_os/, tests/mem_cube/) passes 101 tests; 2 pre-existing failures in tests/memories/activation/test_kv.py are an unrelated transformers DynamicCache.key_cache API drift, confirmed reproducible on the unmodified base branch via git stash. Ruff format and ruff check are clean on the touched files.

    Base branch: main
    Branch: feature/autodev-1926
    Commit: 6a2ba90
    PR: #1942
    Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller
    Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller

  11. added
    ai:testingAI agent is running tests | AI 正在运行测试
    ai:codingAI agent is coding | AI 正在编码
    and removed
    ai:codingAI agent is coding | AI 正在编码
    on Jun 17, 2026
  12. Memtensor-AI commented on Jun 17, 2026

    @Memtensor-AI
    Collaborator

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

    Task ID: f4939bc985cde6d5
    Working branch: feature/autodev-1926
    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.

  13. removed
    ai:testingAI agent is running tests | AI 正在运行测试
    ai:codingAI agent is coding | AI 正在编码
    on Jun 17, 2026
  14. Memtensor-AI commented on Jun 17, 2026

    @Memtensor-AI
    Collaborator

    ✅ AutoDev task f4939bc985cde6d5 completed.

    Summary: Improves the textual-memory hot path in GeneralTextMemory (src/memos/memories/textual/general.py) with three small, isolated, backwards-compatible optimizations endorsed by the Phase-1 timeout default scope.

    Specifically: (1) a per-instance bounded LRU cache (size 256) on _embed_one_sentence so identical queries within a process — common in retry / rerank loops, repeated chat lookups, and update() calls that reuse a recent search() text — skip the embedder round-trip; cached embeddings are deep-copied on the way in and on the way out so downstream mutation cannot poison cache state. (2) Drops a redundant in-process sorted(..., reverse=True) in search(): Qdrant's query_points already returns hits in descending score order; a regression test now guards that contract. (3) Switches TextualMemoryItem(**payload) to TextualMemoryItem.model_validate(payload) on the read paths (search, get, get_by_ids, get_all) — equivalent semantics on a dict input and the recommended Pydantic v2 idiom.

    Tests: adds 4 new unit cases in tests/memories/textual/test_general.py covering cache hit, LRU eviction, search-ordering preservation, and search↔update cache sharing. All 62 textual-memory tests pass. Broader smoke (tests/memories/ tests/mem_os/ tests/mem_cube/) shows 101 passed; 2 test_kv failures are pre-existing transformers DynamicCache API drift reproduced on the unchanged base and unrelated to this PR. Ruff lint + format both clean. No public API change, no schema change, no new dependency, no API contract change. Branch feature/autodev-1926 pushed to origin at commit ecdd118a; specs archived to memos-autodev-specs main.

    Base branch: main
    Branch: feature/autodev-1926
    Commit: ecdd118
    PR: #1944
    Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller
    Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller

  15. added and removed
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    ai:testingAI agent is running tests | AI 正在运行测试
    on Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:coreMOS 编排层 / 框架底座 / 跨模块问题types:enhancementNew feature or improvement | 新功能或改进

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions